bpo-30103: Allow Uuencode in Python using backtick as zero instead of space (#1326)

This commit is contained in:
Xiang Zhang 2017-05-03 11:16:21 +08:00 committed by GitHub
parent 0360a9d015
commit 13f1f423fa
10 changed files with 137 additions and 67 deletions

View file

@ -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 */