[pypy-svn] r75426 - in pypy/trunk/pypy/module/_codecs: . test
arigo at codespeak.net
arigo at codespeak.net
Wed Jun 16 17:08:04 CEST 2010
Author: arigo
Date: Wed Jun 16 17:08:03 2010
New Revision: 75426
Modified:
pypy/trunk/pypy/module/_codecs/app_codecs.py
pypy/trunk/pypy/module/_codecs/test/test_codecs.py
Log:
Some random fixes until test_codecs passes on Mac,
with a 16-bit unicode CPython and emulating a 32-bit
PyPy.
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 Wed Jun 16 17:08:03 2010
@@ -39,8 +39,6 @@
# XXX move some of these functions to RPython (like charmap_encode,
# charmap_build) to make them faster
-import sys
-
def escape_encode( obj, errors='strict'):
"""None
"""
@@ -84,36 +82,36 @@
res = ''.join(res)
return res, len(res)
-if sys.maxunicode == 65535:
- unicode_bytes = 2
-else:
- unicode_bytes = 4
-
def unicode_internal_encode( obj, errors='strict'):
"""None
"""
- if type(obj) == unicode:
- p = []
- t = [ord(x) for x in obj]
- for i in t:
- bytes = []
- for j in xrange(unicode_bytes):
- bytes += chr(i%256)
- i >>= 8
- if sys.byteorder == "big":
- bytes.reverse()
- p += bytes
- res = ''.join(p)
- return res, len(res)
+ import sys
+ if sys.maxunicode == 65535:
+ unicode_bytes = 2
else:
- res = "You can do better than this" # XXX make this right
- return res, len(res)
+ unicode_bytes = 4
+ p = []
+ for x in obj:
+ i = ord(x)
+ bytes = []
+ for j in xrange(unicode_bytes):
+ bytes += chr(i%256)
+ i >>= 8
+ if sys.byteorder == "big":
+ bytes.reverse()
+ p += bytes
+ res = ''.join(p)
+ return res, len(res)
def unicode_internal_decode( unistr, errors='strict'):
- import sys
if type(unistr) == unicode:
return unistr, len(unistr)
else:
+ import sys
+ if sys.maxunicode == 65535:
+ unicode_bytes = 2
+ else:
+ unicode_bytes = 4
p = []
i = 0
if sys.byteorder == "big":
@@ -541,6 +539,7 @@
hexdigits = [hex(i)[-1] for i in range(16)]+[hex(i)[-1].upper() for i in range(10, 16)]
def hexescape(s, pos, digits, message, errors):
+ import sys
chr = 0
p = []
if (pos+digits>len(s)):
@@ -580,6 +579,7 @@
return res, pos
def PyUnicode_DecodeUnicodeEscape(s, size, errors):
+ import sys
if (size == 0):
return u''
@@ -762,6 +762,7 @@
def PyUnicode_DecodeRawUnicodeEscape(s, size, errors):
+ import sys
if (size == 0):
return u''
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 Wed Jun 16 17:08:03 2010
@@ -84,7 +84,7 @@
assert str(UnicodeTranslateError(
u"g\uffffrk", 1, 2, "ouch"))== "can't translate character u'\\uffff' in position 1: ouch"
- if sys.maxunicode > 0xffff:
+ if sys.maxunicode > 0xffff and len(unichr(0x10000)) == 1:
assert str(UnicodeTranslateError(
u"g\U00010000rk", 1, 2, "ouch"))== "can't translate character u'\\U00010000' in position 1: ouch"
@@ -107,7 +107,7 @@
assert str(UnicodeEncodeError(
"ascii", u"\uffffx", 0, 1, "ouch"))=="'ascii' codec can't encode character u'\\uffff' in position 0: ouch"
- if sys.maxunicode > 0xffff:
+ if sys.maxunicode > 0xffff and len(unichr(0x10000)) == 1:
assert str(UnicodeEncodeError(
"ascii", u"\U00010000x", 0, 1, "ouch")) =="'ascii' codec can't encode character u'\\U00010000' in position 0: ouch"
@@ -229,7 +229,9 @@
def test_unicode_internal_encode(self):
import sys
- enc = u"a".encode("unicode_internal")
+ class U(unicode):
+ pass
+ enc = U(u"a").encode("unicode_internal")
if sys.maxunicode == 65535: # UCS2 build
if sys.byteorder == "big":
assert enc == "\x00a"
More information about the Pypy-commit
mailing list