[pypy-commit] pypy py3.6: properly use fsencode on obscure nt._getfinalpathname, fixes translation
mattip
pypy.commits at gmail.com
Fri May 31 04:41:16 EDT 2019
Author: Matti Picus <matti.picus at gmail.com>
Branch: py3.6
Changeset: r96722:1e8797906e74
Date: 2019-05-31 11:40 +0300
http://bitbucket.org/pypy/pypy/changeset/1e8797906e74/
Log: properly use fsencode on obscure nt._getfinalpathname, fixes
translation
diff --git a/pypy/module/posix/interp_nt.py b/pypy/module/posix/interp_nt.py
--- a/pypy/module/posix/interp_nt.py
+++ b/pypy/module/posix/interp_nt.py
@@ -1,5 +1,6 @@
from rpython.rlib import rwin32
from rpython.rtyper.lltypesystem import lltype, rffi
+from rpython.rlib.objectmodel import specialize
from rpython.rlib.rwin32file import make_win32_traits
from rpython.rlib._os_support import UnicodeTraits
from rpython.translator import cdir
@@ -91,6 +92,7 @@
assert traits.str is unicode, 'Currently only handles unicode paths'
win32traits = make_traits(traits)
+ @specialize.argtype(0)
def _getfinalpathname_llimpl(path):
if not win32traits.check_GetFinalPathNameByHandle():
raise LLNotImplemented("GetFinalPathNameByHandle not available on "
@@ -122,7 +124,8 @@
VOLUME_NAME_DOS)
if result == 0:
raise rwin32.lastSavedWindowsError("GetFinalPathNameByHandle")
- return buf.str(rffi.cast(lltype.Signed, result))
+ res = buf.str(rffi.cast(lltype.Signed, result))
+ return res.encode('utf8'), len(res)
finally:
rwin32.CloseHandle(hFile)
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
@@ -2277,15 +2277,14 @@
space.newint(info[2])])
def _getfinalpathname(space, w_path):
- path = space.utf8_w(w_path).decode('utf-8')
try:
- result = nt._getfinalpathname(path)
+ s, lgt = dispatch_filename(nt._getfinalpathname)(space, w_path)
except nt.LLNotImplemented as e:
raise OperationError(space.w_NotImplementedError,
space.newtext(e.msg))
except OSError as e:
raise wrap_oserror2(space, e, w_path, eintr_retry=False)
- return space.newtext(result)
+ return space.newtext(s, lgt)
def chflags():
diff --git a/pypy/module/posix/test/test_nt.py b/pypy/module/posix/test/test_nt.py
--- a/pypy/module/posix/test/test_nt.py
+++ b/pypy/module/posix/test/test_nt.py
@@ -19,9 +19,9 @@
def test__getfinalpathname():
- path = __file__.decode('mbcs')
+ path = __file__.decode('utf-8')
try:
- result = nt._getfinalpathname(path)
+ result, lgt = nt._getfinalpathname(path)
except nt.LLNotImplemented:
py.test.skip("_getfinalpathname not supported on this platform")
assert os.path.exists(result)
diff --git a/pypy/objspace/std/objspace.py b/pypy/objspace/std/objspace.py
--- a/pypy/objspace/std/objspace.py
+++ b/pypy/objspace/std/objspace.py
@@ -383,7 +383,7 @@
def newbytearray(self, l):
return W_BytearrayObject(l)
- # XXX TODO - remove this and force all users to call with utf8
+ # XXX TODO - remove the specialization and force all users to call with utf8
@specialize.argtype(1)
def newtext(self, s, lgt=-1, unused=-1):
# the unused argument can be from something like
More information about the pypy-commit
mailing list