Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ed20f1c

Browse files
committed
some more speed up (one time compilation of popular regexes)
1 parent 3ead88c commit ed20f1c

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

lib/request/basic.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@
3636
from lib.parse.headers import headersParser
3737
from lib.parse.html import htmlParser
3838

39+
__absFilePathsRegExp = ( r" in <b>(?P<result>.*?)</b> on line", r"(?:>|\s)(?P<result>[A-Za-z]:[\\/][\w.\\/]*)", r"(?:>|\s)(?P<result>/\w[/\w.]+)" )
40+
__absFilePathsRegObj = [re.compile(absFilePathRegExp) for absFilePathRegExp in __absFilePathsRegExp]
41+
3942
def forgeHeaders(cookie, ua):
4043
"""
4144
Prepare HTTP Cookie and HTTP User-Agent headers to use when performing
@@ -74,10 +77,9 @@ def parseResponse(page, headers):
7477
# Detect injectable page absolute system path
7578
# NOTE: this regular expression works if the remote web application
7679
# is written in PHP and debug/error messages are enabled.
77-
absFilePathsRegExp = ( r" in <b>(?P<result>.*?)</b> on line", r"(?:>|\s)(?P<result>[A-Za-z]:[\\/][\w.\\/]*)", r"(?:>|\s)(?P<result>/\w[/\w.]+)" )
7880

79-
for absFilePathRegExp in absFilePathsRegExp:
80-
for match in re.finditer(absFilePathRegExp, page):
81+
for reobj in __absFilePathsRegObj:
82+
for match in reobj.finditer(page):
8183
absFilePath = match.group("result").strip()
8284
page = page.replace(absFilePath, "")
8385

0 commit comments

Comments
 (0)