Author: Amaury Forgeot d'Arc <amaur...@gmail.com> Branch: stdlib-2.7.9 Changeset: r75459:aeaed06de33f Date: 2015-01-20 23:41 +0100 http://bitbucket.org/pypy/pypy/changeset/aeaed06de33f/
Log: uudecode: when checking for trailing characters, don't bother checking the incomplete pending bits. For compatibility with CPython2.7.9. diff --git a/pypy/module/binascii/interp_uu.py b/pypy/module/binascii/interp_uu.py --- a/pypy/module/binascii/interp_uu.py +++ b/pypy/module/binascii/interp_uu.py @@ -19,15 +19,6 @@ return (ord(c) - 0x20) & 0x3f _a2b_read._always_inline_ = True -def _a2b_write(space, res, length, char): - if res.getlength() < length: # common case: we have enough room. - res.append(chr(char)) - else: - # overflows. Only accept zeros from now on. - if char != 0: - raise_Error(space, "Trailing garbage") -_a2b_write._always_inline_ = True - @unwrap_spec(ascii='bufferstr') def a2b_uu(space, ascii): @@ -45,9 +36,20 @@ C = _a2b_read(space, ascii, i+2) D = _a2b_read(space, ascii, i+3) # - _a2b_write(space, res, length, A << 2 | B >> 4) - _a2b_write(space, res, length, (B & 0xf) << 4 | C >> 2) - _a2b_write(space, res, length, (C & 0x3) << 6 | D) + if res.getlength() < length: + res.append(chr(A << 2 | B >> 4)) + elif A != 0 or B != 0: + raise_Error(space, "Trailing garbage") + # + if res.getlength() < length: + res.append(chr((B & 0xf) << 4 | C >> 2)) + elif C != 0: + raise_Error(space, "Trailing garbage") + # + if res.getlength() < length: + res.append(chr((C & 0x3) << 6 | D)) + elif D != 0: + raise_Error(space, "Trailing garbage") remaining = length - res.getlength() if remaining > 0: diff --git a/pypy/module/binascii/test/test_binascii.py b/pypy/module/binascii/test/test_binascii.py --- a/pypy/module/binascii/test/test_binascii.py +++ b/pypy/module/binascii/test/test_binascii.py @@ -29,6 +29,7 @@ ('(WAXR6UBA3#', "\xde\x1e2[X\xa1L0"), (')WAXR6UBA3#Q', "\xde\x1e2[X\xa1L<@"), ('*WAXR6UBA3#Q!5', "\xde\x1e2[X\xa1L<AT"), + ('!,_', '\x33'), ]: assert self.binascii.a2b_uu(input) == expected assert self.binascii.a2b_uu(input + ' ') == expected _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit