@@ -1107,33 +1107,42 @@ def sanitizeAsciiString(subject):
11071107
11081108def preparePageForLineComparison (page ):
11091109 retVal = page
1110+
11101111 if isinstance (page , basestring ):
11111112 return page .replace ("><" , ">\n <" ).replace ("<br>" , "\n " ).splitlines ()
1113+
11121114 return retVal
11131115
11141116def getFilteredPageContent (page ):
11151117 retVal = page
1118+
11161119 if isinstance (page , basestring ):
11171120 retVal = re .sub (r"(?s)<script.+?</script>|<style.+?</style>|<[^>]+>|\t|\n|\r" , " " , page )
1121+
11181122 while retVal .find (" " ) != - 1 :
11191123 retVal = retVal .replace (" " , " " )
1124+
11201125 return retVal
11211126
11221127def getPageTextWordsSet (page ):
11231128 retVal = None
1129+
11241130 if isinstance (page , basestring ):
11251131 page = getFilteredPageContent (page )
11261132 retVal = set (re .findall (r"\w+" , page ))
1133+
11271134 return retVal
11281135
11291136def showStaticWords (firstPage , secondPage ):
11301137 infoMsg = "finding static words in longest matching part of dynamic page content"
11311138 logger .info (infoMsg )
1139+
11321140 firstPage = getFilteredPageContent (firstPage )
11331141 secondPage = getFilteredPageContent (secondPage )
11341142 match = SequenceMatcher (None , firstPage , secondPage ).find_longest_match (0 , len (firstPage ), 0 , len (secondPage ))
11351143 commonText = firstPage [match [0 ]:match [0 ]+ match [2 ]]
11361144 commonWords = getPageTextWordsSet (commonText )
1145+
11371146 infoMsg = "static words: "
11381147
11391148 if commonWords :
@@ -1190,6 +1199,7 @@ def posixToNtSlashes(filepath):
11901199 >>> posixToNtSlashes('C:/Windows')
11911200 'C:\\ \\ Windows'
11921201 """
1202+
11931203 return filepath .replace ('/' , '\\ ' )
11941204
11951205def ntToPosixSlashes (filepath ):
@@ -1199,6 +1209,7 @@ def ntToPosixSlashes(filepath):
11991209 >>> ntToPosixSlashes('C:\\ Windows')
12001210 'C:/Windows'
12011211 """
1212+
12021213 return filepath .replace ('\\ ' , '/' )
12031214
12041215def isBase64EncodedString (subject ):
@@ -1209,6 +1220,7 @@ def isBase64EncodedString(subject):
12091220 >>> isBase64EncodedString('123456')
12101221 False
12111222 """
1223+
12121224 return re .match (r"\A(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?\Z" , subject ) is not None
12131225
12141226def isHexEncodedString (subject ):
@@ -1219,6 +1231,7 @@ def isHexEncodedString(subject):
12191231 >>> isHexEncodedString('test')
12201232 False
12211233 """
1234+
12221235 return re .match (r"\A[0-9a-fA-F]+\Z" , subject ) is not None
12231236
12241237def getConsoleWidth (default = 80 ):
@@ -1229,12 +1242,14 @@ def getConsoleWidth(default=80):
12291242 else :
12301243 output = subprocess .Popen ('stty size' , shell = True , stdout = subprocess .PIPE , stderr = subprocess .PIPE ).stdout .read ()
12311244 items = output .split ()
1245+
12321246 if len (items ) == 2 and items [1 ].isdigit ():
12331247 width = int (items [1 ])
12341248
12351249 if width is None :
12361250 try :
12371251 import curses
1252+
12381253 stdscr = curses .initscr ()
12391254 _ , width = stdscr .getmaxyx ()
12401255 curses .endwin ()
@@ -1268,10 +1283,13 @@ def calculateDeltaSeconds(start, epsilon=0.05):
12681283
12691284def getInjectionCase (name ):
12701285 retVal = None
1286+
12711287 for case in kb .injections .root .case :
12721288 if case .name == name :
12731289 retVal = case
1290+
12741291 break
1292+
12751293 return retVal
12761294
12771295def initCommonOutputs ():
@@ -1302,9 +1320,9 @@ def getFileItems(filename):
13021320 retVal = []
13031321
13041322 checkFile (filename )
1305- file = codecs .open (filename , 'r' , conf .dataEncoding )
1323+ ifile = codecs .open (filename , 'r' , conf .dataEncoding )
13061324
1307- for line in file .readlines (): # xreadlines doesn't return unicode strings when codec.open() is used
1325+ for line in ifile .readlines (): # xreadlines doesn't return unicode strings when codec.open() is used
13081326 if line .find ('#' ) != - 1 :
13091327 line = line [:line .find ('#' )]
13101328 line = line .strip ()
0 commit comments