amprolla

devuan's apt repo merger
git clone git://parazyd.org/amprolla.git
Log | Files | Refs | README | LICENSE

commit ad4a91c066ce306caf619fc3783cc963ab9c4802
parent 742e8d0e7f1aede6dac09ed92cba828378dfab24
Author: Merlijn Wajer <merlijn@wizzup.org>
Date:   Fri, 26 May 2017 00:41:00 +0200

Increase parsing speed by not using regex

Diffstat:
Mlib/parse.py | 26+++++++++++++++++++++++++-
1 file changed, 25 insertions(+), 1 deletion(-)

diff --git a/lib/parse.py b/lib/parse.py @@ -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]