]> git.ozlabs.org Git - patchwork/blobdiff - apps/patchwork/parser.py
Add pwclientrc configuration file sample for each project
[patchwork] / apps / patchwork / parser.py
index ecc1d4b0f1e5ce962f4d37a3afcea23867769d90..021dbcdc36ae59bc382ad4cdba458be310f3495e 100644 (file)
 
 
 import re
-import hashlib
+try:
+    import hashlib
+    sha1_hash = hashlib.sha1
+except ImportError:
+    import sha
+    sha1_hash = sha.sha
 
 _hunk_re = re.compile('^\@\@ -\d+(?:,(\d+))? \+\d+(?:,(\d+))? \@\@')
 _filename_re = re.compile('^(---|\+\+\+) (\S+)')
@@ -158,15 +163,15 @@ def patch_hash(str):
     lines = str.split('\n')
 
     prefixes = ['-', '+', ' ']
-    hash = hashlib.sha1()
+    hash = sha1_hash()
 
     for line in str.split('\n'):
 
         if len(line) <= 0:
             continue
 
-       hunk_match = _hunk_re.match(line)
-       filename_match = _filename_re.match(line)
+        hunk_match = _hunk_re.match(line)
+        filename_match = _filename_re.match(line)
 
         if filename_match:
             # normalise -p1 top-directories
@@ -179,7 +184,7 @@ def patch_hash(str):
             line = filename_match.group(1) + ' ' + filename
 
             
-       elif hunk_match:
+        elif hunk_match:
             # remove line numbers
             def fn(x):
                 if not x: