diff options
author | Xiang Zhang <angwerzx@126.com> | 2017-05-03 03:16:21 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-05-03 03:16:21 (GMT) |
commit | 13f1f423fac39f8f14a3ce919dd236975517d5c6 (patch) | |
tree | 674546ddbbbfaf930c0087eeb1621fab11e25d5f /Modules/binascii.c | |
parent | 0360a9d015ddbc4e3d58e3ab4b433da27bf1db3a (diff) | |
download | cpython-13f1f423fac39f8f14a3ce919dd236975517d5c6.zip cpython-13f1f423fac39f8f14a3ce919dd236975517d5c6.tar.gz cpython-13f1f423fac39f8f14a3ce919dd236975517d5c6.tar.bz2 |
bpo-30103: Allow Uuencode in Python using backtick as zero instead of space (#1326)
Diffstat (limited to 'Modules/binascii.c')
-rw-r--r-- | Modules/binascii.c | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/Modules/binascii.c b/Modules/binascii.c index fbd2320..1f9ff5a 100644 --- a/Modules/binascii.c +++ b/Modules/binascii.c @@ -335,13 +335,15 @@ binascii.b2a_uu data: Py_buffer / + * + backtick: bool(accept={int}) = False Uuencode line of data. [clinic start generated code]*/ static PyObject * -binascii_b2a_uu_impl(PyObject *module, Py_buffer *data) -/*[clinic end generated code: output=0070670e52e4aa6b input=00fdf458ce8b465b]*/ +binascii_b2a_uu_impl(PyObject *module, Py_buffer *data, int backtick) +/*[clinic end generated code: output=b1b99de62d9bbeb8 input=b26bc8d32b6ed2f6]*/ { unsigned char *ascii_data; const unsigned char *bin_data; @@ -367,7 +369,10 @@ binascii_b2a_uu_impl(PyObject *module, Py_buffer *data) return NULL; /* Store the length */ - *ascii_data++ = ' ' + (bin_len & 077); + if (backtick && !bin_len) + *ascii_data++ = '`'; + else + *ascii_data++ = ' ' + bin_len; for( ; bin_len > 0 || leftbits != 0 ; bin_len--, bin_data++ ) { /* Shift the data (or padding) into our buffer */ @@ -381,7 +386,10 @@ binascii_b2a_uu_impl(PyObject *module, Py_buffer *data) while ( leftbits >= 6 ) { this_ch = (leftchar >> (leftbits-6)) & 0x3f; leftbits -= 6; - *ascii_data++ = this_ch + ' '; + if (backtick && !this_ch) + *ascii_data++ = '`'; + else + *ascii_data++ = this_ch + ' '; } } *ascii_data++ = '\n'; /* Append a courtesy newline */ |