From 5d84d72f008804ca468858362331efca87103e19 Mon Sep 17 00:00:00 2001 From: grahams Date: Mon, 9 Feb 2009 06:04:42 +0800 Subject: [PATCH] Moved the "lj tag" regular expression objects to the global scope (so they don't need to be recompiled on each iteration). --suggestion by jparise Signed-off-by: Greg Hewgill --- convertdump.py | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/convertdump.py b/convertdump.py index c99fff9..9799cab 100755 --- a/convertdump.py +++ b/convertdump.py @@ -175,28 +175,43 @@ def addCommentsForId(outDoc, entry, username, id): if(parentId != ""): appendTextNode(outDoc, outComment, "parent_itemid", parentId) + +# regular expressions used in replaceLJTags() +# (global for later reuse - suggestion by jparise) + +userRE = re.compile('', re.IGNORECASE) +commRE = re.compile('', re.IGNORECASE) +namedCutRE = re.compile('', + re.IGNORECASE|re.DOTALL) +cutRE = re.compile('', re.IGNORECASE) +cutRE = re.compile('', re.IGNORECASE) +embedRE = re.compile('', re.IGNORECASE) + def replaceLJTags(entry): rv = entry - # replace lj user tags userRE = re.compile('', re.IGNORECASE) + commRE = re.compile('', re.IGNORECASE) + namedCutRE = re.compile('', + re.IGNORECASE|re.DOTALL) + cutRE = re.compile('', re.IGNORECASE) + cutRE = re.compile('', re.IGNORECASE) + embedRE = re.compile('', re.IGNORECASE) + + # replace lj user tags rv = re.sub(userRE, '\\1', rv) # replace lj comm tags - commRE = re.compile('', re.IGNORECASE) rv = re.sub(commRE, '\\1', rv) # replace lj-cut tags - namedCutRE = re.compile('', - re.IGNORECASE|re.DOTALL) rv = re.sub(namedCutRE, '', rv) - - cutRE = re.compile('', re.IGNORECASE) rv = re.sub(cutRE, '', rv) - - cutRE = re.compile('', re.IGNORECASE) rv = re.sub(cutRE, '', rv) + # replace lj-embed tags + rv = re.sub(embedRE, '', rv) + return rv -- 2.39.5