Skip to content

Commit 72fcb66

Browse files
committed
Minor improvement of AttribDict logic
1 parent 51b5682 commit 72fcb66

File tree

3 files changed

+16
-27
lines changed

3 files changed

+16
-27
lines changed

data/txt/sha256sums.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ af24159b8ca5b8fe5e13cdfdedc2a758a2f4883361a601e0a550127cff368b3a lib/core/commo
172172
a6397b10de7ae7c56ed6b0fa3b3c58eb7a9dbede61bf93d786e73258175c981e lib/core/compat.py
173173
a9997e97ebe88e0bf7efcf21e878bc5f62c72348e5aba18f64d6861390a4dcf2 lib/core/convert.py
174174
c03dc585f89642cfd81b087ac2723e3e1bb3bfa8c60e6f5fe58ef3b0113ebfe6 lib/core/data.py
175-
e396b7971d38896e0e20b973a3a6a3fbc3171d080a21bc6e66a65bee452fd69c lib/core/datatype.py
175+
ca06a0e9d66a58e74ef994d53f9b3cd2ebaed98735bbab99854054235a8083d6 lib/core/datatype.py
176176
e18c0c2c5a57924a623792a48bfd36e98d9bc085f6db61a95fc0dc8a3bcedc0c lib/core/decorators.py
177177
147823c37596bd6a56d677697781f34b8d1d1671d5a2518fbc9468d623c6d07d lib/core/defaults.py
178178
6b366f897e66b9df39df2ee45fef77d46efb7a2d4e294440d3aa7dc1b2f4cedf lib/core/dicts.py
@@ -189,7 +189,7 @@ a033f92d136c707a25927c2383125ddb004d4283db62c004dcd67c3fc242bb1c lib/core/dump.
189189
48797d6c34dd9bb8a53f7f3794c85f4288d82a9a1d6be7fcf317d388cb20d4b3 lib/core/replication.py
190190
0b8c38a01bb01f843d94a6c5f2075ee47520d0c4aa799cecea9c3e2c5a4a23a6 lib/core/revision.py
191191
888daba83fd4a34e9503fe21f01fef4cc730e5cde871b1d40e15d4cbc847d56c lib/core/session.py
192-
7f08f592c49c3534afc931a7fb9e1915ffa7425e66ada1d58e56e3383758440f lib/core/settings.py
192+
d6577e20ed58d058dcde4341010e3ea26240cc959185ce9471eda0fab17a21cf lib/core/settings.py
193193
cd5a66deee8963ba8e7e9af3dd36eb5e8127d4d68698811c29e789655f507f82 lib/core/shell.py
194194
bcb5d8090d5e3e0ef2a586ba09ba80eef0c6d51feb0f611ed25299fbb254f725 lib/core/subprocessng.py
195195
d35650179816193164a5f177102f18379dfbe6bb6d40fbb67b78d907b41c8038 lib/core/target.py

lib/core/datatype.py

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,18 @@ class AttribDict(dict):
2020
>>> foo.bar = 1
2121
>>> foo.bar
2222
1
23+
>>> import copy; copy.deepcopy(foo).bar
24+
1
2325
"""
2426

2527
def __init__(self, indict=None, attribute=None, keycheck=True):
2628
if indict is None:
2729
indict = {}
2830

29-
# Set any attributes here - before initialisation
30-
# these remain as normal attributes
31-
self.attribute = attribute
32-
self.keycheck = keycheck
3331
dict.__init__(self, indict)
34-
self.__initialised = True
35-
36-
# After initialisation, setting attributes
37-
# is the same as setting an item
32+
self.__dict__["_attribute"] = attribute
33+
self.__dict__["_keycheck"] = keycheck
34+
self.__dict__["_initialized"] = True
3835

3936
def __getattr__(self, item):
4037
"""
@@ -45,7 +42,7 @@ def __getattr__(self, item):
4542
try:
4643
return self.__getitem__(item)
4744
except KeyError:
48-
if self.keycheck:
45+
if self.__dict__.get("_keycheck"):
4946
raise AttributeError("unable to access item '%s'" % item)
5047
else:
5148
return None
@@ -58,7 +55,7 @@ def __delattr__(self, item):
5855
try:
5956
return self.pop(item)
6057
except KeyError:
61-
if self.keycheck:
58+
if self.__dict__.get("_keycheck"):
6259
raise AttributeError("unable to access item '%s'" % item)
6360
else:
6461
return None
@@ -69,14 +66,8 @@ def __setattr__(self, item, value):
6966
Only if we are initialised
7067
"""
7168

72-
# This test allows attributes to be set in the __init__ method
73-
if "_AttribDict__initialised" not in self.__dict__:
74-
return dict.__setattr__(self, item, value)
75-
76-
# Any normal attributes are handled normally
77-
elif item in self.__dict__:
78-
dict.__setattr__(self, item, value)
79-
69+
if "_initialized" not in self.__dict__ or item in self.__dict__:
70+
self.__dict__[item] = value
8071
else:
8172
self.__setitem__(item, value)
8273

@@ -87,14 +78,12 @@ def __setstate__(self, dict):
8778
self.__dict__ = dict
8879

8980
def __deepcopy__(self, memo):
90-
retVal = self.__class__(keycheck=self.keycheck)
81+
retVal = self.__class__(keycheck=self.__dict__.get("_keycheck"))
9182
memo[id(self)] = retVal
9283

93-
for attr in dir(self):
94-
if not attr.startswith('_'):
95-
value = getattr(self, attr)
96-
if not isinstance(value, (types.BuiltinFunctionType, types.FunctionType, types.MethodType)):
97-
setattr(retVal, attr, copy.deepcopy(value, memo))
84+
for attr, value in self.__dict__.items():
85+
if attr not in ('_attribute', '_keycheck', '_initialized'):
86+
setattr(retVal, attr, copy.deepcopy(value, memo))
9887

9988
for key, value in self.items():
10089
retVal.__setitem__(key, copy.deepcopy(value, memo))

lib/core/settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from thirdparty import six
2020

2121
# sqlmap version (<major>.<minor>.<month>.<monthly commit>)
22-
VERSION = "1.10.1.59"
22+
VERSION = "1.10.1.60"
2323
TYPE = "dev" if VERSION.count('.') > 2 and VERSION.split('.')[-1] != '0' else "stable"
2424
TYPE_COLORS = {"dev": 33, "stable": 90, "pip": 34}
2525
VERSION_STRING = "sqlmap/%s#%s" % ('.'.join(VERSION.split('.')[:-1]) if VERSION.count('.') > 2 and VERSION.split('.')[-1] == '0' else VERSION, TYPE)

0 commit comments

Comments
 (0)