|
26 | 26 |
|
27 | 27 | import re |
28 | 28 |
|
| 29 | +from lib.core.convert import md5hash |
29 | 30 | from lib.core.data import conf |
30 | | -from lib.core.settings import MATCH_RATIO |
| 31 | +from lib.core.data import logger |
| 32 | +#from lib.core.settings import MATCH_RATIO |
31 | 33 |
|
| 34 | +MATCH_RATIO = None |
32 | 35 |
|
33 | 36 | def comparison(page, headers=None, getSeqMatcher=False): |
| 37 | + global MATCH_RATIO |
| 38 | + |
34 | 39 | regExpResults = None |
35 | 40 |
|
36 | 41 | # String to be excluded before calculating page hash |
@@ -67,15 +72,34 @@ def comparison(page, headers=None, getSeqMatcher=False): |
67 | 72 | else: |
68 | 73 | return False |
69 | 74 |
|
70 | | - # By default it returns sequence matcher between the first untouched |
71 | | - # HTTP response page content and this content |
72 | 75 | conf.seqMatcher.set_seq2(page) |
73 | | - |
| 76 | + ratio = round(conf.seqMatcher.ratio(), 3) |
| 77 | + |
| 78 | + # If the url is stable and we did not set yet the match ratio and the |
| 79 | + # current injected value changes the url page content |
| 80 | + if MATCH_RATIO == None: |
| 81 | + if conf.md5hash != None and ratio != 1: |
| 82 | + logger.debug("Setting match ratio to %.3f" % ratio) |
| 83 | + MATCH_RATIO = ratio |
| 84 | + elif conf.md5hash == None: |
| 85 | + logger.debug("Setting match ratio to default value 0.900") |
| 86 | + MATCH_RATIO = 0.900 |
| 87 | + |
| 88 | + # If it has been requested to return the ratio and not a comparison |
| 89 | + # response |
74 | 90 | if getSeqMatcher: |
75 | | - return round(conf.seqMatcher.ratio(), 3) |
76 | | - |
77 | | - elif round(conf.seqMatcher.ratio(), 3) >= MATCH_RATIO: |
| 91 | + return ratio |
| 92 | + |
| 93 | + # If the url is stable it returns True if the page has the same MD5 |
| 94 | + # hash of the original one |
| 95 | + # NOTE: old implementation, it did not handle automatically the fact |
| 96 | + # that the url could be not stable (due to VIEWSTATE, counter, etc.) |
| 97 | + #elif conf.md5hash != None: |
| 98 | + # return conf.md5hash == md5hash(page) |
| 99 | + |
| 100 | + # If the url is not stable it returns sequence matcher between the |
| 101 | + # first untouched HTTP response page content and this content |
| 102 | + elif ratio > MATCH_RATIO: |
78 | 103 | return True |
79 | | - |
80 | 104 | else: |
81 | 105 | return False |
0 commit comments