[pypy-commit] pypy py3k: Remove sys.setdefaultencoding
amauryfa
noreply at buildbot.pypy.org
Sat Jan 28 17:57:32 CET 2012
Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch: py3k
Changeset: r51921:1ff9e2433ebb
Date: 2012-01-28 14:28 +0100
http://bitbucket.org/pypy/pypy/changeset/1ff9e2433ebb/
Log: Remove sys.setdefaultencoding
diff --git a/pypy/module/cpyext/unicodeobject.py b/pypy/module/cpyext/unicodeobject.py
--- a/pypy/module/cpyext/unicodeobject.py
+++ b/pypy/module/cpyext/unicodeobject.py
@@ -258,15 +258,6 @@
i += 1
return default_encoding
- at cpython_api([CONST_STRING], rffi.INT_real, error=-1)
-def PyUnicode_SetDefaultEncoding(space, encoding):
- """Sets the currently active default encoding. Returns 0 on
- success, -1 in case of an error."""
- w_encoding = space.wrap(rffi.charp2str(encoding))
- setdefaultencoding(space, w_encoding)
- default_encoding[0] = '\x00'
- return 0
-
@cpython_api([PyObject, CONST_STRING, CONST_STRING], PyObject)
def PyUnicode_AsEncodedObject(space, w_unicode, llencoding, llerrors):
"""Encode a Unicode object and return the result as Python object.
diff --git a/pypy/module/sys/__init__.py b/pypy/module/sys/__init__.py
--- a/pypy/module/sys/__init__.py
+++ b/pypy/module/sys/__init__.py
@@ -7,7 +7,6 @@
class Module(MixedModule):
"""Sys Builtin Module. """
- _immutable_fields_ = ["defaultencoding?"]
def __init__(self, space, w_name):
"""NOT_RPYTHON""" # because parent __init__ isn't
@@ -16,7 +15,7 @@
super(Module, self).__init__(space, w_name)
self.recursionlimit = 100
self.w_default_encoder = None
- self.defaultencoding = "ascii"
+ self.defaultencoding = "utf-8"
self.filesystemencoding = None
interpleveldefs = {
@@ -74,7 +73,6 @@
'dont_write_bytecode' : 'space.w_False',
'getdefaultencoding' : 'interp_encoding.getdefaultencoding',
- 'setdefaultencoding' : 'interp_encoding.setdefaultencoding',
'getfilesystemencoding' : 'interp_encoding.getfilesystemencoding',
'float_info' : 'system.get_float_info(space)',
diff --git a/pypy/module/sys/interp_encoding.py b/pypy/module/sys/interp_encoding.py
--- a/pypy/module/sys/interp_encoding.py
+++ b/pypy/module/sys/interp_encoding.py
@@ -7,17 +7,6 @@
implementation."""
return space.wrap(space.sys.defaultencoding)
-def setdefaultencoding(space, w_encoding):
- """Set the current default string encoding used by the Unicode
-implementation."""
- encoding = space.str_w(w_encoding)
- mod = space.getbuiltinmodule("_codecs")
- w_lookup = space.getattr(mod, space.wrap("lookup"))
- # check whether the encoding is there
- space.call_function(w_lookup, w_encoding)
- space.sys.w_default_encoder = None
- space.sys.defaultencoding = encoding
-
def get_w_default_encoder(space):
assert not (space.config.translating and not we_are_translated()), \
"get_w_default_encoder() should not be called during translation"
diff --git a/pypy/module/sys/test/test_sysmodule.py b/pypy/module/sys/test/test_sysmodule.py
--- a/pypy/module/sys/test/test_sysmodule.py
+++ b/pypy/module/sys/test/test_sysmodule.py
@@ -329,25 +329,6 @@
# can't check more than the type, as the user might have changed it
assert isinstance(sys.getdefaultencoding(), str)
- def test_setdefaultencoding(self):
- import sys
- if self.appdirect:
- skip("not worth running appdirect")
-
- encoding = sys.getdefaultencoding()
- try:
- sys.setdefaultencoding("ascii")
- assert sys.getdefaultencoding() == 'ascii'
- raises(UnicodeDecodeError, unicode, b'\x80')
-
- sys.setdefaultencoding("latin-1")
- assert sys.getdefaultencoding() == 'latin-1'
- assert unicode(b'\x80') == '\u0080'
-
- finally:
- sys.setdefaultencoding(encoding)
-
-
# testing sys.settrace() is done in test_trace.py
# testing sys.setprofile() is done in test_profile.py
More information about the pypy-commit
mailing list