Trivial code style updates

This commit is contained in:
Miroslav Stampar 2019-04-19 13:54:48 +02:00
parent 10fe87fb4e
commit e7469ab570
14 changed files with 73 additions and 54 deletions

View File

@ -1,6 +1,6 @@
#!/bin/bash #!/bin/bash
# Copyright (c) 2006-2013 sqlmap developers (http://sqlmap.org/) # Copyright (c) 2006-2019 sqlmap developers (http://sqlmap.org/)
# See the file 'LICENSE' for copying permission # See the file 'LICENSE' for copying permission
# Removes trailing spaces from blank lines inside project files # Removes trailing spaces from blank lines inside project files

View File

@ -1,6 +1,6 @@
#!/bin/bash #!/bin/bash
# Copyright (c) 2006-2013 sqlmap developers (http://sqlmap.org/) # Copyright (c) 2006-2019 sqlmap developers (http://sqlmap.org/)
# See the file 'LICENSE' for copying permission # See the file 'LICENSE' for copying permission
# Stress test against Python3 # Stress test against Python3

View File

@ -1,6 +1,6 @@
#!/bin/bash #!/bin/bash
# Copyright (c) 2006-2013 sqlmap developers (http://sqlmap.org/) # Copyright (c) 2006-2019 sqlmap developers (http://sqlmap.org/)
# See the file 'LICENSE' for copying permission # See the file 'LICENSE' for copying permission
# Runs py2diatra on all python files (prerequisite: pip install pydiatra) # Runs py2diatra on all python files (prerequisite: pip install pydiatra)

View File

@ -1,6 +1,6 @@
#!/bin/bash #!/bin/bash
# Copyright (c) 2006-2013 sqlmap developers (http://sqlmap.org/) # Copyright (c) 2006-2019 sqlmap developers (http://sqlmap.org/)
# See the file 'LICENSE' for copying permission # See the file 'LICENSE' for copying permission
# Runs pyflakes on all python files (prerequisite: apt-get install pyflakes) # Runs pyflakes on all python files (prerequisite: apt-get install pyflakes)

View File

@ -117,7 +117,7 @@ class ReqHandler(BaseHTTPRequestHandler):
output += "<td>%s</td>" % value output += "<td>%s</td>" % value
output += "</tr>\n" output += "</tr>\n"
output += "</table>\n" output += "</table>\n"
output += "</body></html>"; output += "</body></html>"
except Exception as ex: except Exception as ex:
output = "%s: %s" % (re.search(r"'([^']+)'", str(type(ex))).group(1), ex) output = "%s: %s" % (re.search(r"'([^']+)'", str(type(ex))).group(1), ex)

View File

@ -37,7 +37,7 @@ class WichmannHill(random.Random):
a = int(binascii.hexlify(os.urandom(16)), 16) a = int(binascii.hexlify(os.urandom(16)), 16)
except NotImplementedError: except NotImplementedError:
import time import time
a = int(time.time() * 256) # use fractional seconds a = int(time.time() * 256) # use fractional seconds
if not isinstance(a, int): if not isinstance(a, int):
a = hash(a) a = hash(a)
@ -45,7 +45,7 @@ class WichmannHill(random.Random):
a, x = divmod(a, 30268) a, x = divmod(a, 30268)
a, y = divmod(a, 30306) a, y = divmod(a, 30306)
a, z = divmod(a, 30322) a, z = divmod(a, 30322)
self._seed = int(x)+1, int(y)+1, int(z)+1 self._seed = int(x) + 1, int(y) + 1, int(z) + 1
self.gauss_next = None self.gauss_next = None
@ -78,7 +78,7 @@ class WichmannHill(random.Random):
# Note: on a platform using IEEE-754 double arithmetic, this can # Note: on a platform using IEEE-754 double arithmetic, this can
# never return 0.0 (asserted by Tim; proof too long for a comment). # never return 0.0 (asserted by Tim; proof too long for a comment).
return (x/30269.0 + y/30307.0 + z/30323.0) % 1.0 return (x / 30269.0 + y / 30307.0 + z / 30323.0) % 1.0
def getstate(self): def getstate(self):
"""Return internal state; can be passed to setstate() later.""" """Return internal state; can be passed to setstate() later."""
@ -130,7 +130,7 @@ class WichmannHill(random.Random):
# Initialize from current time # Initialize from current time
import time import time
t = int(time.time() * 256) t = int(time.time() * 256)
t = int((t&0xffffff) ^ (t>>24)) t = int((t & 0xffffff) ^ (t >> 24))
t, x = divmod(t, 256) t, x = divmod(t, 256)
t, y = divmod(t, 256) t, y = divmod(t, 256)
t, z = divmod(t, 256) t, z = divmod(t, 256)

