|
18 | 18 | from lib.core.session import setMatchRatio |
19 | 19 |
|
20 | 20 | def comparison(page, headers=None, getSeqMatcher=False, pageLength=None): |
| 21 | + if page is None and pageLength is None: |
| 22 | + return None |
| 23 | + |
21 | 24 | regExpResults = None |
22 | 25 |
|
23 | | - # String to be excluded before calculating page hash |
24 | | - if conf.eString and conf.eString in page: |
25 | | - index = page.index(conf.eString) |
26 | | - length = len(conf.eString) |
27 | | - pageWithoutString = page[:index] |
28 | | - pageWithoutString += page[index+length:] |
29 | | - page = pageWithoutString |
30 | | - |
31 | | - # Regular expression matches to be excluded before calculating page hash |
32 | | - if conf.eRegexp: |
33 | | - regExpResults = re.findall(conf.eRegexp, page, re.I | re.M) |
34 | | - |
35 | | - if regExpResults: |
36 | | - for regExpResult in regExpResults: |
37 | | - index = page.index(regExpResult) |
38 | | - length = len(regExpResult) |
39 | | - pageWithoutRegExp = page[:index] |
40 | | - pageWithoutRegExp += page[index+length:] |
41 | | - page = pageWithoutRegExp |
42 | | - |
43 | | - # String to match in page when the query is valid |
44 | | - if conf.string: |
45 | | - return conf.string in page |
46 | | - |
47 | | - # Regular expression to match in page when the query is valid |
48 | | - if conf.regexp: |
49 | | - return re.search(conf.regexp, page, re.I | re.M) is not None |
50 | | - |
51 | | - # Dynamic content lines to be excluded before calculating page hash |
52 | | - for item in kb.dynamicMarkings: |
53 | | - prefix, postfix = item |
54 | | - if prefix is None: |
55 | | - page = re.sub('(?s)^.+%s' % postfix, postfix, page) |
56 | | - elif postfix is None: |
57 | | - page = re.sub('(?s)%s.+$' % prefix, prefix, page) |
58 | | - else: |
59 | | - page = re.sub('(?s)%s.+%s' % (prefix, postfix), '%s%s' % (prefix, postfix), page) |
60 | | - |
61 | | - if not pageLength and page: |
62 | | - pageLength = len(page) |
| 26 | + if page: |
| 27 | + # String to be excluded before calculating page hash |
| 28 | + if conf.eString and conf.eString in page: |
| 29 | + index = page.index(conf.eString) |
| 30 | + length = len(conf.eString) |
| 31 | + pageWithoutString = page[:index] |
| 32 | + pageWithoutString += page[index+length:] |
| 33 | + page = pageWithoutString |
| 34 | + |
| 35 | + # Regular expression matches to be excluded before calculating page hash |
| 36 | + if conf.eRegexp: |
| 37 | + regExpResults = re.findall(conf.eRegexp, page, re.I | re.M) |
| 38 | + |
| 39 | + if regExpResults: |
| 40 | + for regExpResult in regExpResults: |
| 41 | + index = page.index(regExpResult) |
| 42 | + length = len(regExpResult) |
| 43 | + pageWithoutRegExp = page[:index] |
| 44 | + pageWithoutRegExp += page[index+length:] |
| 45 | + page = pageWithoutRegExp |
| 46 | + |
| 47 | + # String to match in page when the query is valid |
| 48 | + if conf.string: |
| 49 | + return conf.string in page |
| 50 | + |
| 51 | + # Regular expression to match in page when the query is valid |
| 52 | + if conf.regexp: |
| 53 | + return re.search(conf.regexp, page, re.I | re.M) is not None |
| 54 | + |
| 55 | + # Dynamic content lines to be excluded before calculating page hash |
| 56 | + if not kb.nullConnection: |
| 57 | + for item in kb.dynamicMarkings: |
| 58 | + prefix, postfix = item |
| 59 | + if prefix is None: |
| 60 | + page = re.sub('(?s)^.+%s' % postfix, postfix, page) |
| 61 | + elif postfix is None: |
| 62 | + page = re.sub('(?s)%s.+$' % prefix, prefix, page) |
| 63 | + else: |
| 64 | + page = re.sub('(?s)%s.+%s' % (prefix, postfix), '%s%s' % (prefix, postfix), page) |
| 65 | + |
| 66 | + if not pageLength: |
| 67 | + pageLength = len(page) |
63 | 68 |
|
64 | 69 | if kb.locks.seqLock: |
65 | 70 | kb.locks.seqLock.acquire() |
|
0 commit comments