From 0fc7a8f9e8b1e88060c3c039331c2fe6f0bfdbaf Mon Sep 17 00:00:00 2001 From: Miroslav Stampar Date: Sat, 4 Dec 2010 10:13:18 +0000 Subject: [PATCH] code refactoring --- lib/controller/checks.py | 12 ++---------- lib/core/common.py | 12 ++++++++++++ lib/request/comparison.py | 11 ++--------- 3 files changed, 16 insertions(+), 19 deletions(-) diff --git a/lib/controller/checks.py b/lib/controller/checks.py index e770b40c0..337dbf334 100644 --- a/lib/controller/checks.py +++ b/lib/controller/checks.py @@ -20,6 +20,7 @@ from lib.core.common import getUnicode from lib.core.common import randomInt from lib.core.common import randomStr from lib.core.common import readInput +from lib.core.common import removeDynamicContent from lib.core.common import showStaticWords from lib.core.common import trimAlphaNum 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 '') logger.info(infoMsg) - if 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) + kb.pageTemplate = removeDynamicContent(kb.pageTemplate) def checkStability(): """ diff --git a/lib/core/common.py b/lib/core/common.py index ed9ec9df5..402c1ec5b 100644 --- a/lib/core/common.py +++ b/lib/core/common.py @@ -1637,3 +1637,15 @@ def aliasToDbmsEnum(value): break 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 diff --git a/lib/request/comparison.py b/lib/request/comparison.py index 4a9d2e872..4192349e2 100644 --- a/lib/request/comparison.py +++ b/lib/request/comparison.py @@ -11,6 +11,7 @@ import re from difflib import SequenceMatcher +from lib.core.common import removeDynamicContent from lib.core.common import wasLastRequestDBMSError from lib.core.data import conf 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 if not kb.nullConnection and not conf.longestCommon: - 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) + page = removeDynamicContent(page) if not pageLength: pageLength = len(page)