Show More
@@ -21,13 +21,18 b' import imp' | |||||
21 | # Python compatibility |
|
21 | # Python compatibility | |
22 |
|
22 | |||
23 | def sha1(s): |
|
23 | def sha1(s): | |
|
24 | return _fastsha1(s) | |||
|
25 | ||||
|
26 | def _fastsha1(s): | |||
|
27 | # This function will import sha1 from hashlib or sha (whichever is | |||
|
28 | # available) and overwrite itself with it on the first call. | |||
|
29 | # Subsequent calls will go directly to the imported function. | |||
24 | try: |
|
30 | try: | |
25 | import hashlib |
|
31 | from hashlib import sha1 as _sha1 | |
26 | _sha1 = hashlib.sha1 |
|
|||
27 | except ImportError: |
|
32 | except ImportError: | |
28 | from sha import sha as _sha1 |
|
33 | from sha import sha as _sha1 | |
29 | global sha1 |
|
34 | global _fastsha1 | |
30 | sha1 = _sha1 |
|
35 | _fastsha1 = _sha1 | |
31 | return _sha1(s) |
|
36 | return _sha1(s) | |
32 |
|
37 | |||
33 | import subprocess |
|
38 | import subprocess |
General Comments 0
You need to be logged in to leave comments.
Login now