[PATCH] windows: import the pure version of osutil correctly

Sune Foldager cryo at cyanite.org
Wed May 13 08:42:02 CDT 2009


# HG changeset patch
# User Sune Foldager <cryo at cyanite.org>
# Date 1242221816 -7200
# Node ID 718c71256f437b829eb1ee2cf9a19388696032dd
# Parent  94e91205d9b6f7272d6a1b61c39de4c2555df240
windows: import the pure version of osutil correctly

The pure version of osutil doen't have a posixfile attribute.
This trips up demandimport, which assumes it's a submodule. When
it tries to load it, it ends up loading the global posixfile
module instead. The original osutil.posixfile is a function.

In the long term, demandimport should probably be fixed to
handle such cases correctly.

diff -r 94e91205d9b6 -r 718c71256f43 mercurial/windows.py
--- a/mercurial/windows.py	Tue May 12 10:03:36 2009 -0400
+++ b/mercurial/windows.py	Wed May 13 15:36:56 2009 +0200
@@ -271,10 +271,19 @@
     # override functions with win32 versions if possible
     from win32 import *
     if not _is_win_9x():
+
+        # slow, unbuffered POSIX-like file support
         posixfile = posixfile_nt
+
+        # fast, buffered POSIX-like file support
         try:
-            # fast, buffered POSIX-like file support
-            from osutil import posixfile as _posixfile
+            # The pure version of osutil doesn't have posixfile,
+            # which will trip up demandimport which will in turn
+            # end up loading the global posixfile module.
+            # To avoid this, we import it directly instead.
+            mod = __import__('osutil.posixfile')
+            _posixfile = getattr(_posixfile, 'posixfile')
+
             def posixfile(name, mode='r', buffering=-1):
                 # wrap osutil.posixfile to provide friendlier exceptions
                 try:
@@ -283,7 +292,7 @@
                     raise WinIOError(err)
             posixfile.__doc__ = _posixfile.__doc__
         except ImportError:
-            # slow, unbuffered POSIX-like file support
-            posixfile = posixfile_nt
+            pass
+
 except ImportError:
     posixfile = file


More information about the Mercurial-devel mailing list