mirror of
https://github.com/sqlmapproject/sqlmap.git
synced 2026-01-21 13:49:04 +00:00
minor refactoring
This commit is contained in:
@@ -788,7 +788,7 @@ def readInput(message, default=None, checkBatch=True):
|
||||
message += " "
|
||||
|
||||
if checkBatch and conf.batch:
|
||||
if isinstance(default, (list, tuple, set)):
|
||||
if isListLike(default):
|
||||
options = ",".join(getUnicode(opt, UNICODE_ENCODING) for opt in default)
|
||||
elif default:
|
||||
options = getUnicode(default, UNICODE_ENCODING)
|
||||
@@ -1888,7 +1888,7 @@ def getUnicode(value, encoding=None, system=False, noneToNull=False):
|
||||
if noneToNull and value is None:
|
||||
return NULL
|
||||
|
||||
if isinstance(value, (list, tuple)):
|
||||
if isListLike(value):
|
||||
value = list(getUnicode(_, encoding, system, noneToNull) for _ in value)
|
||||
return value
|
||||
|
||||
@@ -2425,7 +2425,7 @@ def arrayizeValue(value):
|
||||
Makes a list out of value if it is not already a list or tuple itself
|
||||
"""
|
||||
|
||||
if not isinstance(value, (list, tuple)):
|
||||
if not isListLike(value):
|
||||
value = [value]
|
||||
|
||||
return value
|
||||
@@ -2435,7 +2435,7 @@ def unArrayizeValue(value):
|
||||
Makes a value out of iterable if it is a list or tuple itself
|
||||
"""
|
||||
|
||||
if isinstance(value, (list, tuple)):
|
||||
if isListLike(value):
|
||||
value = value[0] if len(value) > 0 else None
|
||||
|
||||
return value
|
||||
@@ -2446,12 +2446,19 @@ def flattenValue(value):
|
||||
"""
|
||||
|
||||
for i in iter(value):
|
||||
if isinstance(i, (list, tuple)):
|
||||
if isListLike(i):
|
||||
for j in flattenValue(i):
|
||||
yield j
|
||||
else:
|
||||
yield i
|
||||
|
||||
def isListLike(value):
|
||||
"""
|
||||
Returns True if the given value is a list-like instance
|
||||
"""
|
||||
|
||||
return isinstance(value, (list, tuple, set, BigArray))
|
||||
|
||||
def getSortedInjectionTests():
|
||||
"""
|
||||
Returns prioritized test list by eventually detected DBMS from error
|
||||
@@ -2784,7 +2791,7 @@ def isNoneValue(value):
|
||||
|
||||
if isinstance(value, basestring):
|
||||
return value in ("None", "")
|
||||
elif isinstance(value, (list, tuple)):
|
||||
elif isListLike(value):
|
||||
return all(isNoneValue(_) for _ in value)
|
||||
elif isinstance(value, dict):
|
||||
return not any(value)
|
||||
@@ -3127,7 +3134,7 @@ def applyFunctionRecursively(value, function):
|
||||
Applies function recursively through list-like structures
|
||||
"""
|
||||
|
||||
if isinstance(value, (list, tuple, set, BigArray)):
|
||||
if isListLike(value):
|
||||
retVal = [applyFunctionRecursively(_, function) for _ in value]
|
||||
else:
|
||||
retVal = function(value)
|
||||
|
||||
@@ -17,6 +17,7 @@ from lib.core.common import Backend
|
||||
from lib.core.common import dataToDumpFile
|
||||
from lib.core.common import dataToStdout
|
||||
from lib.core.common import getUnicode
|
||||
from lib.core.common import isListLike
|
||||
from lib.core.common import normalizeUnicode
|
||||
from lib.core.common import openFile
|
||||
from lib.core.common import prioritySortColumns
|
||||
@@ -72,7 +73,7 @@ class Dump:
|
||||
return self._outputFile
|
||||
|
||||
def string(self, header, data, sort=True):
|
||||
if isinstance(data, (list, tuple, set)):
|
||||
if isListLike(data):
|
||||
self.lister(header, data, sort)
|
||||
elif data:
|
||||
data = self._formatString(getUnicode(data))
|
||||
@@ -102,7 +103,7 @@ class Dump:
|
||||
for element in elements:
|
||||
if isinstance(element, basestring):
|
||||
self._write("[*] %s" % element)
|
||||
elif isinstance(element, (list, tuple, set)):
|
||||
elif isListLike(element):
|
||||
self._write("[*] " + ", ".join(getUnicode(e) for e in element))
|
||||
|
||||
if elements:
|
||||
@@ -173,7 +174,7 @@ class Dump:
|
||||
|
||||
for tables in dbTables.values():
|
||||
for table in tables:
|
||||
if isinstance(table, (list, tuple, set)):
|
||||
if table and isListLike(table):
|
||||
table = table[0]
|
||||
|
||||
maxlength = max(maxlength, len(normalizeUnicode(table) or str(table)))
|
||||
@@ -193,7 +194,7 @@ class Dump:
|
||||
self._write("+%s+" % lines)
|
||||
|
||||
for table in tables:
|
||||
if isinstance(table, (list, tuple, set)):
|
||||
if table and isListLike(table):
|
||||
table = table[0]
|
||||
|
||||
blank = " " * (maxlength - len(normalizeUnicode(table) or str(table)))
|
||||
|
||||
@@ -35,6 +35,7 @@ from lib.core.common import findPageForms
|
||||
from lib.core.common import getConsoleWidth
|
||||
from lib.core.common import getFileItems
|
||||
from lib.core.common import getFileType
|
||||
from lib.core.common import isListLike
|
||||
from lib.core.common import normalizePath
|
||||
from lib.core.common import ntToPosixSlashes
|
||||
from lib.core.common import openFile
|
||||
@@ -1630,7 +1631,7 @@ def __saveCmdline():
|
||||
optionData.sort()
|
||||
|
||||
for option, value, datatype in optionData:
|
||||
if isinstance(datatype, (list, tuple, set)):
|
||||
if datatype and isListLike(datatype):
|
||||
datatype = datatype[0]
|
||||
|
||||
if value is None:
|
||||
|
||||
Reference in New Issue
Block a user