code refactoring

This commit is contained in:
Miroslav Stampar 2010-12-04 10:13:18 +00:00
parent 04714374f9
commit 0fc7a8f9e8
3 changed files with 16 additions and 19 deletions

View File

@ -20,6 +20,7 @@ from lib.core.common import getUnicode
from lib.core.common import randomInt from lib.core.common import randomInt
from lib.core.common import randomStr from lib.core.common import randomStr
from lib.core.common import readInput from lib.core.common import readInput
from lib.core.common import removeDynamicContent
from lib.core.common import showStaticWords from lib.core.common import showStaticWords
from lib.core.common import trimAlphaNum from lib.core.common import trimAlphaNum
from lib.core.common import wasLastRequestDBMSError from lib.core.common import wasLastRequestDBMSError
@ -523,16 +524,7 @@ def checkDynamicContent(firstPage, secondPage):
infoMsg = "dynamic content marked for removal (%d region%s)" % (len(kb.dynamicMarkings), 's' if len(kb.dynamicMarkings) > 1 else '') infoMsg = "dynamic content marked for removal (%d region%s)" % (len(kb.dynamicMarkings), 's' if len(kb.dynamicMarkings) > 1 else '')
logger.info(infoMsg) logger.info(infoMsg)
if kb.pageTemplate: kb.pageTemplate = removeDynamicContent(kb.pageTemplate)
for item in kb.dynamicMarkings:
prefix, suffix = item
if prefix is None:
kb.pageTemplate = re.sub('(?s)^.+%s' % suffix, suffix, kb.pageTemplate)
elif suffix is None:
kb.pageTemplate = re.sub('(?s)%s.+$' % prefix, prefix, kb.pageTemplate)
else:
kb.pageTemplate = re.sub('(?s)%s.+%s' % (prefix, suffix), '%s%s' % (prefix, suffix), kb.pageTemplate)
def checkStability(): def checkStability():
""" """

View File

@ -1637,3 +1637,15 @@ def aliasToDbmsEnum(value):
break break
return retVal return retVal
def removeDynamicContent(page):
if page:
for item in kb.dynamicMarkings:
prefix, suffix = item
if prefix is None:
page = re.sub('(?s)^.+%s' % suffix, suffix, page)
elif suffix is None:
page = re.sub('(?s)%s.+$' % prefix, prefix, page)
else:
page = re.sub('(?s)%s.+%s' % (prefix, suffix), '%s%s' % (prefix, suffix), page)
return page

View File

@ -11,6 +11,7 @@ import re
from difflib import SequenceMatcher from difflib import SequenceMatcher
from lib.core.common import removeDynamicContent
from lib.core.common import wasLastRequestDBMSError from lib.core.common import wasLastRequestDBMSError
from lib.core.data import conf from lib.core.data import conf
from lib.core.data import kb from lib.core.data import kb
@ -60,15 +61,7 @@ def comparison(page, headers=None, getSeqMatcher=False, pageLength=None):
# Dynamic content lines to be excluded before comparison # Dynamic content lines to be excluded before comparison
if not kb.nullConnection and not conf.longestCommon: if not kb.nullConnection and not conf.longestCommon:
for item in kb.dynamicMarkings: page = removeDynamicContent(page)
prefix, suffix = item
if prefix is None:
page = re.sub('(?s)^.+%s' % suffix, suffix, page)
elif suffix is None:
page = re.sub('(?s)%s.+$' % prefix, prefix, page)
else:
page = re.sub('(?s)%s.+%s' % (prefix, suffix), '%s%s' % (prefix, suffix), page)
if not pageLength: if not pageLength:
pageLength = len(page) pageLength = len(page)