tIncrease parsing speed by not using regex - amprolla - devuan's apt repo merger
HTML git clone git://parazyd.org/amprolla.git
DIR Log
DIR Files
DIR Refs
DIR README
DIR LICENSE
---
DIR commit ad4a91c066ce306caf619fc3783cc963ab9c4802
DIR parent 742e8d0e7f1aede6dac09ed92cba828378dfab24
HTML Author: Merlijn Wajer <merlijn@wizzup.org>
Date: Fri, 26 May 2017 00:41:00 +0200
Increase parsing speed by not using regex
Diffstat:
M lib/parse.py | 26 +++++++++++++++++++++++++-
1 file changed, 25 insertions(+), 1 deletion(-)
---
DIR diff --git a/lib/parse.py b/lib/parse.py
t@@ -35,10 +35,34 @@ def parse_release(reltext):
_hash[(i.split()[2])] = i.split()[0]
return _hash
-PACKAGES_REGEX = re.compile('([A-Za-z0-9\-]+): ')
def parse_package(entry):
""" Parses a single Packages entry """
+ pkgs = {}
+
+ contents = entry.split('\n')
+
+ key = ''
+ value = ''
+ for line in contents:
+ if line.startswith(' '):
+ value += '\n' + line
+ else:
+ pkgs[key] = value
+
+ v = line.split(':', 1)
+ key = v[0]
+ value = v[1][1:]
+
+ if key:
+ pkgs[key] = value
+
+ return pkgs
+
+
+PACKAGES_REGEX = re.compile('([A-Za-z0-9\-]+): ')
+def parse_package_re(entry):
+ """ Parses a single Packages entry """
contents = PACKAGES_REGEX.split(entry)[1:] # Throw away the first ''
keys = contents[::2]