mirror of
https://github.com/sqlmapproject/sqlmap.git
synced 2026-01-29 09:39:04 +00:00
Minor improvement of AttribDict logic
This commit is contained in:
@@ -20,21 +20,18 @@ class AttribDict(dict):
|
||||
>>> foo.bar = 1
|
||||
>>> foo.bar
|
||||
1
|
||||
>>> import copy; copy.deepcopy(foo).bar
|
||||
1
|
||||
"""
|
||||
|
||||
def __init__(self, indict=None, attribute=None, keycheck=True):
|
||||
if indict is None:
|
||||
indict = {}
|
||||
|
||||
# Set any attributes here - before initialisation
|
||||
# these remain as normal attributes
|
||||
self.attribute = attribute
|
||||
self.keycheck = keycheck
|
||||
dict.__init__(self, indict)
|
||||
self.__initialised = True
|
||||
|
||||
# After initialisation, setting attributes
|
||||
# is the same as setting an item
|
||||
self.__dict__["_attribute"] = attribute
|
||||
self.__dict__["_keycheck"] = keycheck
|
||||
self.__dict__["_initialized"] = True
|
||||
|
||||
def __getattr__(self, item):
|
||||
"""
|
||||
@@ -45,7 +42,7 @@ class AttribDict(dict):
|
||||
try:
|
||||
return self.__getitem__(item)
|
||||
except KeyError:
|
||||
if self.keycheck:
|
||||
if self.__dict__.get("_keycheck"):
|
||||
raise AttributeError("unable to access item '%s'" % item)
|
||||
else:
|
||||
return None
|
||||
@@ -58,7 +55,7 @@ class AttribDict(dict):
|
||||
try:
|
||||
return self.pop(item)
|
||||
except KeyError:
|
||||
if self.keycheck:
|
||||
if self.__dict__.get("_keycheck"):
|
||||
raise AttributeError("unable to access item '%s'" % item)
|
||||
else:
|
||||
return None
|
||||
@@ -69,14 +66,8 @@ class AttribDict(dict):
|
||||
Only if we are initialised
|
||||
"""
|
||||
|
||||
# This test allows attributes to be set in the __init__ method
|
||||
if "_AttribDict__initialised" not in self.__dict__:
|
||||
return dict.__setattr__(self, item, value)
|
||||
|
||||
# Any normal attributes are handled normally
|
||||
elif item in self.__dict__:
|
||||
dict.__setattr__(self, item, value)
|
||||
|
||||
if "_initialized" not in self.__dict__ or item in self.__dict__:
|
||||
self.__dict__[item] = value
|
||||
else:
|
||||
self.__setitem__(item, value)
|
||||
|
||||
@@ -87,14 +78,12 @@ class AttribDict(dict):
|
||||
self.__dict__ = dict
|
||||
|
||||
def __deepcopy__(self, memo):
|
||||
retVal = self.__class__(keycheck=self.keycheck)
|
||||
retVal = self.__class__(keycheck=self.__dict__.get("_keycheck"))
|
||||
memo[id(self)] = retVal
|
||||
|
||||
for attr in dir(self):
|
||||
if not attr.startswith('_'):
|
||||
value = getattr(self, attr)
|
||||
if not isinstance(value, (types.BuiltinFunctionType, types.FunctionType, types.MethodType)):
|
||||
setattr(retVal, attr, copy.deepcopy(value, memo))
|
||||
for attr, value in self.__dict__.items():
|
||||
if attr not in ('_attribute', '_keycheck', '_initialized'):
|
||||
setattr(retVal, attr, copy.deepcopy(value, memo))
|
||||
|
||||
for key, value in self.items():
|
||||
retVal.__setitem__(key, copy.deepcopy(value, memo))
|
||||
|
||||
@@ -19,7 +19,7 @@ from lib.core.enums import OS
|
||||
from thirdparty import six
|
||||
|
||||
# sqlmap version (<major>.<minor>.<month>.<monthly commit>)
|
||||
VERSION = "1.10.1.59"
|
||||
VERSION = "1.10.1.60"
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user