[PATCH 1 of 4] win32mbcs: look up modules using sys.modules (issue1729)

Shun-ichi Goto shunichi.goto at gmail.com
Thu Jul 9 08:57:35 CDT 2009


# HG changeset patch
# User Brodie Rao <me+hg at dackz.net>
# Date 1247060928 14400
# Node ID 1ea9bcb2d34907b0de2bba4cb2ed319a5f32b829
# Parent  95046688f80fbe481241ed3affeed205ce378b7e
win32mbcs: look up modules using sys.modules (issue1729)

globals()[module] doesn't work for modules inside of packages, such as
os.path.

diff -r 95046688f80f -r 1ea9bcb2d349 hgext/win32mbcs.py
--- a/hgext/win32mbcs.py	Sun Jul 05 18:52:55 2009 -0400
+++ b/hgext/win32mbcs.py	Wed Jul 08 09:48:48 2009 -0400
@@ -38,7 +38,7 @@
 setting or HGENCODING.
 '''
 
-import os
+import os, sys
 from mercurial.i18n import _
 from mercurial import util, encoding
 
@@ -79,10 +79,8 @@
                          " %s encoding\n") % (encoding.encoding))
 
 def wrapname(name):
-    idx = name.rfind('.')
-    module = name[:idx]
-    name = name[idx+1:]
-    module = globals()[module]
+    module, name = name.rsplit('.', 1)
+    module = sys.modules[module]
     func = getattr(module, name)
     def f(*args):
         return wrapper(func, args)
@@ -97,7 +95,8 @@
 #       they use result of os.path.split()
 funcs = '''os.path.join os.path.split os.path.splitext
  os.path.splitunc os.path.normpath os.path.normcase os.makedirs
- util.endswithsep util.splitpath util.checkcase util.fspath'''
+ mercurial.util.endswithsep mercurial.util.splitpath mercurial.util.checkcase
+ mercurial.util.fspath'''
 
 # codec and alias names of sjis and big5 to be faked.
 problematic_encodings = '''big5 big5-tw csbig5 big5hkscs big5-hkscs


More information about the Mercurial-devel mailing list