Mercurial > hg
comparison mercurial/util.py @ 15656:4f5a78fa4917
util: clean up function ordering
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Thu, 15 Dec 2011 14:59:22 -0600 |
parents | ec8a49c46d7e |
children | d976b1ef6760 |
comparison
equal
deleted
inserted
replaced
15655:5402fd9dd13e | 15656:4f5a78fa4917 |
---|---|
72 unlinkpath = platform.unlinkpath | 72 unlinkpath = platform.unlinkpath |
73 username = platform.username | 73 username = platform.username |
74 | 74 |
75 # Python compatibility | 75 # Python compatibility |
76 | 76 |
77 _notset = object() | |
78 | |
79 def safehasattr(thing, attr): | |
80 return getattr(thing, attr, _notset) is not _notset | |
81 | |
77 def sha1(s=''): | 82 def sha1(s=''): |
78 ''' | 83 ''' |
79 Low-overhead wrapper around Python's SHA support | 84 Low-overhead wrapper around Python's SHA support |
80 | 85 |
81 >>> f = _fastsha1 | 86 >>> f = _fastsha1 |
84 >>> a.hexdigest() | 89 >>> a.hexdigest() |
85 'da39a3ee5e6b4b0d3255bfef95601890afd80709' | 90 'da39a3ee5e6b4b0d3255bfef95601890afd80709' |
86 ''' | 91 ''' |
87 | 92 |
88 return _fastsha1(s) | 93 return _fastsha1(s) |
89 | |
90 _notset = object() | |
91 def safehasattr(thing, attr): | |
92 return getattr(thing, attr, _notset) is not _notset | |
93 | 94 |
94 def _fastsha1(s=''): | 95 def _fastsha1(s=''): |
95 # This function will import sha1 from hashlib or sha (whichever is | 96 # This function will import sha1 from hashlib or sha (whichever is |
96 # available) and overwrite itself with it on the first call. | 97 # available) and overwrite itself with it on the first call. |
97 # Subsequent calls will go directly to the imported function. | 98 # Subsequent calls will go directly to the imported function. |