[PATCH] win32mbcs: add reversing wrapper for some unicode-incompatible functions

Shun-ichi Goto shunichi.goto at gmail.com
Wed Oct 17 04:34:52 CDT 2012


2012/10/17 Matt Mackall <mpm at selenic.com>:
>> win32mbcs: add reversing wrapper for some unicode-incompatible functions.
>
> Looks like we're waiting on a cleaned-up version of this following
> foozy's review.

Sorry for bothering you, I had forgot sending modified version.

> My take is that this is a bit too hard to read. Something like this
> would be better:

OK, I've taken your suggestion and code sample (with some typo fix).
Send new patch in another email.

By the way, there is an another solution by making encoding.lower() and upper()
unicode compatible. With this change, current win32mbcs.py works correctly.
Is this better?

diff -r d34ba4991188 mercurial/encoding.py
--- a/mercurial/encoding.py	Fri Sep 21 19:27:22 2012 +0200
+++ b/mercurial/encoding.py	Wed Oct 17 13:11:35 2012 +0900
@@ -167,6 +167,8 @@

 def lower(s):
     "best-effort encoding-aware case-folding of local string s"
+    if isinstance(s, unicode):
+        return s.lower()
     try:
         s.decode('ascii') # throw exception for non-ASCII character
         return s.lower()
@@ -189,6 +191,8 @@

 def upper(s):
     "best-effort encoding-aware case-folding of local string s"
+    if isinstance(s, unicode):
+        return s.lower()
     try:
         s.decode('ascii') # throw exception for non-ASCII character
         return s.upper()



> While we're on the topic, this bit looks iffy:
>
>     for arg in args:
>         if isinstance(arg, argtype):
>             return func(*args, **kwds)

I agree. At least, kwds should be checked.
And also it should be checked recursively for the case of list / tuple / dict.
I already have a code to check all the arguments recursively like
decode() / encode()
but I cannot decide to use it.

-- 
Shun-ichi GOTO


More information about the Mercurial-devel mailing list