Mercurial > public > mercurial-scm > hg
comparison mercurial/util.py @ 14942:5b072d4b62f2
safehasattr: new function to work around hasattr being broken
author | Augie Fackler <durin42@gmail.com> |
---|---|
date | Mon, 25 Jul 2011 14:59:55 -0500 |
parents | 2aa3e07b2f07 |
children | b7dbe957585c |
comparison
equal
deleted
inserted
replaced
14941:4a28cb4df1f8 | 14942:5b072d4b62f2 |
---|---|
73 # Python compatibility | 73 # Python compatibility |
74 | 74 |
75 def sha1(s): | 75 def sha1(s): |
76 return _fastsha1(s) | 76 return _fastsha1(s) |
77 | 77 |
78 _notset = object() | |
79 def safehasattr(thing, attr): | |
80 return getattr(thing, attr, _notset) is not _notset | |
81 | |
78 def _fastsha1(s): | 82 def _fastsha1(s): |
79 # This function will import sha1 from hashlib or sha (whichever is | 83 # This function will import sha1 from hashlib or sha (whichever is |
80 # available) and overwrite itself with it on the first call. | 84 # available) and overwrite itself with it on the first call. |
81 # Subsequent calls will go directly to the imported function. | 85 # Subsequent calls will go directly to the imported function. |
82 if sys.version_info >= (2, 5): | 86 if sys.version_info >= (2, 5): |