diff --git a/lib/core/common.py b/lib/core/common.py index 346712894..ecafa0087 100644 --- a/lib/core/common.py +++ b/lib/core/common.py @@ -2265,8 +2265,8 @@ def average(values): """ Computes the arithmetic mean of a list of numbers. - >>> round(average([0.9, 0.9, 0.9, 1.0, 0.8, 0.9]), 1) - 0.9 + >>> "%.1f" % average([0.9, 0.9, 0.9, 1.0, 0.8, 0.9]) + '0.9' """ return (1.0 * sum(values) / len(values)) if values else None @@ -2278,8 +2278,8 @@ def stdev(values): # Reference: http://www.goldb.org/corestats.html - >>> round(stdev([0.9, 0.9, 0.9, 1.0, 0.8, 0.9]), 3) - 0.063 + >>> "%.3f" % stdev([0.9, 0.9, 0.9, 1.0, 0.8, 0.9]) + '0.063' """ if not values or len(values) < 2: @@ -4701,10 +4701,7 @@ def prioritySortColumns(columns): def _(column): return column and "id" in column.lower() - if six.PY2: - return sorted(sorted(columns, key=len), lambda x, y: -1 if _(x) and not _(y) else 1 if not _(x) and _(y) else 0) - else: - return sorted(sorted(columns, key=len), key=functools.cmp_to_key(lambda x, y: -1 if _(x) and not _(y) else 1 if not _(x) and _(y) else 0)) + return sorted(sorted(columns, key=len), key=functools.cmp_to_key(lambda x, y: -1 if _(x) and not _(y) else 1 if not _(x) and _(y) else 0)) def getRequestHeader(request, name): """ diff --git a/lib/core/compat.py b/lib/core/compat.py index d1403b302..f3fee9662 100644 --- a/lib/core/compat.py +++ b/lib/core/compat.py @@ -6,6 +6,7 @@ See the file 'LICENSE' for copying permission """ import binascii +import functools import math import os import random @@ -201,6 +202,31 @@ def round(x, d=0): else: return float(math.ceil((x * p) - 0.5))/p +def cmp_to_key(mycmp): + """Convert a cmp= function into a key= function""" + class K(object): + __slots__ = ['obj'] + def __init__(self, obj, *args): + self.obj = obj + def __lt__(self, other): + return mycmp(self.obj, other.obj) < 0 + def __gt__(self, other): + return mycmp(self.obj, other.obj) > 0 + def __eq__(self, other): + return mycmp(self.obj, other.obj) == 0 + def __le__(self, other): + return mycmp(self.obj, other.obj) <= 0 + def __ge__(self, other): + return mycmp(self.obj, other.obj) >= 0 + def __ne__(self, other): + return mycmp(self.obj, other.obj) != 0 + def __hash__(self): + raise TypeError('hash not implemented') + return K + +# Note: patch for Python 2.6 +if not hasattr(functools, "cmp_to_key"): + functools.cmp_to_key = cmp_to_key if sys.version_info >= (3, 0): xrange = range diff --git a/lib/core/settings.py b/lib/core/settings.py index 15738386e..48f4ac011 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -18,7 +18,7 @@ from lib.core.enums import OS from thirdparty import six # sqlmap version (...) -VERSION = "1.3.5.68" +VERSION = "1.3.5.69" 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/utils/purge.py b/lib/utils/purge.py index 2e1e521bd..15146fcff 100644 --- a/lib/utils/purge.py +++ b/lib/utils/purge.py @@ -68,10 +68,7 @@ def purge(directory): except: pass - if six.PY2: - dirpaths.sort(cmp=lambda x, y: y.count(os.path.sep) - x.count(os.path.sep)) - else: - dirpaths.sort(key=functools.cmp_to_key(lambda x, y: y.count(os.path.sep) - x.count(os.path.sep))) + dirpaths.sort(key=functools.cmp_to_key(lambda x, y: y.count(os.path.sep) - x.count(os.path.sep))) logger.debug("renaming directory names to random values") for dirpath in dirpaths: