X-Git-Url: https://git.ozlabs.org/?a=blobdiff_plain;f=apps%2Fpatchwork%2Fparser.py;h=021dbcdc36ae59bc382ad4cdba458be310f3495e;hb=690043e0318f5cd8110fca2945f2ca3763597343;hp=ecc1d4b0f1e5ce962f4d37a3afcea23867769d90;hpb=c561ebe710d6e6a43aa4afc6c2036a215378ce87;p=patchwork diff --git a/apps/patchwork/parser.py b/apps/patchwork/parser.py index ecc1d4b..021dbcd 100644 --- a/apps/patchwork/parser.py +++ b/apps/patchwork/parser.py @@ -21,7 +21,12 @@ 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: