Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions Include/internal/pycore_unicodeobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,6 @@ extern int _PyUnicodeWriter_FormatV(

extern PyObject* _PyUnicode_EncodeUTF7(
PyObject *unicode, /* Unicode object */
int base64SetO, /* Encode RFC2152 Set O characters in base64 */
int base64WhiteSpace, /* Encode whitespace (sp, ht, nl, cr) in base64 */
const char *errors); /* error handling */

/* --- UTF-8 Codecs ------------------------------------------------------- */
Expand Down
2 changes: 1 addition & 1 deletion Modules/_codecsmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,7 @@ _codecs_utf_7_encode_impl(PyObject *module, PyObject *str,
const char *errors)
/*[clinic end generated code: output=0feda21ffc921bc8 input=2546dbbb3fa53114]*/
{
return codec_tuple(_PyUnicode_EncodeUTF7(str, 0, 0, errors),
return codec_tuple(_PyUnicode_EncodeUTF7(str, errors),
PyUnicode_GET_LENGTH(str));
}

Expand Down
15 changes: 5 additions & 10 deletions Objects/unicodeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -4668,15 +4668,12 @@ char utf7_category[128] = {

/* ENCODE_DIRECT: this character should be encoded as itself. The
* answer depends on whether we are encoding set O as itself, and also
* on whether we are encoding whitespace as itself. RFC2152 makes it
* on whether we are encoding whitespace as itself. RFC 2152 makes it
* clear that the answers to these questions vary between
* applications, so this code needs to be flexible. */

#define ENCODE_DIRECT(c, directO, directWS) \
((c) < 128 && (c) > 0 && \
((utf7_category[(c)] == 0) || \
(directWS && (utf7_category[(c)] == 2)) || \
(directO && (utf7_category[(c)] == 1))))
#define ENCODE_DIRECT(c) \
((c) < 128 && (c) > 0 && ((utf7_category[(c)] != 3)))

PyObject *
PyUnicode_DecodeUTF7(const char *s,
Expand Down Expand Up @@ -4893,8 +4890,6 @@ PyUnicode_DecodeUTF7Stateful(const char *s,

PyObject *
_PyUnicode_EncodeUTF7(PyObject *str,
int base64SetO,
int base64WhiteSpace,
const char *errors)
{
Py_ssize_t len = PyUnicode_GET_LENGTH(str);
Expand All @@ -4921,7 +4916,7 @@ _PyUnicode_EncodeUTF7(PyObject *str,
Py_UCS4 ch = PyUnicode_READ(kind, data, i);

if (inShift) {
if (ENCODE_DIRECT(ch, !base64SetO, !base64WhiteSpace)) {
if (ENCODE_DIRECT(ch)) {
/* shifting out */
if (base64bits) { /* output remaining bits */
*out++ = TO_BASE64(base64buffer << (6-base64bits));
Expand All @@ -4945,7 +4940,7 @@ _PyUnicode_EncodeUTF7(PyObject *str,
*out++ = '+';
*out++ = '-';
}
else if (ENCODE_DIRECT(ch, !base64SetO, !base64WhiteSpace)) {
else if (ENCODE_DIRECT(ch)) {
*out++ = (char) ch;
}
else {
Expand Down
Loading