View File

@ -17,7 +17,7 @@ from lib.core.enums import DBMS_DIRECTORY_NAME
from lib.core.enums import OS from lib.core.enums import OS
# sqlmap version (<major>.<minor>.<month>.<monthly commit>) # sqlmap version (<major>.<minor>.<month>.<monthly commit>)
VERSION = "1.3.4.30" VERSION = "1.3.4.31"
TYPE = "dev" if VERSION.count('.') > 2 and VERSION.split('.')[-1] != '0' else "stable" TYPE = "dev" if VERSION.count('.') > 2 and VERSION.split('.')[-1] != '0' else "stable"
TYPE_COLORS = {"dev": 33, "stable": 90, "pip": 34} TYPE_COLORS = {"dev": 33, "stable": 90, "pip": 34}
VERSION_STRING = "sqlmap/%s#%s" % ('.'.join(VERSION.split('.')[:-1]) if VERSION.count('.') > 2 and VERSION.split('.')[-1] == '0' else VERSION, TYPE) VERSION_STRING = "sqlmap/%s#%s" % ('.'.join(VERSION.split('.')[:-1]) if VERSION.count('.') > 2 and VERSION.split('.')[-1] == '0' else VERSION, TYPE)

View File

@ -600,7 +600,7 @@ def cmdLineParser(argv=None):
help="Parse and display DBMS error messages from responses") help="Parse and display DBMS error messages from responses")
general.add_option("--preprocess", dest="preprocess", general.add_option("--preprocess", dest="preprocess",
help="Use given script(s) for preprocessing of response data") help="Use given script(s) for preprocessing of response data")
general.add_option("--repair", dest="repair", action="store_true", general.add_option("--repair", dest="repair", action="store_true",
help="Redump entries having unknown character marker (%s)" % INFERENCE_UNKNOWN_CHAR) help="Redump entries having unknown character marker (%s)" % INFERENCE_UNKNOWN_CHAR)

View File

@ -21,9 +21,9 @@ __all__ = ["SGMLParser", "SGMLParseError"]
interesting = re.compile('[&<]') interesting = re.compile('[&<]')
incomplete = re.compile('&([a-zA-Z][a-zA-Z0-9]*|#[0-9]*)?|' incomplete = re.compile('&([a-zA-Z][a-zA-Z0-9]*|#[0-9]*)?|'
'<([a-zA-Z][^<>]*|' '<([a-zA-Z][^<>]*|'
'/([a-zA-Z][^<>]*)?|' '/([a-zA-Z][^<>]*)?|'
'![^<>]*)?') '![^<>]*)?')
entityref = re.compile('&([a-zA-Z][-.a-zA-Z0-9]*)[^a-zA-Z0-9]') entityref = re.compile('&([a-zA-Z][-.a-zA-Z0-9]*)[^a-zA-Z0-9]')
charref = re.compile('&#([0-9]+)[^0-9]') charref = re.compile('&#([0-9]+)[^0-9]')
@ -58,8 +58,8 @@ class SGMLParseError(RuntimeError):
class SGMLParser(_markupbase.ParserBase): class SGMLParser(_markupbase.ParserBase):
# Definition of entities -- derived classes may override # Definition of entities -- derived classes may override
entity_or_charref = re.compile('&(?:' entity_or_charref = re.compile('&(?:'
'([a-zA-Z][-.a-zA-Z0-9]*)|#([0-9]+)' '([a-zA-Z][-.a-zA-Z0-9]*)|#([0-9]+)'
')(;?)') ')(;?)')
def __init__(self, verbose=0): def __init__(self, verbose=0):
"""Initialize and reset this instance.""" """Initialize and reset this instance."""
@ -121,32 +121,37 @@ class SGMLParser(_markupbase.ParserBase):
i = n i = n
break break
match = interesting.search(rawdata, i) match = interesting.search(rawdata, i)
if match: j = match.start() if match:
else: j = n j = match.start()
else:
j = n
if i < j: if i < j:
self.handle_data(rawdata[i:j]) self.handle_data(rawdata[i:j])
i = j i = j
if i == n: break if i == n:
break
if rawdata[i] == '<': if rawdata[i] == '<':
if starttagopen.match(rawdata, i): if starttagopen.match(rawdata, i):
if self.literal: if self.literal:
self.handle_data(rawdata[i]) self.handle_data(rawdata[i])
i = i+1 i = i + 1
continue continue
k = self.parse_starttag(i) k = self.parse_starttag(i)
if k < 0: break if k < 0:
break
i = k i = k
continue continue
if rawdata.startswith("</", i): if rawdata.startswith("</", i):
k = self.parse_endtag(i) k = self.parse_endtag(i)
if k < 0: break if k < 0:
break
i = k i = k
self.literal = 0 self.literal = 0
continue continue
if self.literal: if self.literal:
if n > (i + 1): if n > (i + 1):
self.handle_data("<") self.handle_data("<")
i = i+1 i = i + 1
else: else:
# incomplete # incomplete
break break
@ -157,12 +162,14 @@ class SGMLParser(_markupbase.ParserBase):
# This should be removed, # This should be removed,
# and comments handled only in parse_declaration. # and comments handled only in parse_declaration.
k = self.parse_comment(i) k = self.parse_comment(i)
if k < 0: break if k < 0:
break
i = k i = k
continue continue
if rawdata.startswith("<?", i): if rawdata.startswith("<?", i):
k = self.parse_pi(i) k = self.parse_pi(i)
if k < 0: break if k < 0:
break
i = i+k i = i+k
continue continue
if rawdata.startswith("<!", i): if rawdata.startswith("<!", i):
@ -170,27 +177,30 @@ class SGMLParser(_markupbase.ParserBase):
# deployed," this should only be the document type # deployed," this should only be the document type
# declaration ("<!DOCTYPE html...>"). # declaration ("<!DOCTYPE html...>").
k = self.parse_declaration(i) k = self.parse_declaration(i)
if k < 0: break if k < 0:
break
i = k i = k
continue continue
elif rawdata[i] == '&': elif rawdata[i] == '&':
if self.literal: if self.literal:
self.handle_data(rawdata[i]) self.handle_data(rawdata[i])
i = i+1 i = i + 1
continue continue
match = charref.match(rawdata, i) match = charref.match(rawdata, i)
if match: if match:
name = match.group(1) name = match.group(1)
self.handle_charref(name) self.handle_charref(name)
i = match.end(0) i = match.end(0)
if rawdata[i-1] != ';': i = i-1 if rawdata[i-1] != ';':
i = i-1
continue continue
match = entityref.match(rawdata, i) match = entityref.match(rawdata, i)
if match: if match:
name = match.group(1) name = match.group(1)
self.handle_entityref(name) self.handle_entityref(name)
i = match.end(0) i = match.end(0)
if rawdata[i-1] != ';': i = i-1 if rawdata[i-1] != ';':
i = i-1
continue continue
else: else:
self.error('neither < nor & ??') self.error('neither < nor & ??')
@ -199,11 +209,11 @@ class SGMLParser(_markupbase.ParserBase):
match = incomplete.match(rawdata, i) match = incomplete.match(rawdata, i)
if not match: if not match:
self.handle_data(rawdata[i]) self.handle_data(rawdata[i])
i = i+1 i = i + 1
continue continue
j = match.end(0) j = match.end(0)
if j == n: if j == n:
break # Really incomplete break # Really incomplete
self.handle_data(rawdata[i:j]) self.handle_data(rawdata[i:j])
i = j i = j
# end while # end while
@ -256,32 +266,33 @@ class SGMLParser(_markupbase.ParserBase):
# As a shortcut way to exit, this isn't so bad, but shouldn't # As a shortcut way to exit, this isn't so bad, but shouldn't
# be used to locate the actual end of the start tag since the # be used to locate the actual end of the start tag since the
# < or > characters may be embedded in an attribute value. # < or > characters may be embedded in an attribute value.
match = endbracket.search(rawdata, i+1) match = endbracket.search(rawdata, i + 1)
if not match: if not match:
return -1 return -1
j = match.start(0) j = match.start(0)
# Now parse the data between i+1 and j into a tag and attrs # Now parse the data between i + 1 and j into a tag and attrs
attrs = [] attrs = []
if rawdata[i:i+2] == '<>': if rawdata[i:i+2] == '<>':
# SGML shorthand: <> == <last open tag seen> # SGML shorthand: <> == <last open tag seen>
k = j k = j
tag = self.lasttag tag = self.lasttag
else: else:
match = tagfind.match(rawdata, i+1) match = tagfind.match(rawdata, i + 1)
if not match: if not match:
self.error('unexpected call to parse_starttag') self.error('unexpected call to parse_starttag')
k = match.end(0) k = match.end(0)
tag = rawdata[i+1:k].lower() tag = rawdata[i + 1:k].lower()
self.lasttag = tag self.lasttag = tag
while k < j: while k < j:
match = attrfind.match(rawdata, k) match = attrfind.match(rawdata, k)
if not match: break if not match:
break
attrname, rest, attrvalue = match.group(1, 2, 3) attrname, rest, attrvalue = match.group(1, 2, 3)
if not rest: if not rest:
attrvalue = attrname attrvalue = attrname
else: else:
if (attrvalue[:1] == "'" == attrvalue[-1:] or if (attrvalue[:1] == "'" == attrvalue[-1:] or
attrvalue[:1] == '"' == attrvalue[-1:]): attrvalue[:1] == '"' == attrvalue[-1:]):
# strip quotes # strip quotes
attrvalue = attrvalue[1:-1] attrvalue = attrvalue[1:-1]
attrvalue = self.entity_or_charref.sub( attrvalue = self.entity_or_charref.sub(
@ -289,7 +300,7 @@ class SGMLParser(_markupbase.ParserBase):
attrs.append((attrname.lower(), attrvalue)) attrs.append((attrname.lower(), attrvalue))
k = match.end(0) k = match.end(0)
if rawdata[j] == '>': if rawdata[j] == '>':
j = j+1 j = j + 1
self.__starttag_text = rawdata[start_pos:j] self.__starttag_text = rawdata[start_pos:j]
self.finish_starttag(tag, attrs) self.finish_starttag(tag, attrs)
return j return j
@ -308,13 +319,13 @@ class SGMLParser(_markupbase.ParserBase):
# Internal -- parse endtag # Internal -- parse endtag
def parse_endtag(self, i): def parse_endtag(self, i):
rawdata = self.rawdata rawdata = self.rawdata
match = endbracket.search(rawdata, i+1) match = endbracket.search(rawdata, i + 1)
if not match: if not match:
return -1 return -1
j = match.start(0) j = match.start(0)
tag = rawdata[i+2:j].strip().lower() tag = rawdata[i+2:j].strip().lower()
if rawdata[j] == '>': if rawdata[j] == '>':
j = j+1 j = j + 1
self.finish_endtag(tag) self.finish_endtag(tag)
return j return j
@ -361,7 +372,8 @@ class SGMLParser(_markupbase.ParserBase):
return return
found = len(self.stack) found = len(self.stack)
for i in range(found): for i in range(found):
if self.stack[i] == tag: found = i if self.stack[i] == tag:
found = i
while len(self.stack) > found: while len(self.stack) > found:
tag = self.stack[-1] tag = self.stack[-1]
try: try:
@ -411,7 +423,7 @@ class SGMLParser(_markupbase.ParserBase):
# Definition of entities -- derived classes may override # Definition of entities -- derived classes may override
entitydefs = \ entitydefs = \
{'lt': '<', 'gt': '>', 'amp': '&', 'quot': '"', 'apos': '\''} {'lt': '<', 'gt': '>', 'amp': '&', 'quot': '"', 'apos': '\''}
def convert_entityref(self, name): def convert_entityref(self, name):
"""Convert entity references. """Convert entity references.
@ -450,10 +462,17 @@ class SGMLParser(_markupbase.ParserBase):
pass pass
# To be overridden -- handlers for unknown objects # To be overridden -- handlers for unknown objects
def unknown_starttag(self, tag, attrs): pass def unknown_starttag(self, tag, attrs):
def unknown_endtag(self, tag): pass pass
def unknown_charref(self, ref): pass
def unknown_entityref(self, ref): pass def unknown_endtag(self, tag):
pass
def unknown_charref(self, ref):
pass
def unknown_entityref(self, ref):
pass
class TestSGMLParser(SGMLParser): class TestSGMLParser(SGMLParser):
@ -511,7 +530,7 @@ class TestSGMLParser(SGMLParser):
self.flush() self.flush()
def test(args = None): def test(args=None):
import sys import sys
if args is None: if args is None: