[pypy-svn] r73823 - in pypy/trunk/pypy/module/sys: . test
fijal at codespeak.net
fijal at codespeak.net
Fri Apr 16 23:19:18 CEST 2010
Author: fijal
Date: Fri Apr 16 23:19:15 2010
New Revision: 73823
Modified:
pypy/trunk/pypy/module/sys/__init__.py
pypy/trunk/pypy/module/sys/app.py
pypy/trunk/pypy/module/sys/interp_encoding.py
pypy/trunk/pypy/module/sys/test/test_sysmodule.py
Log:
Add getfilesystemencoding using rlocale
Modified: pypy/trunk/pypy/module/sys/__init__.py
==============================================================================
--- pypy/trunk/pypy/module/sys/__init__.py (original)
+++ pypy/trunk/pypy/module/sys/__init__.py Fri Apr 16 23:19:15 2010
@@ -68,13 +68,14 @@
'getdefaultencoding' : 'interp_encoding.getdefaultencoding',
'setdefaultencoding' : 'interp_encoding.setdefaultencoding',
-}
+ 'getfilesystemencoding' : 'interp_encoding.getfilesystemencoding',
+ }
+
appleveldefs = {
'excepthook' : 'app.excepthook',
'__excepthook__' : 'app.excepthook',
'exit' : 'app.exit',
'exitfunc' : 'app.exitfunc',
- 'getfilesystemencoding' : 'app.getfilesystemencoding',
'callstats' : 'app.callstats',
'copyright' : 'app.copyright_str',
}
Modified: pypy/trunk/pypy/module/sys/app.py
==============================================================================
--- pypy/trunk/pypy/module/sys/app.py (original)
+++ pypy/trunk/pypy/module/sys/app.py Fri Apr 16 23:19:15 2010
@@ -26,18 +26,6 @@
#import __builtin__
-def getfilesystemencoding():
- """Return the encoding used to convert Unicode filenames in
- operating system filenames.
- """
- if sys.platform == "win32":
- encoding = "mbcs"
- elif sys.platform == "darwin":
- encoding = "utf-8"
- else:
- encoding = None
- return encoding
-
def callstats():
"""Not implemented."""
return None
Modified: pypy/trunk/pypy/module/sys/interp_encoding.py
==============================================================================
--- pypy/trunk/pypy/module/sys/interp_encoding.py (original)
+++ pypy/trunk/pypy/module/sys/interp_encoding.py Fri Apr 16 23:19:15 2010
@@ -1,3 +1,6 @@
+import sys
+from pypy.rlib import rlocale
+
def getdefaultencoding(space):
"""Return the current default string encoding used by the Unicode
implementation."""
@@ -22,3 +25,27 @@
w_encoder = space.getitem(w_functuple, space.wrap(0))
space.sys.w_default_encoder = w_encoder # cache it
return w_encoder
+
+def getfilesystemencoding(space):
+ """Return the encoding used to convert Unicode filenames in
+ operating system filenames.
+ """
+ if sys.platform == "win32":
+ encoding = "mbcs"
+ elif sys.platform == "darwin":
+ encoding = "utf-8"
+ else:
+ encoding = None
+ # CPython does this at startup time, I don't thing it matter that much
+ if rlocale.HAVE_LANGINFO and rlocale.CODESET:
+ oldlocale = rlocale.setlocale(rlocale.LC_CTYPE, None)
+ rlocale.setlocale(rlocale.LC_CTYPE, "")
+ loc_codeset = rlocale.nl_langinfo(rlocale.CODESET)
+ if loc_codeset:
+ codecmod = space.getbuiltinmodule('_codecs')
+ w_res = space.call_function(space.getattr(codecmod,
+ space.wrap('lookup')),
+ space.wrap(loc_codeset))
+ if space.is_true(w_res):
+ encoding = loc_codeset
+ return space.wrap(encoding)
Modified: pypy/trunk/pypy/module/sys/test/test_sysmodule.py
==============================================================================
--- pypy/trunk/pypy/module/sys/test/test_sysmodule.py (original)
+++ pypy/trunk/pypy/module/sys/test/test_sysmodule.py Fri Apr 16 23:19:15 2010
@@ -3,6 +3,7 @@
from pypy.conftest import option
from py.test import raises
from pypy.interpreter.gateway import app2interp_temp
+import sys
def init_globals_via_builtins_hack(space):
space.appexec([], """():
@@ -24,6 +25,7 @@
def setup_class(cls):
cls.w_appdirect = cls.space.wrap(option.runappdirect)
+ cls.w_filesystemenc = cls.space.wrap(sys.getfilesystemencoding())
def test_sys_in_modules(self):
import sys
@@ -108,6 +110,10 @@
assert isinstance(sys.stderr, file)
assert isinstance(sys.stdin, file)
+ def test_getfilesystemencoding(self):
+ import sys
+ assert sys.getfilesystemencoding() == self.filesystemenc
+
class AppTestSysModulePortedFromCPython:
def setup_class(cls):
More information about the Pypy-commit
mailing list