From 91022c4325f478f4d01872d70426a62e1d4fea47 Mon Sep 17 00:00:00 2001 From: asciimoo Date: Sun, 27 May 2012 20:17:43 +0200 Subject: [PATCH] [fix] iteration fixes --- README.markdown | 2 +- exrex.py | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/README.markdown b/README.markdown index 3bc7fb4..20134b1 100644 --- a/README.markdown +++ b/README.markdown @@ -39,7 +39,7 @@ Example: ### TODO - * Memory usage reduction (!generators!) (80%) + * Memory usage reduction (!generators!) (70%) * Count the number of matching strings (0%) * Command line switches to change default character sets/ranges (eg. for '.','\s'..) (0%) diff --git a/exrex.py b/exrex.py index f6c807b..7a6e31c 100644 --- a/exrex.py +++ b/exrex.py @@ -28,8 +28,8 @@ CATEGORIES = {'category_space' : sre_parse.WHITESPACE def _p(d, append=False): """docstring for _p""" #print d - ret =[] - ranges = [''] + ret = [''] + ranges = [] if not isinstance(d, list): print '[!] not a list: %r' % d yield None @@ -64,9 +64,10 @@ def _p(d, append=False): elif i[0] == 'range': ranges.extend(map(chr, range(i[1][0], i[1][1]+1))) elif i[0] == 'max_repeat': + tmp_ret = list(ret) chars = [x for x in _p(list(i[1][2])) if x != ''] ran = (i[1][0], i[1][1]+1) - ret = (r+''.join(piece) for r in ret for rep in range(*ran) for piece in product(*repeat(chars, rep))) + ret = (r+''.join(piece) for r in tmp_ret for rep in range(*ran) for piece in product(*repeat(chars, rep))) elif i[0] == 'category': cat = CATEGORIES.get(i[1], ['']) ret = (r+c for r in ret for c in cat) @@ -91,7 +92,7 @@ def _p(d, append=False): def parse(s): """docstring for parse""" r = sre_parse.parse(s) - #print r + print r return _p(list(r))