Further pleasing the pylint gods

This commit is contained in:
Miroslav Stampar 2019-05-30 22:40:51 +02:00
parent 1f7ee039ad
commit f8e9f9c87d
14 changed files with 38 additions and 50 deletions

View File

@ -70,7 +70,6 @@ enable=import-error,
unused-wildcard-import,
global-variable-not-assigned,
undefined-loop-variable,
global-statement,
global-at-module-level,
bad-open-mode,
redundant-unittest-assert,

View File

@ -561,7 +561,7 @@ def checkSqlInjection(place, parameter, value):
candidates = trueSet - falseSet - errorSet
if candidates:
candidates = sorted(candidates, key=lambda _: len(_))
candidates = sorted(candidates, key=len)
for candidate in candidates:
if re.match(r"\A[\w.,! ]+\Z", candidate) and ' ' in candidate and candidate.strip() and len(candidate) > CANDIDATE_SENTENCE_MIN_LENGTH:
conf.string = candidate
@ -595,7 +595,7 @@ def checkSqlInjection(place, parameter, value):
candidates = filterNone(_.strip() if _.strip() in trueRawResponse and _.strip() not in falseRawResponse else None for _ in (trueSet - falseSet - errorSet))
if candidates:
candidates = sorted(candidates, key=lambda _: len(_))
candidates = sorted(candidates, key=len)
for candidate in candidates:
if re.match(r"\A\w+\Z", candidate):
break
@ -609,7 +609,7 @@ def checkSqlInjection(place, parameter, value):
candidates = filterNone(_.strip() if _.strip() in falseRawResponse and _.strip() not in trueRawResponse else None for _ in (falseSet - trueSet))
if candidates:
candidates = sorted(candidates, key=lambda _: len(_))
candidates = sorted(candidates, key=len)
for candidate in candidates:
if re.match(r"\A\w+\Z", candidate):
break

View File

