encoding: use getattr isntead of hasattr stable
authorAugie Fackler <durin42@gmail.com>
Mon, 25 Jul 2011 15:19:43 -0500
branchstable
changeset 15064 1f581a8b1948
parent 15063 c20688b7c061
child 15065 24a6c3f903bb
encoding: use getattr isntead of hasattr
mercurial/encoding.py
--- a/mercurial/encoding.py	Thu Aug 25 21:25:14 2011 +0200
+++ 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):