@@ -882,6 +882,16 @@ def singleTimeLogMessage(message, level=logging.INFO, flag=None):
882882 logger .log (level , message )
883883
884884def boldifyMessage (message ):
885+ """
886+ Sets ANSI bold marking on entire message if parts found in predefined BOLD_PATTERNS
887+
888+ >>> boldifyMessage("Hello World")
889+ 'Hello World'
890+
891+ >>> boldifyMessage("GET parameter id is not injectable")
892+ '\\ x1b[1mGET parameter id is not injectable\\ x1b[0m'
893+ """
894+
885895 retVal = message
886896
887897 if any (_ in message for _ in BOLD_PATTERNS ):
@@ -890,6 +900,13 @@ def boldifyMessage(message):
890900 return retVal
891901
892902def setColor (message , color = None , bold = False , level = None ):
903+ """
904+ Sets ANSI color codes
905+
906+ >>> setColor("Hello World", "red")
907+ '\\ x1b[31mHello World\\ x1b[0m'
908+ """
909+
893910 retVal = message
894911 level = level or extractRegexResult (r"\[(?P<result>%s)\]" % '|' .join (_ [0 ] for _ in getPublicTypeMembers (LOGGING_LEVELS )), message )
895912
@@ -933,7 +950,7 @@ def dataToStdout(data, forceOutput=False, bold=False, content_type=None, status=
933950 if multiThreadMode :
934951 logging ._acquireLock ()
935952
936- if isinstance (data , unicode ):
953+ if isinstance (data , six . text_type ):
937954 message = stdoutencode (data )
938955 else :
939956 message = data
@@ -1840,7 +1857,7 @@ def safeFilepathEncode(filepath):
18401857
18411858 retVal = filepath
18421859
1843- if filepath and isinstance (filepath , unicode ):
1860+ if filepath and isinstance (filepath , six . text_type ):
18441861 retVal = filepath .encode (sys .getfilesystemencoding () or UNICODE_ENCODING )
18451862
18461863 return retVal
@@ -1927,7 +1944,7 @@ def getFilteredPageContent(page, onlyText=True, split=" "):
19271944 retVal = page
19281945
19291946 # only if the page's charset has been successfully identified
1930- if isinstance (page , unicode ):
1947+ if isinstance (page , six . text_type ):
19311948 retVal = re .sub (r"(?si)<script.+?</script>|<!--.+?-->|<style.+?</style>%s" % (r"|<[^>]+>|\t|\n|\r" if onlyText else "" ), split , page )
19321949 retVal = re .sub (r"%s{2,}" % split , split , retVal )
19331950 retVal = htmlunescape (retVal .strip ().strip (split ))
@@ -1945,7 +1962,7 @@ def getPageWordSet(page):
19451962 retVal = set ()
19461963
19471964 # only if the page's charset has been successfully identified
1948- if isinstance (page , unicode ):
1965+ if isinstance (page , six . text_type ):
19491966 retVal = set (_ .group (0 ) for _ in re .finditer (r"\w+" , getFilteredPageContent (page )))
19501967
19511968 return retVal
@@ -2430,7 +2447,7 @@ def getUnicode(value, encoding=None, noneToNull=False):
24302447 except UnicodeDecodeError :
24312448 return six .text_type (str (value ), errors = "ignore" ) # encoding ignored for non-basestring instances
24322449
2433- def getBytes (value , encoding = UNICODE_ENCODING ):
2450+ def getBytes (value , encoding = UNICODE_ENCODING , errors = "strict" ):
24342451 """
24352452 Returns byte representation of provided Unicode value
24362453
@@ -2445,11 +2462,11 @@ def getBytes(value, encoding=UNICODE_ENCODING):
24452462 for char in xrange (0xF0000 , 0xF00FF + 1 ):
24462463 value = value .replace (unichr (char ), "%s%02x" % (SAFE_HEX_MARKER , char - 0xF0000 ))
24472464
2448- retVal = value .encode (encoding )
2465+ retVal = value .encode (encoding , errors )
24492466
24502467 retVal = re .sub (r"%s([0-9a-f]{2})" % SAFE_HEX_MARKER , lambda _ : _ .group (1 ).decode ("hex" ), retVal )
24512468 else :
2452- retVal = value .encode (encoding )
2469+ retVal = value .encode (encoding , errors )
24532470 retVal = re .sub (r"\\x([0-9a-f]{2})" , lambda _ : _ .group (1 ).decode ("hex" ), retVal )
24542471
24552472 return retVal
@@ -3694,7 +3711,7 @@ def removeReflectiveValues(content, payload, suppressWarning=False):
36943711 retVal = content
36953712
36963713 try :
3697- if all ((content , payload )) and isinstance (content , unicode ) and kb .reflectiveMechanism and not kb .heuristicMode :
3714+ if all ((content , payload )) and isinstance (content , six . text_type ) and kb .reflectiveMechanism and not kb .heuristicMode :
36983715 def _ (value ):
36993716 while 2 * REFLECTED_REPLACEMENT_REGEX in value :
37003717 value = value .replace (2 * REFLECTED_REPLACEMENT_REGEX , REFLECTED_REPLACEMENT_REGEX )
@@ -3786,7 +3803,7 @@ def normalizeUnicode(value):
37863803 'sucuraj'
37873804 """
37883805
3789- return unicodedata .normalize ("NFKD" , value ).encode ("ascii" , "ignore" ) if isinstance (value , unicode ) else value
3806+ return unicodedata .normalize ("NFKD" , value ).encode ("ascii" , "ignore" ) if isinstance (value , six . text_type ) else value
37903807
37913808def safeSQLIdentificatorNaming (name , isTable = False ):
37923809 """
@@ -4105,7 +4122,7 @@ def quote(s, safe):
41054122 # _urllib.parse.quote(s.replace('%', '')) != s.replace('%', '')
41064123 # which would trigger on all %-characters, e.g. "&".
41074124 if getUnicode (s ).encode ("ascii" , "replace" ) != s or forceQuote :
4108- return _urllib .parse .quote (s .encode (UNICODE_ENCODING ) if isinstance (s , unicode ) else s , safe = safe )
4125+ return _urllib .parse .quote (s .encode (UNICODE_ENCODING ) if isinstance (s , six . text_type ) else s , safe = safe )
41094126 return s
41104127
41114128 username = quote (parts .username , '' )
@@ -4459,8 +4476,8 @@ def _(value):
44594476 retVal = retVal .decode ("utf-16-be" )
44604477 except UnicodeDecodeError :
44614478 pass
4462- if not isinstance (retVal , unicode ):
4463- retVal = getUnicode (retVal , conf .encoding or "utf8" )
4479+ if not isinstance (retVal , six . text_type ):
4480+ retVal = getUnicode (retVal , conf .encoding or UNICODE_ENCODING )
44644481
44654482 return retVal
44664483
0 commit comments