@ -53,7 +53,7 @@ class BigArray(list):
List-like class used for storing large amounts of data (disk cached)
"""
def __init__(self, items=[]):
def __init__(self, items=None):
self.chunks = [[]]
self.chunk_length = sys.maxsize
self.cache = None
@ -61,7 +61,7 @@ class BigArray(list):
self._os_remove = os.remove
self._size_counter = 0
for item in items:
for item in (items or []):
self.append(item)
def append(self, value):
@ -139,12 +139,6 @@ class BigArray(list):
self.__init__()
self.chunks, self.filenames = state
def __getslice__(self, i, j):
i = max(0, len(self) + i if i < 0 else i)
j = min(len(self), len(self) + j if j < 0 else j)
return BigArray(self[_] for _ in xrange(i, j))
def __getitem__(self, y):
if y < 0:
y += len(self)

View File

@ -2328,22 +2328,21 @@ def initCommonOutputs():
kb.commonOutputs = {}
key = None
with openFile(paths.COMMON_OUTPUTS, 'r') as f:
for line in f:
if line.find('#') != -1:
line = line[:line.find('#')]
for line in openFile(paths.COMMON_OUTPUTS, 'r'):
if line.find('#') != -1:
line = line[:line.find('#')]
line = line.strip()
line = line.strip()
if len(line) > 1:
if line.startswith('[') and line.endswith(']'):
key = line[1:-1]
elif key:
if key not in kb.commonOutputs:
kb.commonOutputs[key] = set()
if len(line) > 1:
if line.startswith('[') and line.endswith(']'):
key = line[1:-1]
elif key:
if key not in kb.commonOutputs:
kb.commonOutputs[key] = set()
if line not in kb.commonOutputs[key]:
kb.commonOutputs[key].add(line)
if line not in kb.commonOutputs[key]:
kb.commonOutputs[key].add(line)
def getFileItems(filename, commentPrefix='#', unicoded=True, lowercase=False, unique=False):
"""
@ -3921,7 +3920,7 @@ def normalizeUnicode(value, charset=string.printable[:string.printable.find(' ')
# Reference: http://www.peterbe.com/plog/unicode-to-ascii
>>> normalizeUnicode(u'\u0161u\u0107uraj') == u'sucuraj'
>>> normalizeUnicode(u'\\u0161u\\u0107uraj') == u'sucuraj'
True
>>> normalizeUnicode(getUnicode(decodeHex("666f6f00626172"))) == u'foobar'
True
@ -4096,7 +4095,7 @@ def expandMnemonics(mnemonics, parser, args):
debugMsg = "mnemonic '%s' resolved to %s). " % (name, found)
logger.debug(debugMsg)
else:
found = sorted(options.keys(), key=lambda x: len(x))[0]
found = sorted(options.keys(), key=len)[0]
warnMsg = "detected ambiguity (mnemonic '%s' can be resolved to any of: %s). " % (name, ", ".join("'%s'" % key for key in options))
warnMsg += "Resolved to shortest of those ('%s')" % found
logger.warn(warnMsg)
@ -5043,7 +5042,6 @@ def parseRequestFile(reqFile, checkParams=True):
def getSafeExString(ex, encoding=None):
"""
Safe way how to get the proper exception represtation as a string
(Note: errors to be avoided: 1) "%s" % Exception(u'\u0161') and 2) "%s" % str(Exception(u'\u0161'))
>>> getSafeExString(SqlmapBaseException('foobar')) == 'foobar'
True

View File

@ -184,15 +184,15 @@ class OrderedSet(collections.MutableSet):
def __contains__(self, key):
return key in self.map
def add(self, key):
if key not in self.map:
def add(self, value):
if value not in self.map:
end = self.end
curr = end[1]
curr[2] = end[1] = self.map[key] = [key, curr, end]
curr[2] = end[1] = self.map[value] = [value, curr, end]
def discard(self, key):
if key in self.map:
key, prev, next = self.map.pop(key)
def discard(self, value):
if value in self.map:
value, prev, next = self.map.pop(value)
prev[2] = next
next[1] = prev

View File

@ -468,8 +468,7 @@ class Dump(object):
shutil.copyfile(dumpFileName, candidate)
except IOError:
pass
finally:
break
break
else:
count += 1

View File

@ -838,6 +838,7 @@ def _setPreprocessFunctions():
if conf.preprocess:
for script in re.split(PARAMETER_SPLITTING_REGEX, conf.preprocess):
found = False
function = None
script = safeFilepathEncode(script.strip())

View File

@ -79,9 +79,9 @@ class Replication(object):
errMsg = "wrong number of columns used in replicating insert"
raise SqlmapValueException(errMsg)
def execute(self, sql, parameters=[]):
def execute(self, sql, parameters=None):
try:
self.parent.cursor.execute(sql, parameters)
self.parent.cursor.execute(sql, parameters or [])
except sqlite3.OperationalError as ex:
errMsg = "problem occurred ('%s') while accessing sqlite database " % getSafeExString(ex, UNICODE_ENCODING)
errMsg += "located at '%s'. Please make sure that " % self.parent.dbpath

View File

@ -18,7 +18,7 @@ from lib.core.enums import OS
from thirdparty.six import unichr as _unichr
# sqlmap version (<major>.<minor>.<month>.<monthly commit>)
VERSION = "1.3.5.154"
VERSION = "1.3.5.155"
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)

View File

@ -53,11 +53,11 @@ class MSSQLBannerHandler(ContentHandler):
elif name == "servicepack":
self._inServicePack = True
def characters(self, data):
def characters(self, content):
if self._inVersion:
self._version += sanitizeStr(data)
self._version += sanitizeStr(content)
elif self._inServicePack:
self._servicePack += sanitizeStr(data)
self._servicePack += sanitizeStr(content)
def endElement(self, name):
if name == "signature":

View File

@ -57,10 +57,10 @@ class _GetchMacCarbon(object):
"""
def __init__(self):
import Carbon
Carbon.Evt # see if it has this (in Unix, it doesn't)
_ = Carbon.Evt # see if it has this (in Unix, it doesn't)
def __call__(self):
import Carbon
if Carbon.Evt.EventAvail(0x0008)[0] == 0: # 0x0008 is the keyDownMask
return ''
else:

View File

@ -635,7 +635,7 @@ def attackDumpedTable():
col_passwords = set()
attack_dict = {}
for column in sorted(columns, key=lambda _: len(_), reverse=True):
for column in sorted(columns, key=len, reverse=True):
if column and column.lower() in COMMON_USER_COLUMNS:
col_user = column
break

View File

@ -11,7 +11,7 @@ from lib.core.data import logger
from lib.core.enums import CUSTOM_LOGGING
from lib.core.enums import TIMEOUT_STATE
def timeout(func, args=(), kwargs={}, duration=1, default=None):
def timeout(func, args=None, kwargs=None, duration=1, default=None):
class InterruptableThread(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
@ -20,7 +20,7 @@ def timeout(func, args=(), kwargs={}, duration=1, default=None):
def run(self):
try:
self.result = func(*args, **kwargs)
self.result = func(*(args or ()), **(kwargs or {}))
self.timeout_state = TIMEOUT_STATE.NORMAL
except Exception as ex:
logger.log(CUSTOM_LOGGING.TRAFFIC_IN, ex)

View File

@ -66,9 +66,6 @@ class xrange(object):
def __hash__(self):
return hash(self._slice)
def __cmp__(self, other):
return (cmp(type(self), type(other)) or cmp(self._slice, other._slice))
def __repr__(self):
return '%s(%r, %r, %r)' % (type(self).__name__, self.start, self.stop, self.step)