[pypy-svn] r48506 - in pypy/branch/unicode-objspace/pypy: interpreter module/sys objspace/std
cfbolz at codespeak.net
cfbolz at codespeak.net
Sat Nov 10 15:47:42 CET 2007
Author: cfbolz
Date: Sat Nov 10 15:47:40 2007
New Revision: 48506
Modified:
pypy/branch/unicode-objspace/pypy/interpreter/baseobjspace.py
pypy/branch/unicode-objspace/pypy/module/sys/interp_encoding.py
pypy/branch/unicode-objspace/pypy/objspace/std/unicodetype.py
Log:
sticking the encoding to the space is a bad idea
Modified: pypy/branch/unicode-objspace/pypy/interpreter/baseobjspace.py
==============================================================================
--- pypy/branch/unicode-objspace/pypy/interpreter/baseobjspace.py (original)
+++ pypy/branch/unicode-objspace/pypy/interpreter/baseobjspace.py Sat Nov 10 15:47:40 2007
@@ -188,7 +188,6 @@
self.interned_strings = {}
self.pending_actions = []
self.setoptions(**kw)
- self.defaultencoding = "ascii"
# if self.config.objspace.logbytecodes:
# self.bytecodecounts = {}
Modified: pypy/branch/unicode-objspace/pypy/module/sys/interp_encoding.py
==============================================================================
--- pypy/branch/unicode-objspace/pypy/module/sys/interp_encoding.py (original)
+++ pypy/branch/unicode-objspace/pypy/module/sys/interp_encoding.py Sat Nov 10 15:47:40 2007
@@ -1,8 +1,13 @@
+class EncodingState(object):
+ def __init__(self, space):
+ self.space = space
+ self.defaultencoding = "ascii"
+
def getdefaultencoding(space):
"""Return the current default string encoding used by the Unicode
implementation."""
- return space.wrap(space.defaultencoding)
+ return space.wrap(space.fromcache(EncodingState).defaultencoding)
def setdefaultencoding(space, w_encoding):
"""Set the current default string encoding used by the Unicode
@@ -12,4 +17,4 @@
w_lookup = space.getattr(mod, space.wrap("lookup"))
# check whether the encoding is there
space.call_function(w_lookup, w_encoding)
- space.defaultencoding = encoding
+ space.fromcache(EncodingState).defaultencoding = encoding
Modified: pypy/branch/unicode-objspace/pypy/objspace/std/unicodetype.py
==============================================================================
--- pypy/branch/unicode-objspace/pypy/objspace/std/unicodetype.py (original)
+++ pypy/branch/unicode-objspace/pypy/objspace/std/unicodetype.py Sat Nov 10 15:47:40 2007
@@ -142,18 +142,22 @@
# ____________________________________________________________
+def getdefaultencoding(space):
+ w_sys = space.getbuiltinmodule("sys")
+ return space.str_w(
+ space.call_function(
+ space.getattr(w_sys, space.wrap("getdefaultencoding"))))
+
def unicode_from_encoded_object(space, w_obj, encoding, errors):
w_codecs = space.getbuiltinmodule("_codecs")
if encoding is None:
- encoding = space.defaultencoding
+ encoding = getdefaultencoding(space)
w_decode = space.getattr(w_codecs, space.wrap("decode"))
if errors is None:
- w_retval = space.call(w_decode, space.newlist([w_obj,
- space.wrap(encoding)]))
+ w_retval = space.call_function(w_decode, w_obj, space.wrap(encoding))
else:
- w_retval = space.call(w_decode, space.newlist([w_obj,
- space.wrap(encoding),
- space.wrap(errors)]))
+ w_retval = space.call_function(w_decode, w_obj, space.wrap(encoding),
+ space.wrap(errors))
if not space.is_true(space.isinstance(w_retval, space.w_unicode)):
raise OperationError(
space.w_TypeError,
@@ -177,7 +181,7 @@
else:
raise
else:
- w_res = space.call(w_unicode_method, space.newlist([]))
+ w_res = space.call_function(w_unicode_method)
if space.is_true(space.isinstance(w_res, space.w_unicode)):
return w_res
return unicode_from_encoded_object(space, w_res, None, "strict")
@@ -185,7 +189,7 @@
def unicode_from_string(space, w_str):
# this is a performance and bootstrapping hack
from pypy.objspace.std.unicodeobject import W_UnicodeObject
- encoding = space.defaultencoding
+ encoding = getdefaultencoding(space)
if encoding != 'ascii':
return unicode_from_object(space, w_str)
s = space.str_w(w_str)
More information about the Pypy-commit
mailing list