Mercurial > public > mercurial-scm > hg
comparison mercurial/encoding.py @ 15064:1f581a8b1948 stable
encoding: use getattr isntead of hasattr
author | Augie Fackler <durin42@gmail.com> |
---|---|
date | Mon, 25 Jul 2011 15:19:43 -0500 |
parents | e38846a79a23 |
children | 24efa83d81cb |
comparison
equal
deleted
inserted
replaced
15063:c20688b7c061 | 15064:1f581a8b1948 |
---|---|
138 ambiguous = os.environ.get("HGENCODINGAMBIGUOUS", "narrow") | 138 ambiguous = os.environ.get("HGENCODINGAMBIGUOUS", "narrow") |
139 | 139 |
140 def colwidth(s): | 140 def colwidth(s): |
141 "Find the column width of a UTF-8 string for display" | 141 "Find the column width of a UTF-8 string for display" |
142 d = s.decode(encoding, 'replace') | 142 d = s.decode(encoding, 'replace') |
143 if hasattr(unicodedata, 'east_asian_width'): | 143 eaw = getattr(unicodedata, 'east_asian_width', None) |
144 if eaw is not None: | |
144 wide = "WF" | 145 wide = "WF" |
145 if ambiguous == "wide": | 146 if ambiguous == "wide": |
146 wide = "WFA" | 147 wide = "WFA" |
147 w = unicodedata.east_asian_width | 148 return sum([eaw(c) in wide and 2 or 1 for c in d]) |
148 return sum([w(c) in wide and 2 or 1 for c in d]) | |
149 return len(d) | 149 return len(d) |
150 | 150 |
151 def lower(s): | 151 def lower(s): |
152 "best-effort encoding-aware case-folding of local string s" | 152 "best-effort encoding-aware case-folding of local string s" |
153 try: | 153 try: |