Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/encoding.py @ 16493:72c6240a4b7d stable
encoding: protect against non-ascii default encoding
If the default python encoding was changed from ascii, the attempt to
encode as ascii before lower() could throw a UnicodeEncodeError.
Catch UnicodeError instead to prevent an unhandled exception.
author | Cesar Mena <cesarmena@gmail.com> |
---|---|
date | Sun, 22 Apr 2012 21:27:52 -0400 |
parents | c481761033bd |
children | 3745ae495ce5 |
comparison
equal
deleted
inserted
replaced
16492:774e2dcd0a65 | 16493:72c6240a4b7d |
---|---|
167 | 167 |
168 def lower(s): | 168 def lower(s): |
169 "best-effort encoding-aware case-folding of local string s" | 169 "best-effort encoding-aware case-folding of local string s" |
170 try: | 170 try: |
171 return s.encode('ascii').lower() | 171 return s.encode('ascii').lower() |
172 except UnicodeDecodeError: | 172 except UnicodeError: |
173 pass | 173 pass |
174 try: | 174 try: |
175 if isinstance(s, localstr): | 175 if isinstance(s, localstr): |
176 u = s._utf8.decode("utf-8") | 176 u = s._utf8.decode("utf-8") |
177 else: | 177 else: |