From e7469ab57087031a634884807db06be01f635c92 Mon Sep 17 00:00:00 2001 From: Miroslav Stampar Date: Fri, 19 Apr 2019 13:54:48 +0200 Subject: [PATCH] Trivial code style updates --- extra/shutils/blanks.sh | 2 +- extra/shutils/drei.sh | 2 +- extra/shutils/pydiatra.sh | 2 +- extra/shutils/pyflakes.sh | 2 +- extra/vulnserver/vulnserver.py | 2 +- lib/core/compat.py | 8 +-- lib/core/settings.py | 2 +- lib/parse/cmdline.py | 4 +- lib/request/connect.py | 2 +- lib/utils/sgmllib.py | 93 +++++++++++++++++------------ plugins/dbms/db2/filesystem.py | 2 +- plugins/dbms/informix/filesystem.py | 2 +- plugins/dbms/mysql/enumeration.py | 2 +- waf/chinacache.py | 2 +- 14 files changed, 73 insertions(+), 54 deletions(-) diff --git a/extra/shutils/blanks.sh b/extra/shutils/blanks.sh index 4edfb86be..9813f9a10 100755 --- a/extra/shutils/blanks.sh +++ b/extra/shutils/blanks.sh @@ -1,6 +1,6 @@ #!/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 # Removes trailing spaces from blank lines inside project files diff --git a/extra/shutils/drei.sh b/extra/shutils/drei.sh index ae7934a34..e45a1fd1d 100755 --- a/extra/shutils/drei.sh +++ b/extra/shutils/drei.sh @@ -1,6 +1,6 @@ #!/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 # Stress test against Python3 diff --git a/extra/shutils/pydiatra.sh b/extra/shutils/pydiatra.sh index dbb0907ea..3b560004a 100755 --- a/extra/shutils/pydiatra.sh +++ b/extra/shutils/pydiatra.sh @@ -1,6 +1,6 @@ #!/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 # Runs py2diatra on all python files (prerequisite: pip install pydiatra) diff --git a/extra/shutils/pyflakes.sh b/extra/shutils/pyflakes.sh index 0938d5e08..e4ea94d74 100755 --- a/extra/shutils/pyflakes.sh +++ b/extra/shutils/pyflakes.sh @@ -1,6 +1,6 @@ #!/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 # Runs pyflakes on all python files (prerequisite: apt-get install pyflakes) diff --git a/extra/vulnserver/vulnserver.py b/extra/vulnserver/vulnserver.py index 99e45417f..bb730b665 100644 --- a/extra/vulnserver/vulnserver.py +++ b/extra/vulnserver/vulnserver.py @@ -117,7 +117,7 @@ class ReqHandler(BaseHTTPRequestHandler): output += "%s" % value output += "\n" output += "\n" - output += ""; + output += "" except Exception as ex: output = "%s: %s" % (re.search(r"'([^']+)'", str(type(ex))).group(1), ex) diff --git a/lib/core/compat.py b/lib/core/compat.py index f08bfedc2..0cb669f81 100644 --- a/lib/core/compat.py +++ b/lib/core/compat.py @@ -37,7 +37,7 @@ class WichmannHill(random.Random): a = int(binascii.hexlify(os.urandom(16)), 16) except NotImplementedError: import time - a = int(time.time() * 256) # use fractional seconds + a = int(time.time() * 256) # use fractional seconds if not isinstance(a, int): a = hash(a) @@ -45,7 +45,7 @@ class WichmannHill(random.Random): a, x = divmod(a, 30268) a, y = divmod(a, 30306) 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 @@ -78,7 +78,7 @@ class WichmannHill(random.Random): # Note: on a platform using IEEE-754 double arithmetic, this can # 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): """Return internal state; can be passed to setstate() later.""" @@ -130,7 +130,7 @@ class WichmannHill(random.Random): # Initialize from current time import time t = int(time.time() * 256) - t = int((t&0xffffff) ^ (t>>24)) + t = int((t & 0xffffff) ^ (t >> 24)) t, x = divmod(t, 256) t, y = divmod(t, 256) t, z = divmod(t, 256) diff --git a/lib/core/settings.py b/lib/core/settings.py index 8684b44a7..bcef70f3b 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -17,7 +17,7 @@ from lib.core.enums import DBMS_DIRECTORY_NAME from lib.core.enums import OS # sqlmap version (...) -VERSION = "1.3.4.30" +VERSION = "1.3.4.31" TYPE = "dev" if VERSION.count('.') > 2 and VERSION.split('.')[-1] != '0' else "stable" 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) diff --git a/lib/parse/cmdline.py b/lib/parse/cmdline.py index 049e1f49b..b20b95aa7 100644 --- a/lib/parse/cmdline.py +++ b/lib/parse/cmdline.py @@ -224,7 +224,7 @@ def cmdLineParser(argv=None): request.add_option("--eval", dest="evalCode", help="Evaluate provided Python code before the request (e.g. \"import hashlib;id2=hashlib.md5(id).hexdigest()\")") - + # Optimization options optimization = OptionGroup(parser, "Optimization", "These options can be used to optimize the performance of sqlmap") @@ -600,7 +600,7 @@ def cmdLineParser(argv=None): help="Parse and display DBMS error messages from responses") 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", help="Redump entries having unknown character marker (%s)" % INFERENCE_UNKNOWN_CHAR) diff --git a/lib/request/connect.py b/lib/request/connect.py index e89dfafa9..fe87fd101 100644 --- a/lib/request/connect.py +++ b/lib/request/connect.py @@ -406,7 +406,7 @@ class Connect(object): if conf.keepAlive: headers[HTTP_HEADER.CONNECTION] = "keep-alive" - + if chunked: headers[HTTP_HEADER.TRANSFER_ENCODING] = "chunked" diff --git a/lib/utils/sgmllib.py b/lib/utils/sgmllib.py index 227529789..c69e08996 100644 --- a/lib/utils/sgmllib.py +++ b/lib/utils/sgmllib.py @@ -21,9 +21,9 @@ __all__ = ["SGMLParser", "SGMLParseError"] interesting = re.compile('[&<]') 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]') charref = re.compile('&#([0-9]+)[^0-9]') @@ -58,8 +58,8 @@ class SGMLParseError(RuntimeError): class SGMLParser(_markupbase.ParserBase): # Definition of entities -- derived classes may override 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): """Initialize and reset this instance.""" @@ -121,32 +121,37 @@ class SGMLParser(_markupbase.ParserBase): i = n break match = interesting.search(rawdata, i) - if match: j = match.start() - else: j = n + if match: + j = match.start() + else: + j = n if i < j: self.handle_data(rawdata[i:j]) i = j - if i == n: break + if i == n: + break if rawdata[i] == '<': if starttagopen.match(rawdata, i): if self.literal: self.handle_data(rawdata[i]) - i = i+1 + i = i + 1 continue k = self.parse_starttag(i) - if k < 0: break + if k < 0: + break i = k continue if rawdata.startswith(" (i + 1): self.handle_data("<") - i = i+1 + i = i + 1 else: # incomplete break @@ -157,12 +162,14 @@ class SGMLParser(_markupbase.ParserBase): # This should be removed, # and comments handled only in parse_declaration. k = self.parse_comment(i) - if k < 0: break + if k < 0: + break i = k continue if rawdata.startswith(""). k = self.parse_declaration(i) - if k < 0: break + if k < 0: + break i = k continue elif rawdata[i] == '&': if self.literal: self.handle_data(rawdata[i]) - i = i+1 + i = i + 1 continue match = charref.match(rawdata, i) if match: name = match.group(1) self.handle_charref(name) i = match.end(0) - if rawdata[i-1] != ';': i = i-1 + if rawdata[i-1] != ';': + i = i-1 continue match = entityref.match(rawdata, i) if match: name = match.group(1) self.handle_entityref(name) i = match.end(0) - if rawdata[i-1] != ';': i = i-1 + if rawdata[i-1] != ';': + i = i-1 continue else: self.error('neither < nor & ??') @@ -199,11 +209,11 @@ class SGMLParser(_markupbase.ParserBase): match = incomplete.match(rawdata, i) if not match: self.handle_data(rawdata[i]) - i = i+1 + i = i + 1 continue j = match.end(0) if j == n: - break # Really incomplete + break # Really incomplete self.handle_data(rawdata[i:j]) i = j # end while @@ -256,32 +266,33 @@ class SGMLParser(_markupbase.ParserBase): # 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 # < or > characters may be embedded in an attribute value. - match = endbracket.search(rawdata, i+1) + match = endbracket.search(rawdata, i + 1) if not match: return -1 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 = [] if rawdata[i:i+2] == '<>': # SGML shorthand: <> == k = j tag = self.lasttag else: - match = tagfind.match(rawdata, i+1) + match = tagfind.match(rawdata, i + 1) if not match: self.error('unexpected call to parse_starttag') k = match.end(0) - tag = rawdata[i+1:k].lower() + tag = rawdata[i + 1:k].lower() self.lasttag = tag while k < j: match = attrfind.match(rawdata, k) - if not match: break + if not match: + break attrname, rest, attrvalue = match.group(1, 2, 3) if not rest: attrvalue = attrname else: if (attrvalue[:1] == "'" == attrvalue[-1:] or - attrvalue[:1] == '"' == attrvalue[-1:]): + attrvalue[:1] == '"' == attrvalue[-1:]): # strip quotes attrvalue = attrvalue[1:-1] attrvalue = self.entity_or_charref.sub( @@ -289,7 +300,7 @@ class SGMLParser(_markupbase.ParserBase): attrs.append((attrname.lower(), attrvalue)) k = match.end(0) if rawdata[j] == '>': - j = j+1 + j = j + 1 self.__starttag_text = rawdata[start_pos:j] self.finish_starttag(tag, attrs) return j @@ -308,13 +319,13 @@ class SGMLParser(_markupbase.ParserBase): # Internal -- parse endtag def parse_endtag(self, i): rawdata = self.rawdata - match = endbracket.search(rawdata, i+1) + match = endbracket.search(rawdata, i + 1) if not match: return -1 j = match.start(0) tag = rawdata[i+2:j].strip().lower() if rawdata[j] == '>': - j = j+1 + j = j + 1 self.finish_endtag(tag) return j @@ -361,7 +372,8 @@ class SGMLParser(_markupbase.ParserBase): return found = len(self.stack) for i in range(found): - if self.stack[i] == tag: found = i + if self.stack[i] == tag: + found = i while len(self.stack) > found: tag = self.stack[-1] try: @@ -411,7 +423,7 @@ class SGMLParser(_markupbase.ParserBase): # Definition of entities -- derived classes may override entitydefs = \ - {'lt': '<', 'gt': '>', 'amp': '&', 'quot': '"', 'apos': '\''} + {'lt': '<', 'gt': '>', 'amp': '&', 'quot': '"', 'apos': '\''} def convert_entityref(self, name): """Convert entity references. @@ -450,10 +462,17 @@ class SGMLParser(_markupbase.ParserBase): pass # To be overridden -- handlers for unknown objects - def unknown_starttag(self, tag, attrs): pass - def unknown_endtag(self, tag): pass - def unknown_charref(self, ref): pass - def unknown_entityref(self, ref): pass + def unknown_starttag(self, tag, attrs): + pass + + def unknown_endtag(self, tag): + pass + + def unknown_charref(self, ref): + pass + + def unknown_entityref(self, ref): + pass class TestSGMLParser(SGMLParser): @@ -511,7 +530,7 @@ class TestSGMLParser(SGMLParser): self.flush() -def test(args = None): +def test(args=None): import sys if args is None: @@ -548,4 +567,4 @@ def test(args = None): if __name__ == '__main__': - test() \ No newline at end of file + test() diff --git a/plugins/dbms/db2/filesystem.py b/plugins/dbms/db2/filesystem.py index 7e93a4c12..c640bae43 100644 --- a/plugins/dbms/db2/filesystem.py +++ b/plugins/dbms/db2/filesystem.py @@ -8,4 +8,4 @@ See the file 'LICENSE' for copying permission from plugins.generic.filesystem import Filesystem as GenericFilesystem class Filesystem(GenericFilesystem): - pass \ No newline at end of file + pass diff --git a/plugins/dbms/informix/filesystem.py b/plugins/dbms/informix/filesystem.py index 7e93a4c12..c640bae43 100644 --- a/plugins/dbms/informix/filesystem.py +++ b/plugins/dbms/informix/filesystem.py @@ -8,4 +8,4 @@ See the file 'LICENSE' for copying permission from plugins.generic.filesystem import Filesystem as GenericFilesystem class Filesystem(GenericFilesystem): - pass \ No newline at end of file + pass diff --git a/plugins/dbms/mysql/enumeration.py b/plugins/dbms/mysql/enumeration.py index 35b6e42bb..e0d798ddf 100644 --- a/plugins/dbms/mysql/enumeration.py +++ b/plugins/dbms/mysql/enumeration.py @@ -8,4 +8,4 @@ See the file 'LICENSE' for copying permission from plugins.generic.enumeration import Enumeration as GenericEnumeration class Enumeration(GenericEnumeration): - pass \ No newline at end of file + pass diff --git a/waf/chinacache.py b/waf/chinacache.py index 35fc66c1b..0a3021fb1 100644 --- a/waf/chinacache.py +++ b/waf/chinacache.py @@ -19,4 +19,4 @@ def detect(get_page): if retval: break - return retval \ No newline at end of file + return retval