Minor improvement of AttribDict logic

This commit is contained in:
Miroslav Stampar
2026-01-27 11:27:55 +01:00
parent 51b56820f7
commit 72fcb66fe8
3 changed files with 16 additions and 27 deletions

View File

@@ -172,7 +172,7 @@ af24159b8ca5b8fe5e13cdfdedc2a758a2f4883361a601e0a550127cff368b3a lib/core/commo
a6397b10de7ae7c56ed6b0fa3b3c58eb7a9dbede61bf93d786e73258175c981e lib/core/compat.py
a9997e97ebe88e0bf7efcf21e878bc5f62c72348e5aba18f64d6861390a4dcf2 lib/core/convert.py
c03dc585f89642cfd81b087ac2723e3e1bb3bfa8c60e6f5fe58ef3b0113ebfe6 lib/core/data.py
e396b7971d38896e0e20b973a3a6a3fbc3171d080a21bc6e66a65bee452fd69c lib/core/datatype.py
ca06a0e9d66a58e74ef994d53f9b3cd2ebaed98735bbab99854054235a8083d6 lib/core/datatype.py
e18c0c2c5a57924a623792a48bfd36e98d9bc085f6db61a95fc0dc8a3bcedc0c lib/core/decorators.py
147823c37596bd6a56d677697781f34b8d1d1671d5a2518fbc9468d623c6d07d lib/core/defaults.py
6b366f897e66b9df39df2ee45fef77d46efb7a2d4e294440d3aa7dc1b2f4cedf lib/core/dicts.py
@@ -189,7 +189,7 @@ a033f92d136c707a25927c2383125ddb004d4283db62c004dcd67c3fc242bb1c lib/core/dump.
48797d6c34dd9bb8a53f7f3794c85f4288d82a9a1d6be7fcf317d388cb20d4b3 lib/core/replication.py
0b8c38a01bb01f843d94a6c5f2075ee47520d0c4aa799cecea9c3e2c5a4a23a6 lib/core/revision.py
888daba83fd4a34e9503fe21f01fef4cc730e5cde871b1d40e15d4cbc847d56c lib/core/session.py
7f08f592c49c3534afc931a7fb9e1915ffa7425e66ada1d58e56e3383758440f lib/core/settings.py
d6577e20ed58d058dcde4341010e3ea26240cc959185ce9471eda0fab17a21cf lib/core/settings.py
cd5a66deee8963ba8e7e9af3dd36eb5e8127d4d68698811c29e789655f507f82 lib/core/shell.py
bcb5d8090d5e3e0ef2a586ba09ba80eef0c6d51feb0f611ed25299fbb254f725 lib/core/subprocessng.py
d35650179816193164a5f177102f18379dfbe6bb6d40fbb67b78d907b41c8038 lib/core/target.py

View File

@@ -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))

View File

@@ -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)