|
138 | 138 | """
|
139 | 139 |
|
140 | 140 | import gyp.common
|
| 141 | +import hashlib |
141 | 142 | import posixpath
|
142 | 143 | import re
|
143 | 144 | import struct
|
144 | 145 | import sys
|
145 | 146 |
|
146 |
| -# hashlib is supplied as of Python 2.5 as the replacement interface for sha |
147 |
| -# and other secure hashes. In 2.6, sha is deprecated. Import hashlib if |
148 |
| -# available, avoiding a deprecation warning under 2.6. Import sha otherwise, |
149 |
| -# preserving 2.4 compatibility. |
150 | 147 | try:
|
151 |
| - import hashlib |
152 |
| - _new_sha1 = hashlib.sha1 |
153 |
| -except ImportError: |
154 |
| - import sha |
155 |
| - _new_sha1 = sha.new |
| 148 | + basestring, cmp, unicode |
| 149 | +except NameError: # Python 3 |
| 150 | + basestring = unicode = str |
| 151 | + def cmp(x, y): |
| 152 | + return (x > y) - (x < y) |
156 | 153 |
|
157 | 154 |
|
158 | 155 | # See XCObject._EncodeString. This pattern is used to determine when a string
|
@@ -324,8 +321,7 @@ def Copy(self):
|
324 | 321 | that._properties[key] = new_value
|
325 | 322 | else:
|
326 | 323 | that._properties[key] = value
|
327 |
| - elif isinstance(value, str) or isinstance(value, unicode) or \ |
328 |
| - isinstance(value, int): |
| 324 | + elif isinstance(value, (basestring, int)): |
329 | 325 | that._properties[key] = value
|
330 | 326 | elif isinstance(value, list):
|
331 | 327 | if is_strong:
|
@@ -422,7 +418,7 @@ def _HashUpdate(hash, data):
|
422 | 418 | hash.update(data)
|
423 | 419 |
|
424 | 420 | if seed_hash is None:
|
425 |
| - seed_hash = _new_sha1() |
| 421 | + seed_hash = hashlib.sha1() |
426 | 422 |
|
427 | 423 | hash = seed_hash.copy()
|
428 | 424 |
|
@@ -788,8 +784,7 @@ def UpdateProperties(self, properties, do_copy=False):
|
788 | 784 | self._properties[property] = value.Copy()
|
789 | 785 | else:
|
790 | 786 | self._properties[property] = value
|
791 |
| - elif isinstance(value, str) or isinstance(value, unicode) or \ |
792 |
| - isinstance(value, int): |
| 787 | + elif isinstance(value, (basestring, int)): |
793 | 788 | self._properties[property] = value
|
794 | 789 | elif isinstance(value, list):
|
795 | 790 | if is_strong:
|
|
0 commit comments