diff options
author | 2012-06-07 14:24:48 +0200 | |
---|---|---|
committer | 2012-06-07 14:24:48 +0200 | |
commit | 78839556b923ed4d35c026731f9bc7130bcfa614 (patch) | |
tree | 929c13920778f87c37121cb556e677aa3ab62baf | |
parent | hg merge default (diff) | |
parent | GetConsoleCP() & GetConsoleOutputCP() for Windows. (diff) | |
download | pypy-release-1.9.tar.gz pypy-release-1.9.tar.bz2 pypy-release-1.9.zip |
hg merge defaultrelease-1.9
-rw-r--r-- | pypy/doc/cpython_differences.rst | 5 | ||||
-rw-r--r-- | pypy/module/__pypy__/__init__.py | 2 | ||||
-rw-r--r-- | pypy/module/__pypy__/interp_magic.py | 7 | ||||
-rw-r--r-- | pypy/rlib/rwin32.py | 8 | ||||
-rw-r--r-- | pypy/translator/goal/app_main.py | 28 |
5 files changed, 40 insertions, 10 deletions
diff --git a/pypy/doc/cpython_differences.rst b/pypy/doc/cpython_differences.rst index 015b7e6afc..c1d1b3a0bd 100644 --- a/pypy/doc/cpython_differences.rst +++ b/pypy/doc/cpython_differences.rst @@ -324,5 +324,10 @@ Miscellaneous type and vice versa. For builtin types, a dictionary will be returned that cannot be changed (but still looks and behaves like a normal dictionary). +* the ``__len__`` or ``__length_hint__`` special methods are sometimes + called by CPython to get a length estimate to preallocate internal arrays. + So far, PyPy never calls ``__len__`` for this purpose, and never calls + ``__length_hint__`` at all. + .. include:: _ref.txt diff --git a/pypy/module/__pypy__/__init__.py b/pypy/module/__pypy__/__init__.py index d3f3053dbb..541d77b5c4 100644 --- a/pypy/module/__pypy__/__init__.py +++ b/pypy/module/__pypy__/__init__.py @@ -44,6 +44,8 @@ class Module(MixedModule): 'list_strategy' : 'interp_magic.list_strategy', 'validate_fd' : 'interp_magic.validate_fd', } + if sys.platform == 'win32': + interpleveldefs['get_console_cp'] = 'interp_magic.get_console_cp' submodules = { "builders": BuildersModule, diff --git a/pypy/module/__pypy__/interp_magic.py b/pypy/module/__pypy__/interp_magic.py index d6a0dea7b4..328583ce24 100644 --- a/pypy/module/__pypy__/interp_magic.py +++ b/pypy/module/__pypy__/interp_magic.py @@ -88,3 +88,10 @@ def validate_fd(space, fd): rposix.validate_fd(fd) except OSError, e: raise wrap_oserror(space, e) + +def get_console_cp(space): + from pypy.rlib import rwin32 # Windows only + return space.newtuple([ + space.wrap('cp%d' % rwin32.GetConsoleCP()), + space.wrap('cp%d' % rwin32.GetConsoleOutputCP()), + ]) diff --git a/pypy/rlib/rwin32.py b/pypy/rlib/rwin32.py index c43176fb90..59e3c3789b 100644 --- a/pypy/rlib/rwin32.py +++ b/pypy/rlib/rwin32.py @@ -367,6 +367,14 @@ if WIN32: 'GetCurrentProcessId', [], DWORD) def GetCurrentProcessId(): return rffi.cast(lltype.Signed, _GetCurrentProcessId()) + + _GetConsoleCP = winexternal('GetConsoleCP', [], DWORD) + _GetConsoleOutputCP = winexternal('GetConsoleOutputCP', [], DWORD) + def GetConsoleCP(): + return rffi.cast(lltype.Signed, _GetConsoleCP()) + def GetConsoleOutputCP(): + return rffi.cast(lltype.Signed, _GetConsoleOutputCP()) + def os_kill(pid, sig): if sig == CTRL_C_EVENT or sig == CTRL_BREAK_EVENT: if GenerateConsoleCtrlEvent(sig, pid) == 0: diff --git a/pypy/translator/goal/app_main.py b/pypy/translator/goal/app_main.py index 2d3f08c563..865c859370 100644 --- a/pypy/translator/goal/app_main.py +++ b/pypy/translator/goal/app_main.py @@ -288,7 +288,7 @@ def setup_initial_paths(ignore_environment=False, **extra): sys.path.append(dir) _seen[dir] = True -def set_io_encoding(io_encoding): +def set_io_encoding(io_encoding, io_encoding_output, errors, overridden): try: import _file except ImportError: @@ -299,12 +299,11 @@ def set_io_encoding(io_encoding): set_file_encoding.argtypes = [ctypes.py_object, ctypes.c_char_p, ctypes.c_char_p] else: set_file_encoding = _file.set_file_encoding - if ":" in io_encoding: - encoding, errors = io_encoding.split(":", 1) - else: - encoding, errors = io_encoding, None - for f in [sys.stdin, sys.stdout, sys.stderr]: - set_file_encoding(f, encoding, errors) + for f, encoding in [(sys.stdin, io_encoding), + (sys.stdout, io_encoding_output), + (sys.stderr, io_encoding_output)]: + if isinstance(f, file) and (overridden or f.isatty()): + set_file_encoding(f, encoding, errors) # Order is significant! sys_flags = ( @@ -514,10 +513,19 @@ def run_command_line(interactive, readenv = not ignore_environment io_encoding = readenv and os.getenv("PYTHONIOENCODING") - if not io_encoding and not IS_WINDOWS: - io_encoding = sys.getfilesystemencoding() if io_encoding: - set_io_encoding(io_encoding) + errors = None + if ":" in io_encoding: + io_encoding, errors = io_encoding.split(":", 1) + set_io_encoding(io_encoding, io_encoding, errors, True) + else: + if IS_WINDOWS: + import __pypy__ + io_encoding, io_encoding_output = __pypy__.get_console_cp() + else: + io_encoding = io_encoding_output = sys.getfilesystemencoding() + if io_encoding: + set_io_encoding(io_encoding, io_encoding_output, None, False) pythonwarnings = readenv and os.getenv('PYTHONWARNINGS') if pythonwarnings: |