# HG changeset patch # User Martin Geisler # Date 1343080522 21600 # Node ID 3745ae495ce5c6d021d5519a436b2f51005e8d8d # Parent 0cfece81e051c253d9cf8b7cfacaaf54bafe99ce encoding: use s.decode to trigger UnicodeDecodeError When calling encode on a str, the string is first decoded using the default encoding and then encoded. So s.encode('ascii') == s.decode().encode('ascii') We don't care about the encode step here -- we're just after the UnicodeDecodeError raised by decode if it finds a non-ASCII character. This way is also marginally faster since it saves the construction of the extra str object. diff -r 0cfece81e051 -r 3745ae495ce5 mercurial/encoding.py --- a/mercurial/encoding.py Sun Jul 22 13:16:45 2012 +0200 +++ b/mercurial/encoding.py Mon Jul 23 15:55:22 2012 -0600 @@ -168,8 +168,9 @@ def lower(s): "best-effort encoding-aware case-folding of local string s" try: - return s.encode('ascii').lower() - except UnicodeError: + s.decode('ascii') # throw exception for non-ASCII character + return s.lower() + except UnicodeDecodeError: pass try: if isinstance(s, localstr):