[pypy-svn] r45243 - in pypy/dist/pypy/lib: . test2
fijal at codespeak.net
fijal at codespeak.net
Sun Jul 22 14:17:13 CEST 2007
Author: fijal
Date: Sun Jul 22 14:17:11 2007
New Revision: 45243
Added:
pypy/dist/pypy/lib/test2/test_binascii.py (contents, props changed)
Modified:
pypy/dist/pypy/lib/binascii.py
Log:
A bit of monkeypatching error reporting, reported by exarkun.
Modified: pypy/dist/pypy/lib/binascii.py
==============================================================================
--- pypy/dist/pypy/lib/binascii.py (original)
+++ pypy/dist/pypy/lib/binascii.py Sun Jul 22 14:17:11 2007
@@ -160,28 +160,30 @@
for A, B, C, D in quadruplets_gen(s[:-4])]
if s:
- final = s[-4:]
- if final[2] == '=':
- A = table_a2b_base64[final[0]]
- B = table_a2b_base64[final[1]]
- snippet = chr(A << 2 | ((B >> 4) & 0x3))
- elif final[3] == '=':
- A = table_a2b_base64[final[0]]
- B = table_a2b_base64[final[1]]
- C = table_a2b_base64[final[2]]
- snippet = chr(A << 2 | ((B >> 4) & 0x3)) + \
- chr((B & 0xf) << 4 | ((C >> 2 ) & 0xf))
- else:
- A = table_a2b_base64[final[0]]
- B = table_a2b_base64[final[1]]
- C = table_a2b_base64[final[2]]
- D = table_a2b_base64[final[3]]
- snippet = chr(A << 2 | ((B >> 4) & 0x3)) + \
- chr((B & 0xf) << 4 | ((C >> 2 ) & 0xf)) + \
- chr((C & 0x3) << 6 | D )
- result.append(snippet)
-
- return ''.join(result)
+ try:
+ final = s[-4:]
+ if final[2] == '=':
+ A = table_a2b_base64[final[0]]
+ B = table_a2b_base64[final[1]]
+ snippet = chr(A << 2 | ((B >> 4) & 0x3))
+ elif final[3] == '=':
+ A = table_a2b_base64[final[0]]
+ B = table_a2b_base64[final[1]]
+ C = table_a2b_base64[final[2]]
+ snippet = chr(A << 2 | ((B >> 4) & 0x3)) + \
+ chr((B & 0xf) << 4 | ((C >> 2 ) & 0xf))
+ else:
+ A = table_a2b_base64[final[0]]
+ B = table_a2b_base64[final[1]]
+ C = table_a2b_base64[final[2]]
+ D = table_a2b_base64[final[3]]
+ snippet = chr(A << 2 | ((B >> 4) & 0x3)) + \
+ chr((B & 0xf) << 4 | ((C >> 2 ) & 0xf)) + \
+ chr((C & 0x3) << 6 | D )
+ result.append(snippet)
+ return ''.join(result)
+ except KeyError:
+ raise Error('Incorrect padding')
table_b2a_base64 = \
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
Added: pypy/dist/pypy/lib/test2/test_binascii.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/lib/test2/test_binascii.py Sun Jul 22 14:17:11 2007
@@ -0,0 +1,8 @@
+
+""" Some more binascii.py tests
+"""
+
+class AppTestBinAscii:
+ def test_incorrect_padding(self):
+ import binascii
+ raises(binascii.Error, "'x'.decode('base64')")
More information about the Pypy-commit
mailing list