changeset 14951:61807854004e

encoding: use getattr isntead of hasattr
author Augie Fackler <durin42@gmail.com>
date Mon, 25 Jul 2011 15:19:43 -0500
parents 144e97421f6b
children 4c523a2af6e7
files mercurial/encoding.py
diffstat 1 files changed, 3 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/encoding.py	Mon Jul 25 15:17:47 2011 -0500
+++ b/mercurial/encoding.py	Mon Jul 25 15:19:43 2011 -0500
@@ -140,12 +140,12 @@
 def colwidth(s):
     "Find the column width of a UTF-8 string for display"
     d = s.decode(encoding, 'replace')
-    if hasattr(unicodedata, 'east_asian_width'):
+    eaw = getattr(unicodedata, 'east_asian_width', None)
+    if eaw is not None:
         wide = "WF"
         if ambiguous == "wide":
             wide = "WFA"
-        w = unicodedata.east_asian_width
-        return sum([w(c) in wide and 2 or 1 for c in d])
+        return sum([eaw(c) in wide and 2 or 1 for c in d])
     return len(d)
 
 def lower(s):