[PATCH 5 of 5] Introduce a mechanism to handle MBCS file name correctly on Windows
Matt Mackall
mpm at selenic.com
Mon Jan 7 23:09:31 UTC 2008
On Sun, 2008-01-06 at 21:26 +0900, Shun-ichi Goto wrote:
> + # codec and alias names of sjis and big5 to be faked.
> + _problematic_encodings = frozenset([
> + 'big5', 'big5-tw', 'csbig5',
> + 'big5hkscs', 'big5-hkscs', 'hkscs',
> + 'cp932', '932', 'ms932', 'mskanji', 'ms-kanji',
> + 'shift_jis', 'csshiftjis', 'shiftjis', 'sjis', 's_jis',
> + 'shift_jis_2004', 'shiftjis2004', 'sjis_2004', 'sjis2004',
> + 'shift_jisx0213', 'shiftjisx0213', 'sjisx0213', 's_jisx0213',
> + ])
Meh. I'm not a fan of sets. This would have been cleaner as
"""strings""".split()
> + def _withdecoding(func):
> + """Return wrapper function for func to oprerate MBCS string.
> + The wrapper function trys decoding if need and do the job.
> + Return value is encoded if deocded."""
> +
> + def encode(s):
> + if isinstance(s, unicode):
> + return s.encode(_encoding)
> + else:
> + return s
I assume we only get unicode strings passed in because these things call
each other internally? Messing with the Python internals like this is a
little scary and it'll break things that import Mercurial modules.
> +
> + def wrapped(*args):
> + # fake is only for relevant environment.
> + if _encoding.lower() not in _problematic_encodings:
> + return func(*args)
This is the wrong place to do this. If you move it up a layer, you can
do "return func" and skip a level of indirection. This is all probably
overly complex as well.
--
Mathematics is the supreme nostalgia of our time.
More information about the Mercurial-devel
mailing list