]> git.ozlabs.org Git - patchwork/blobdiff - patchwork/parser.py
trivial: Remove Python < 2.5 code
[patchwork] / patchwork / parser.py
index a51a7b609af0c1df36a85f0d9fac4670efd9322e..13b4466a4b145cfc667018ad804e9a68299c00c4 100644 (file)
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
 
+import hashlib
 import re
-
-try:
-    import hashlib
-    sha1_hash = hashlib.sha1
-except ImportError:
-    import sha
-    sha1_hash = sha.sha
+from collections import Counter
 
 _hunk_re = re.compile('^\@\@ -\d+(?:,(\d+))? \+\d+(?:,(\d+))? \@\@')
 _filename_re = re.compile('^(---|\+\+\+) (\S+)')
@@ -193,7 +188,7 @@ def hash_patch(str):
     str = str.strip() + '\n'
 
     prefixes = ['-', '+', ' ']
-    hash = sha1_hash()
+    hash = hashlib.sha1()
 
     for line in str.split('\n'):
 
@@ -234,6 +229,14 @@ def hash_patch(str):
 
     return hash
 
+def extract_tags(content, tags):
+    counts = Counter()
+
+    for tag in tags:
+        regex = re.compile(tag.pattern, re.MULTILINE | re.IGNORECASE)
+        counts[tag] = len(regex.findall(content))
+
+    return counts
 
 def main(args):
     from optparse import OptionParser