[pypy-svn] r32030 - in pypy/dist/pypy/module/_codecs: . test
xoraxax at codespeak.net
xoraxax at codespeak.net
Wed Sep 6 16:47:43 CEST 2006
Author: xoraxax
Date: Wed Sep 6 16:47:40 2006
New Revision: 32030
Modified:
pypy/dist/pypy/module/_codecs/app_codecs.py
pypy/dist/pypy/module/_codecs/test/test_codecs.py
Log:
Fixed _codecs module: it did not normalise codec names before looking them up. Thanks to Victor Stinner for the patch. Interestingly, the added patch did not fail with py.test because py.py got it right, pypy-c did not.
Modified: pypy/dist/pypy/module/_codecs/app_codecs.py
==============================================================================
--- pypy/dist/pypy/module/_codecs/app_codecs.py (original)
+++ pypy/dist/pypy/module/_codecs/app_codecs.py Wed Sep 6 16:47:40 2006
@@ -65,26 +65,26 @@
Looks up a codec tuple in the Python codec registry and returns
a tuple of functions.
"""
-
- result = codec_search_cache.get(encoding, None)
+ if not isinstance(encoding, str):
+ raise TypeError("Encoding must be a string")
+ normalized_encoding = encoding.replace(" ", "-").lower()
+ result = codec_search_cache.get(normalized_encoding, None)
if not result:
if codec_need_encodings:
import encodings
if len(codec_search_path) == 0:
raise LookupError("no codec search functions registered: can't find encoding")
del codec_need_encodings[:]
- if not isinstance(encoding, str):
- raise TypeError("Encoding must be a string")
for search in codec_search_path:
- result = search(encoding)
- if result :
- if not( type(result) == tuple and len(result) == 4):
+ result = search(normalized_encoding)
+ if result:
+ if not (type(result) == tuple and len(result) == 4):
raise TypeError("codec search functions must return 4-tuples")
else:
- codec_search_cache[encoding] = result
+ codec_search_cache[normalized_encoding] = result
return result
if not result:
- raise LookupError( "unknown encoding: %s" % encoding)
+ raise LookupError("unknown encoding: %s" % encoding)
return result
Modified: pypy/dist/pypy/module/_codecs/test/test_codecs.py
==============================================================================
--- pypy/dist/pypy/module/_codecs/test/test_codecs.py (original)
+++ pypy/dist/pypy/module/_codecs/test/test_codecs.py Wed Sep 6 16:47:40 2006
@@ -254,3 +254,7 @@
assert '\\100'.decode('string_escape') == '@'
assert '\\253'.decode('string_escape') == chr(0253)
assert '\\312'.decode('string_escape') == chr(0312)
+
+ def test_decode_utf8_different_case(self):
+ constant = u"a"
+ assert constant.encode("utf-8") == constant.encode("UTF-8")
More information about the Pypy-commit
mailing list