[pypy-svn] r12743 - in pypy/dist/pypy: module/__builtin__ objspace/std
ac at codespeak.net
ac at codespeak.net
Mon May 23 15:04:45 CEST 2005
Author: ac
Date: Mon May 23 15:04:44 2005
New Revision: 12743
Modified:
pypy/dist/pypy/module/__builtin__/compiling.py
pypy/dist/pypy/objspace/std/unicodeobject.py
Log:
Allow unwraping of unicode objects to the benefit of faked functions
getting unicode arguments.
Use the pypy codecs module to encode unicode objects.
Modified: pypy/dist/pypy/module/__builtin__/compiling.py
==============================================================================
--- pypy/dist/pypy/module/__builtin__/compiling.py (original)
+++ pypy/dist/pypy/module/__builtin__/compiling.py Mon May 23 15:04:44 2005
@@ -9,7 +9,7 @@
def compile(space, w_source, filename, mode, flags=0, dont_inherit=0):
if space.is_true(space.isinstance(w_source, space.w_unicode)):
- str_ = u''.join(w_source._value) # Bad exposing of unicode internals
+ str_ = space.unwrap(w_source) # Bad exposing of unicode internals
else:
str_ = space.str_w(w_source)
Modified: pypy/dist/pypy/objspace/std/unicodeobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/unicodeobject.py (original)
+++ pypy/dist/pypy/objspace/std/unicodeobject.py Mon May 23 15:04:44 2005
@@ -1,6 +1,5 @@
from pypy.objspace.std.objspace import *
from pypy.interpreter import gateway
-from pypy.objspace.std.fake import wrap_exception
from pypy.objspace.std.stringobject import W_StringObject
from pypy.objspace.std.noneobject import W_NoneObject
from pypy.objspace.std.sliceobject import W_SliceObject
@@ -23,6 +22,11 @@
""" representation for debugging purposes """
return "%s(%r)" % (w_self.__class__.__name__, w_self._value)
+ def unwrap(w_self):
+ # For faked functions taking unicodearguments.
+ # Remove when we no longer need faking.
+ return u''.join(w_self._value)
+
registerimplementation(W_UnicodeObject)
# Helper for converting int/long
@@ -178,23 +182,6 @@
offset += len(item)
return W_UnicodeObject(space, result)
-def unicode_encode__Unicode_String_String(space, w_self, w_encoding, w_errors):
- try:
- return space.wrap(u''.join(w_self._value).encode(space.str_w(w_encoding), space.str_w(w_errors)))
- except:
- wrap_exception(space)
-
-def unicode_encode__Unicode_String_None(space, w_self, w_encoding, w_none):
- try:
- return space.wrap(u''.join(w_self._value).encode(space.str_w(w_encoding)))
- except:
- wrap_exception(space)
-
-def unicode_encode__Unicode_None_None(space, w_self, w_encoding, w_errors):
- try:
- return space.wrap(u''.join(w_self._value).encode())
- except:
- wrap_exception(space)
def hash__Unicode(space, w_uni):
if w_uni.w_hash is None:
@@ -770,14 +757,30 @@
import _formatting
if isinstance(values, tuple):
return _formatting.format(format, values, None, do_unicode=True)
- if hasattr(values, 'keys'):
+ if hasattr(values, "keys"):
return _formatting.format(format, (values,), values, do_unicode=True)
return _formatting.format(format, (values,), None, do_unicode=True)
+
+def unicode_encode__Unicode_ANY_ANY(unistr, encoding=None, errors=None):
+ import codecs, sys
+ if encoding is None:
+ encoding = sys.getdefaultencoding()
+
+ encoder = codecs.getencoder(encoding)
+ if errors is None:
+ retval, lenght = encoder(unistr)
+ else:
+ retval, length = encoder(unistr, errors)
+
+ return retval
+
''')
unicode_expandtabs__Unicode_ANY = app.interphook('unicode_expandtabs__Unicode_ANY')
unicode_translate__Unicode_ANY = app.interphook('unicode_translate__Unicode_ANY')
mod__Unicode_ANY = app.interphook('mod__Unicode_ANY')
+unicode_encode__Unicode_ANY_ANY = app.interphook('unicode_encode__Unicode_ANY_ANY')
+
import unicodetype
register_all(vars(), unicodetype)
More information about the Pypy-commit
mailing list