1010except :
1111 import pickle
1212
13- import bz2
1413import itertools
1514import os
1615import sys
1716import tempfile
17+ import zlib
1818
1919from lib .core .compat import xrange
2020from lib .core .enums import MKSTEMP_PREFIX
2424
2525DEFAULT_SIZE_OF = sys .getsizeof (object ())
2626
27- def _size_of (object_ ):
27+ def _size_of (instance ):
2828 """
29- Returns total size of a given object_ (in bytes)
29+ Returns total size of a given instance / object (in bytes)
3030 """
3131
32- retval = sys .getsizeof (object_ , DEFAULT_SIZE_OF )
32+ retval = sys .getsizeof (instance , DEFAULT_SIZE_OF )
3333
34- if isinstance (object_ , dict ):
35- retval += sum (_size_of (_ ) for _ in itertools .chain .from_iterable (object_ .items ()))
36- elif hasattr (object_ , "__iter__" ):
37- retval += sum (_size_of (_ ) for _ in object_ if _ != object_ )
34+ if isinstance (instance , dict ):
35+ retval += sum (_size_of (_ ) for _ in itertools .chain .from_iterable (instance .items ()))
36+ elif hasattr (instance , "__iter__" ):
37+ retval += sum (_size_of (_ ) for _ in instance if _ != instance )
3838
3939 return retval
4040
@@ -54,8 +54,8 @@ class BigArray(list):
5454
5555 >>> _ = BigArray(xrange(100000))
5656 >>> _[20] = 0
57- >>> _[100 ]
58- 100
57+ >>> _[99999 ]
58+ 99999
5959 """
6060
6161 def __init__ (self , items = None ):
@@ -92,7 +92,7 @@ def pop(self):
9292 self .chunks .pop ()
9393 try :
9494 with open (self .chunks [- 1 ], "rb" ) as f :
95- self .chunks [- 1 ] = pickle .loads (bz2 .decompress (f .read ()))
95+ self .chunks [- 1 ] = pickle .loads (zlib .decompress (f .read ()))
9696 except IOError as ex :
9797 errMsg = "exception occurred while retrieving data "
9898 errMsg += "from a temporary file ('%s')" % ex
@@ -113,7 +113,7 @@ def _dump(self, chunk):
113113 self .filenames .add (filename )
114114 os .close (handle )
115115 with open (filename , "w+b" ) as f :
116- f .write (bz2 .compress (pickle .dumps (chunk , pickle .HIGHEST_PROTOCOL ), BIGARRAY_COMPRESS_LEVEL ))
116+ f .write (zlib .compress (pickle .dumps (chunk , pickle .HIGHEST_PROTOCOL ), BIGARRAY_COMPRESS_LEVEL ))
117117 return filename
118118 except (OSError , IOError ) as ex :
119119 errMsg = "exception occurred while storing data "
@@ -131,7 +131,7 @@ def _checkcache(self, index):
131131 if not (self .cache and self .cache .index == index ):
132132 try :
133133 with open (self .chunks [index ], "rb" ) as f :
134- self .cache = Cache (index , pickle .loads (bz2 .decompress (f .read ())), False )
134+ self .cache = Cache (index , pickle .loads (zlib .decompress (f .read ())), False )
135135 except Exception as ex :
136136 errMsg = "exception occurred while retrieving data "
137137 errMsg += "from a temporary file ('%s')" % ex
0 commit comments