[pypy-commit] pypy py3k: Merged in yuyichao/pypy/py3k (pull request #326)
mjacob
noreply at buildbot.pypy.org
Sat Jun 13 12:46:16 CEST 2015
Author: Manuel Jacob <me at manueljacob.de>
Branch: py3k
Changeset: r78083:c99fbaf556ce
Date: 2015-06-13 12:44 +0200
http://bitbucket.org/pypy/pypy/changeset/c99fbaf556ce/
Log: Merged in yuyichao/pypy/py3k (pull request #326)
fix strerror encoding
diff --git a/pypy/interpreter/error.py b/pypy/interpreter/error.py
--- a/pypy/interpreter/error.py
+++ b/pypy/interpreter/error.py
@@ -14,6 +14,10 @@
AUTO_DEBUG = os.getenv('PYPY_DEBUG')
RECORD_INTERPLEVEL_TRACEBACK = True
+def strerror(errno):
+ """Translate an error code to a message string."""
+ from pypy.module._codecs.locale import str_decode_locale_surrogateescape
+ return str_decode_locale_surrogateescape(os.strerror(errno))
class OperationError(Exception):
"""Interpreter-level exception that signals an exception that should be
@@ -530,9 +534,9 @@
space.getexecutioncontext().checksignals()
try:
- msg = os.strerror(errno)
+ msg = strerror(errno)
except ValueError:
- msg = 'error %d' % errno
+ msg = u'error %d' % errno
if w_exception_class is None:
exc = getattr(space, exception_name)
else:
@@ -562,7 +566,7 @@
from rpython.rlib.rposix import get_saved_errno
errno = get_saved_errno()
- msg = os.strerror(errno)
+ msg = strerror(errno)
w_error = space.call_function(w_type, space.wrap(errno), space.wrap(msg))
return OperationError(w_type, w_error)
diff --git a/pypy/module/_codecs/locale.py b/pypy/module/_codecs/locale.py
--- a/pypy/module/_codecs/locale.py
+++ b/pypy/module/_codecs/locale.py
@@ -13,6 +13,8 @@
from rpython.translator import cdir
from rpython.translator.tool.cbuild import ExternalCompilationInfo
+from pypy.interpreter.error import strerror as _strerror
+
cwd = py.path.local(__file__).dirpath()
eci = ExternalCompilationInfo(
includes=[cwd.join('locale_codec.h')],
@@ -56,7 +58,7 @@
errorpos = rffi.cast(lltype.Signed, errorposp[0])
if errorpos == -1:
raise MemoryError
- errmsg = _errmsg("pypy_wchar2char")
+ errmsg = _errmsg(u"pypy_wchar2char")
errorhandler('strict', 'filesystemencoding', errmsg, u,
errorpos, errorpos + 1)
return rffi.charp2str(sbuf)
@@ -79,7 +81,7 @@
ubuf = pypy_char2wchar(sbuf, sizep)
try:
if ubuf is None:
- errmsg = _errmsg("pypy_char2wchar")
+ errmsg = _errmsg(u"pypy_char2wchar")
errorhandler('strict', 'filesystemencoding', errmsg, s, 0, 1)
size = rffi.cast(lltype.Signed, sizep[0])
return rawwcharp2unicoden(ubuf, size)
@@ -89,8 +91,8 @@
def _errmsg(what):
from rpython.rlib import rposix
- errmsg = os.strerror(rposix.get_errno())
- return "%s failed" % what if errmsg is None else errmsg
+ errmsg = _strerror(rposix.get_errno())
+ return u"%s failed" % what if errmsg is None else errmsg
class scoped_unicode2rawwcharp:
diff --git a/pypy/module/cpyext/pyerrors.py b/pypy/module/cpyext/pyerrors.py
--- a/pypy/module/cpyext/pyerrors.py
+++ b/pypy/module/cpyext/pyerrors.py
@@ -1,7 +1,7 @@
import os
from rpython.rtyper.lltypesystem import rffi, lltype
-from pypy.interpreter.error import OperationError
+from pypy.interpreter.error import OperationError, strerror as _strerror
from pypy.interpreter import pytraceback
from pypy.module.cpyext.api import cpython_api, CANNOT_FAIL, CONST_STRING
from pypy.module.exceptions.interp_exceptions import W_RuntimeWarning
@@ -164,7 +164,7 @@
Return value: always NULL."""
# XXX Doesn't actually do anything with PyErr_CheckSignals.
errno = rffi.cast(lltype.Signed, rposix._get_errno())
- msg = os.strerror(errno)
+ msg = _strerror(errno)
if w_value:
w_error = space.call_function(w_type,
space.wrap(errno),
diff --git a/pypy/module/posix/interp_posix.py b/pypy/module/posix/interp_posix.py
--- a/pypy/module/posix/interp_posix.py
+++ b/pypy/module/posix/interp_posix.py
@@ -9,7 +9,8 @@
from rpython.rtyper.module.ll_os import RegisterOs
from pypy.interpreter.gateway import unwrap_spec, WrappedDefault
-from pypy.interpreter.error import OperationError, wrap_oserror, wrap_oserror2
+from pypy.interpreter.error import (OperationError, wrap_oserror,
+ wrap_oserror2, strerror as _strerror)
from pypy.interpreter.executioncontext import ExecutionContext
@@ -477,11 +478,10 @@
def strerror(space, errno):
"""Translate an error code to a message string."""
try:
- text = os.strerror(errno)
+ return space.wrap(_strerror(errno))
except ValueError:
raise OperationError(space.w_ValueError,
space.wrap("strerror() argument out of range"))
- return space.wrap(text)
def getlogin(space):
"""Return the currently logged in user."""
diff --git a/pypy/module/time/interp_time.py b/pypy/module/time/interp_time.py
--- a/pypy/module/time/interp_time.py
+++ b/pypy/module/time/interp_time.py
@@ -1,6 +1,6 @@
from rpython.rtyper.tool import rffi_platform as platform
from rpython.rtyper.lltypesystem import rffi
-from pypy.interpreter.error import OperationError, oefmt
+from pypy.interpreter.error import OperationError, oefmt, strerror as _strerror
from pypy.interpreter.gateway import unwrap_spec
from rpython.rtyper.lltypesystem import lltype
from rpython.rlib.rarithmetic import intmask
@@ -306,7 +306,7 @@
def _get_error_msg():
errno = rposix.get_saved_errno()
- return os.strerror(errno)
+ return _strerror(errno)
if sys.platform != 'win32':
@unwrap_spec(secs=float)
@@ -404,7 +404,7 @@
lltype.free(t_ref, flavor='raw')
if not pbuf:
raise OperationError(space.w_ValueError,
- space.wrap(_get_error_msg()))
+ space.wrap(_get_error_msg()))
return pbuf
tup_w = space.fixedview(w_tup)
More information about the pypy-commit
mailing list