@@ -27,10 +27,12 @@ def _size_of(object_):
2727 """
2828
2929 retval = sys .getsizeof (object_ , DEFAULT_SIZE_OF )
30+
3031 if isinstance (object_ , dict ):
3132 retval += sum (_size_of (_ ) for _ in itertools .chain .from_iterable (object_ .items ()))
3233 elif hasattr (object_ , "__iter__" ):
3334 retval += sum (_size_of (_ ) for _ in object_ )
35+
3436 return retval
3537
3638class Cache (object ):
@@ -58,11 +60,13 @@ def __init__(self):
5860
5961 def append (self , value ):
6062 self .chunks [- 1 ].append (value )
63+
6164 if self .chunk_length == sys .maxint :
6265 self ._size_counter += _size_of (value )
6366 if self ._size_counter >= BIGARRAY_CHUNK_SIZE :
6467 self .chunk_length = len (self .chunks [- 1 ])
6568 self ._size_counter = None
69+
6670 if len (self .chunks [- 1 ]) >= self .chunk_length :
6771 filename = self ._dump (self .chunks [- 1 ])
6872 self .chunks [- 1 ] = filename
@@ -82,12 +86,14 @@ def pop(self):
8286 errMsg = "exception occurred while retrieving data "
8387 errMsg += "from a temporary file ('%s')" % ex .message
8488 raise SqlmapSystemException , errMsg
89+
8590 return self .chunks [- 1 ].pop ()
8691
8792 def index (self , value ):
8893 for index in xrange (len (self )):
8994 if self [index ] == value :
9095 return index
96+
9197 return ValueError , "%s is not in list" % value
9298
9399 def _dump (self , chunk ):
@@ -110,6 +116,7 @@ def _checkcache(self, index):
110116 if (self .cache and self .cache .index != index and self .cache .dirty ):
111117 filename = self ._dump (self .cache .data )
112118 self .chunks [self .cache .index ] = filename
119+
113120 if not (self .cache and self .cache .index == index ):
114121 try :
115122 with open (self .chunks [index ], "rb" ) as fp :
@@ -128,18 +135,23 @@ def __setstate__(self, state):
128135
129136 def __getslice__ (self , i , j ):
130137 retval = BigArray ()
138+
131139 i = max (0 , len (self ) + i if i < 0 else i )
132140 j = min (len (self ), len (self ) + j if j < 0 else j )
141+
133142 for _ in xrange (i , j ):
134143 retval .append (self [_ ])
144+
135145 return retval
136146
137147 def __getitem__ (self , y ):
138148 if y < 0 :
139149 y += len (self )
150+
140151 index = y / self .chunk_length
141152 offset = y % self .chunk_length
142153 chunk = self .chunks [index ]
154+
143155 if isinstance (chunk , list ):
144156 return chunk [offset ]
145157 else :
@@ -150,6 +162,7 @@ def __setitem__(self, y, value):
150162 index = y / self .chunk_length
151163 offset = y % self .chunk_length
152164 chunk = self .chunks [index ]
165+
153166 if isinstance (chunk , list ):
154167 chunk [offset ] = value
155168 else :
0 commit comments