[pypy-svn] r61082 - in pypy/trunk/pypy/module/_codecs: . test
fijal at codespeak.net
fijal at codespeak.net
Sun Jan 18 17:57:57 CET 2009
Author: fijal
Date: Sun Jan 18 17:57:56 2009
New Revision: 61082
Modified:
pypy/trunk/pypy/module/_codecs/app_codecs.py
pypy/trunk/pypy/module/_codecs/test/test_codecs.py
Log:
a bit of fixes for _codecs module. This is not over yet thouhg.
Modified: pypy/trunk/pypy/module/_codecs/app_codecs.py
==============================================================================
--- pypy/trunk/pypy/module/_codecs/app_codecs.py (original)
+++ pypy/trunk/pypy/module/_codecs/app_codecs.py Sun Jan 18 17:57:56 2009
@@ -1,3 +1,4 @@
+
# Note:
# This *is* now explicitly RPython.
# Please make sure not to break this.
@@ -48,12 +49,6 @@
"""
pass
-def readbuffer_encode( obj, errors='strict'):
- """None
- """
- res = str(obj)
- return res, len(res)
-
def escape_encode( obj, errors='strict'):
"""None
"""
@@ -142,10 +137,17 @@
t = 0
h = 0
for j in range(start, stop, step):
- t += ord(unistr[i+j])<<(h*8)
+ t += ord(unistr[i+j])<<(h*8)
h += 1
i += unicode_bytes
- p += unichr(t)
+ try:
+ p += unichr(t)
+ except ValueError:
+ startpos = i - unicode_bytes
+ endpos = i
+ raise UnicodeDecodeError('unicode_internal', unistr, startpos,
+ endpos,
+ "unichr(%s) not in range" % (t,))
res = u''.join(p)
return res, len(unistr)
@@ -416,8 +418,8 @@
inShift = 1
elif SPECIAL(ch, 0, 0) :
- raise UnicodeDecodeError, "unexpected special character"
-
+ msg = "unexpected special character"
+ raise UnicodeDecodeError('utf-7', s, i-1, i, msg)
else:
p += ch
else:
@@ -437,7 +439,8 @@
elif (SPECIAL(ch, 0, 0)):
i += 1
- raise UnicodeDecodeError, "unexpected special character"
+ msg = "unexpected special character"
+ raise UnicodeDecodeError('utf-7', s, i-1, i, msg)
else:
p += ch
i += 1
@@ -445,7 +448,8 @@
if (inShift) :
#XXX This aint right
endinpos = size
- raise UnicodeDecodeError, "unterminated shift sequence"
+ msg = "unterminated shift sequence"
+ raise UnicodeDecodeError('utf-7', s, i-1, i, msg)
return p
@@ -857,7 +861,7 @@
raise KeyError
else:
raise TypeError
- except KeyError:
+ except (KeyError, IndexError):
x = unicode_call_errorhandler(errors, "charmap",
"character maps to <undefined>", s, inpos, inpos+1)
p += x[0]
Modified: pypy/trunk/pypy/module/_codecs/test/test_codecs.py
==============================================================================
--- pypy/trunk/pypy/module/_codecs/test/test_codecs.py (original)
+++ pypy/trunk/pypy/module/_codecs/test/test_codecs.py Sun Jan 18 17:57:56 2009
@@ -352,3 +352,21 @@
s = '\\\n'
decoded = _codecs.unicode_escape_decode(s)[0]
assert decoded == ''
+
+ def test_charmap_decode(self):
+ import codecs
+ res = codecs.charmap_decode("\x00\x01\x02", "replace", u"ab")
+ assert res == (u"ab\ufffd", 3)
+
+ def test_decode_errors(self):
+ import sys
+ if sys.maxunicode > 0xffff:
+ try:
+ "\x00\x00\x00\x00\x00\x11\x11\x00".decode("unicode_internal")
+ except UnicodeDecodeError, ex:
+ assert "unicode_internal" == ex.encoding
+ assert "\x00\x00\x00\x00\x00\x11\x11\x00" == ex.object
+ assert ex.start == 4
+ assert ex.end == 8
+ else:
+ raise Exception("DID NOT RAISE")
More information about the Pypy-commit
mailing list