From e4933f0c9265f0e99d7d9f025bca2a58f6096e95 Mon Sep 17 00:00:00 2001 From: Miroslav Stampar Date: Thu, 3 Feb 2011 23:25:56 +0000 Subject: [PATCH] refactoring --- lib/core/settings.py | 6 ++++++ lib/request/comparison.py | 12 ++++++++---- lib/request/connect.py | 8 ++++---- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/lib/core/settings.py b/lib/core/settings.py index f5c6fc526..809091a11 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -235,3 +235,9 @@ MAX_NUMBER_OF_THREADS = 10 # Minimum range between minimum and maximum of statistical set MIN_STATISTICAL_RANGE = 0.01 + +# Minimum value for comparison ratio +MIN_RATIO = 0.0 + +# Maximum value for comparison ratio +MAX_RATIO = 1.0 diff --git a/lib/request/comparison.py b/lib/request/comparison.py index 53508f299..9ffca2f11 100644 --- a/lib/request/comparison.py +++ b/lib/request/comparison.py @@ -20,11 +20,13 @@ from lib.core.data import kb from lib.core.data import logger from lib.core.settings import CONSTANT_RATIO from lib.core.settings import DIFF_TOLERANCE +from lib.core.settings import MIN_RATIO +from lib.core.settings import MAX_RATIO from lib.core.settings import LOWER_RATIO_BOUND from lib.core.settings import UPPER_RATIO_BOUND from lib.core.threads import getCurrentThreadData -def comparison(page, getSeqMatcher=False, pageLength=None): +def comparison(page, getRatioValue=False, pageLength=None): if page is None and pageLength is None: return None @@ -36,11 +38,13 @@ def comparison(page, getSeqMatcher=False, pageLength=None): if page: # String to match in page when the query is valid if conf.string: - return conf.string in page + condition = conf.string in page + return condition if not getRatioValue else (MAX_RATIO if condition else MIN_RATIO) # Regular expression to match in page when the query is valid if conf.regexp: - return re.search(conf.regexp, page, re.I | re.M) is not None + condition = re.search(conf.regexp, page, re.I | re.M) is not None + return condition if not getRatioValue else (MAX_RATIO if condition else MIN_RATIO) # In case of an DBMS error page return None if kb.errorIsNone and (wasLastRequestDBMSError() or wasLastRequestHTTPError()): @@ -76,7 +80,7 @@ def comparison(page, getSeqMatcher=False, pageLength=None): # If it has been requested to return the ratio and not a comparison # response - if getSeqMatcher: + if getRatioValue: return ratio elif ratio > UPPER_RATIO_BOUND: diff --git a/lib/request/connect.py b/lib/request/connect.py index 237d7e766..1a8a7301a 100644 --- a/lib/request/connect.py +++ b/lib/request/connect.py @@ -369,7 +369,7 @@ class Connect: return page, responseHeaders @staticmethod - def queryPage(value=None, place=None, content=False, getSeqMatcher=False, silent=False, method=None, timeBasedCompare=False, noteResponseTime=True, auxHeaders=None, response=False, raise404=None): + def queryPage(value=None, place=None, content=False, getRatioValue=False, silent=False, method=None, timeBasedCompare=False, noteResponseTime=True, auxHeaders=None, response=False, raise404=None): """ This method calls a function to get the target url page content and returns its page MD5 hash or a boolean value in case of @@ -481,9 +481,9 @@ class Connect: if content or response: return page, headers - elif getSeqMatcher: - return comparison(page, getSeqMatcher=False, pageLength=pageLength), comparison(page, getSeqMatcher=True, pageLength=pageLength) + elif getRatioValue: + return comparison(page, getRatioValue=False, pageLength=pageLength), comparison(page, getRatioValue=True, pageLength=pageLength) elif pageLength or page: - return comparison(page, getSeqMatcher, pageLength) + return comparison(page, getRatioValue, pageLength) else: return False