comparison hgext/win32mbcs.py @ 9098:5e4654f5522d

win32mbcs: look up modules using sys.modules (issue1729) globals()[module] doesn't work for modules inside of packages, such as os.path.
author Brodie Rao <me+hg@dackz.net>
date Wed, 08 Jul 2009 09:48:48 -0400
parents f87884329419
children 623f96ae3a26
comparison
equal deleted inserted replaced
9097:431462bd8478 9098:5e4654f5522d
36 Path encoding conversion are done between Unicode and 36 Path encoding conversion are done between Unicode and
37 encoding.encoding which is decided by Mercurial from current locale 37 encoding.encoding which is decided by Mercurial from current locale
38 setting or HGENCODING. 38 setting or HGENCODING.
39 ''' 39 '''
40 40
41 import os 41 import os, sys
42 from mercurial.i18n import _ 42 from mercurial.i18n import _
43 from mercurial import util, encoding 43 from mercurial import util, encoding
44 44
45 def decode(arg): 45 def decode(arg):
46 if isinstance(arg, str): 46 if isinstance(arg, str):
77 # continue with calling original function. 77 # continue with calling original function.
78 raise util.Abort(_("[win32mbcs] filename conversion fail with" 78 raise util.Abort(_("[win32mbcs] filename conversion fail with"
79 " %s encoding\n") % (encoding.encoding)) 79 " %s encoding\n") % (encoding.encoding))
80 80
81 def wrapname(name): 81 def wrapname(name):
82 idx = name.rfind('.') 82 module, name = name.rsplit('.', 1)
83 module = name[:idx] 83 module = sys.modules[module]
84 name = name[idx+1:]
85 module = globals()[module]
86 func = getattr(module, name) 84 func = getattr(module, name)
87 def f(*args): 85 def f(*args):
88 return wrapper(func, args) 86 return wrapper(func, args)
89 try: 87 try:
90 f.__name__ = func.__name__ # fail with python23 88 f.__name__ = func.__name__ # fail with python23
95 # List of functions to be wrapped. 93 # List of functions to be wrapped.
96 # NOTE: os.path.dirname() and os.path.basename() are safe because 94 # NOTE: os.path.dirname() and os.path.basename() are safe because
97 # they use result of os.path.split() 95 # they use result of os.path.split()
98 funcs = '''os.path.join os.path.split os.path.splitext 96 funcs = '''os.path.join os.path.split os.path.splitext
99 os.path.splitunc os.path.normpath os.path.normcase os.makedirs 97 os.path.splitunc os.path.normpath os.path.normcase os.makedirs
100 util.endswithsep util.splitpath util.checkcase util.fspath''' 98 mercurial.util.endswithsep mercurial.util.splitpath mercurial.util.checkcase
99 mercurial.util.fspath'''
101 100
102 # codec and alias names of sjis and big5 to be faked. 101 # codec and alias names of sjis and big5 to be faked.
103 problematic_encodings = '''big5 big5-tw csbig5 big5hkscs big5-hkscs 102 problematic_encodings = '''big5 big5-tw csbig5 big5hkscs big5-hkscs
104 hkscs cp932 932 ms932 mskanji ms-kanji shift_jis csshiftjis shiftjis 103 hkscs cp932 932 ms932 mskanji ms-kanji shift_jis csshiftjis shiftjis
105 sjis s_jis shift_jis_2004 shiftjis2004 sjis_2004 sjis2004 104 sjis s_jis shift_jis_2004 shiftjis2004 sjis_2004 sjis2004