Modify flawfinder to work in Python 2 *and* Python 3 - this passes tests
Signed-off-by: David A. Wheeler <dwheeler@dwheeler.com>
This commit is contained in:
parent
90777b6980
commit
48a6b3982b
20
flawfinder
20
flawfinder
|
@ -313,11 +313,7 @@ def load_patch_info(input_patch_file):
|
||||||
|
|
||||||
def htmlize(s):
|
def htmlize(s):
|
||||||
# Take s, and return legal (UTF-8) HTML.
|
# Take s, and return legal (UTF-8) HTML.
|
||||||
s1 = string.replace(s, "&", "&")
|
return s.replace("&", "&").replace("<", "<").replace(">", ">")
|
||||||
s2 = string.replace(s1, "<", "<")
|
|
||||||
s3 = string.replace(s2, ">", ">")
|
|
||||||
return s3
|
|
||||||
|
|
||||||
|
|
||||||
def h(s):
|
def h(s):
|
||||||
# htmlize s if we're generating html, otherwise just return s.
|
# htmlize s if we're generating html, otherwise just return s.
|
||||||
|
@ -410,7 +406,7 @@ class Hit(object):
|
||||||
def fingerprint(self):
|
def fingerprint(self):
|
||||||
"""Return fingerprint of stripped context."""
|
"""Return fingerprint of stripped context."""
|
||||||
m = hashlib.sha256()
|
m = hashlib.sha256()
|
||||||
m.update(self.context_text.strip())
|
m.update(self.context_text.strip().encode('utf-8'))
|
||||||
return m.hexdigest()
|
return m.hexdigest()
|
||||||
|
|
||||||
# Show as CSV format
|
# Show as CSV format
|
||||||
|
@ -556,16 +552,14 @@ def extract_c_parameters(text, pos=0):
|
||||||
parenlevel = parenlevel + 1
|
parenlevel = parenlevel + 1
|
||||||
elif c == ',' and (parenlevel == 1):
|
elif c == ',' and (parenlevel == 1):
|
||||||
parameters.append(
|
parameters.append(
|
||||||
string.strip(
|
p_trailingbackslashes.sub('', text[currentstart:i]).strip())
|
||||||
p_trailingbackslashes.sub('', text[currentstart:i])))
|
|
||||||
currentstart = i + 1
|
currentstart = i + 1
|
||||||
elif c == ')':
|
elif c == ')':
|
||||||
parenlevel = parenlevel - 1
|
parenlevel = parenlevel - 1
|
||||||
if parenlevel <= 0:
|
if parenlevel <= 0:
|
||||||
parameters.append(
|
parameters.append(
|
||||||
string.strip(
|
p_trailingbackslashes.sub(
|
||||||
p_trailingbackslashes.sub('', text[currentstart:
|
'', text[currentstart:i]).strip())
|
||||||
i])))
|
|
||||||
# Re-enable these for debugging:
|
# Re-enable these for debugging:
|
||||||
# print " EXTRACT_C_PARAMETERS: ", text[pos:pos+80]
|
# print " EXTRACT_C_PARAMETERS: ", text[pos:pos+80]
|
||||||
# print " RESULTS: ", parameters
|
# print " RESULTS: ", parameters
|
||||||
|
@ -598,10 +592,10 @@ def strip_i18n(text):
|
||||||
"""
|
"""
|
||||||
match = gettext_pattern.search(text)
|
match = gettext_pattern.search(text)
|
||||||
if match:
|
if match:
|
||||||
return string.strip(match.group(1))
|
return match.group(1).strip()
|
||||||
match = undersc_pattern.search(text)
|
match = undersc_pattern.search(text)
|
||||||
if match:
|
if match:
|
||||||
return string.strip(match.group(3))
|
return match.group(3).strip()
|
||||||
return text
|
return text
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue