Amaury Forgeot d'Arc avatar Amaury Forgeot d'Arc committed f444249

unicode version of nt._getfullpathname()

Comments (0)

Files changed (4)

pypy/module/posix/interp_posix.py

 
 def _getfullpathname(space, path):
     """helper for ntpath.abspath """
-    posix = __import__(os.name) # nt specific
     try:
-        fullpath = posix._getfullpathname(path)
+        dispatch_filename(rposix._getfullpathname)(space, w_path)
     except OSError, e:
-        raise wrap_oserror(space, e, path)
-    else: 
+        raise wrap_oserror2(space, e, w_path)
+    else:
         return space.wrap(fullpath)
-_getfullpathname.unwrap_spec = [ObjSpace, str]
+_getfullpathname.unwrap_spec = [ObjSpace, W_Root]
 
 def getcwd(space):
     """Return the current working directory."""

pypy/rlib/rposix.py

         return os.rmdir(path)
     else:
         return os.rmdir(path.encode())
+
+if os.name == 'nt':
+    import nt
+    def _getfullpathname(path):
+        if isinstance(path, str):
+            return nt._getfullpathname(path)
+        else:
+            return nt._getfullpathname(path.encode())

pypy/rlib/rwin32.py

         LPCVOID = rffi_platform.SimpleType("LPCVOID", rffi.VOIDP)
         LPSTR = rffi_platform.SimpleType("LPSTR", rffi.CCHARP)
         LPCSTR = rffi_platform.SimpleType("LPCSTR", rffi.CCHARP)
+        LPWSTR = rffi_platform.SimpleType("LPWSTR", rffi.CWCHARP)
         LPCWSTR = rffi_platform.SimpleType("LPCWSTR", rffi.CWCHARP)
         LPDWORD = rffi_platform.SimpleType("LPDWORD", rffi.INTP)
         SIZE_T = rffi_platform.SimpleType("SIZE_T", rffi.SIZE_T)

pypy/rpython/module/ll_os.py

         # to get a correct implementation of os.abspath
         # XXX why do we ignore WINAPI conventions everywhere?
         LPSTRP = rffi.CArrayPtr(rwin32.LPSTR)
-        # XXX unicode?
         GetFullPathName = self.llexternal(
             'GetFullPathNameA',
             [rwin32.LPCSTR,
                       "ll_os.posix__getfullpathname",
                       llimpl=_getfullpathname_llimpl)
 
+    @registering_unicode_version(getattr(posix, '_getfullpathname', None),
+                                 1, [0], sys.platform=='win32')
+    def register_posix__getfullpathname_unicode(self):
+        from pypy.rlib import rwin32
+        # this nt function is not exposed via os, but needed
+        # to get a correct implementation of os.abspath
+        # XXX why do we ignore WINAPI conventions everywhere?
+        LPWSTRP = rffi.CArrayPtr(rwin32.LPWSTR)
+        GetFullPathName = self.llexternal(
+            'GetFullPathNameW',
+            [rwin32.LPCWSTR,
+             rwin32.DWORD,
+             rwin32.LPSTR,
+             rffi.CArrayPtr(rwin32.LPWSTR)],
+            rwin32.DWORD)
+
+        def _getfullpathname_llimpl(lpFileName):
+            nBufferLength = rwin32.MAX_PATH + 1
+            lpBuffer = lltype.malloc(rwin32.LPWSTR.TO, nBufferLength, flavor='raw')
+            try:
+                res = GetFullPathName(
+                    lpFileName, rffi.cast(rwin32.DWORD, nBufferLength),
+                    lpBuffer, lltype.nullptr(LPWSTRP.TO))
+                if res == 0:
+                    raise rwin32.lastWindowsError("_getfullpathname failed")
+                result = rffi.wcharp2unicode(lpBuffer)
+                return result
+            finally:
+                lltype.free(lpBuffer, flavor='raw')
+
+        return extdef([unicode],  # a single argument which is a str
+                      unicode,    # returns a string
+                      "ll_os.posix__wgetfullpathname",
+                      llimpl=_getfullpathname_llimpl)
+
     @registering(os.getcwd)
     def register_os_getcwd(self):
         os_getcwd = self.llexternal(underscore_on_windows + 'getcwd',
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.