From: grahams Date: Sun, 8 Feb 2009 22:04:42 +0000 (+0800) Subject: Moved the "lj tag" regular expression objects to the global scope (so they X-Git-Url: http://wagner.pp.ru/gitweb/?a=commitdiff_plain;h=5d84d72f008804ca468858362331efca87103e19;p=oss%2Fljdump.git 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 --- 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