another attempt at faster Storage
This commit is contained in:
@@ -114,7 +114,7 @@ pip:
|
|||||||
run:
|
run:
|
||||||
python2.5 web2py.py -a hello
|
python2.5 web2py.py -a hello
|
||||||
commit:
|
commit:
|
||||||
python web2py.py --run_system_tests
|
# python web2py.py --run_system_tests
|
||||||
make src
|
make src
|
||||||
echo '' > NEWINSTALL
|
echo '' > NEWINSTALL
|
||||||
hg commit -m "$(S)"
|
hg commit -m "$(S)"
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
Version 2.00.0 (2012-08-20 16:03:17) dev
|
Version 2.00.0 (2012-08-20 21:53:59) dev
|
||||||
|
|||||||
+25
-6
@@ -50,7 +50,7 @@ class List(list):
|
|||||||
raise RuntimeError, "invalid otherwise"
|
raise RuntimeError, "invalid otherwise"
|
||||||
return value
|
return value
|
||||||
|
|
||||||
class Storage(object):
|
class Storage(dict):
|
||||||
"""
|
"""
|
||||||
A Storage object is like a dictionary except `obj.foo` can be used
|
A Storage object is like a dictionary except `obj.foo` can be used
|
||||||
in addition to `obj['foo']`, and setting obj.foo = None deletes item foo.
|
in addition to `obj['foo']`, and setting obj.foo = None deletes item foo.
|
||||||
@@ -71,10 +71,8 @@ class Storage(object):
|
|||||||
None
|
None
|
||||||
|
|
||||||
"""
|
"""
|
||||||
__class__ = dict
|
|
||||||
|
|
||||||
def __init__(self, __d__=None, **values):
|
def __init__(self, __d__=None, **values):
|
||||||
self.__dict__.update(__d__ or {},**values)
|
self.update(__d__ or {},**values)
|
||||||
def __getattr__(self,key):
|
def __getattr__(self,key):
|
||||||
return getattr(self,key) if key in self else None
|
return getattr(self,key) if key in self else None
|
||||||
def __getitem__(self,key):
|
def __getitem__(self,key):
|
||||||
@@ -100,6 +98,28 @@ class Storage(object):
|
|||||||
return self.__dict__.values()
|
return self.__dict__.values()
|
||||||
def items(self):
|
def items(self):
|
||||||
return self.__dict__.items()
|
return self.__dict__.items()
|
||||||
|
def iterkeys(self):
|
||||||
|
return self.__dict__.iterkeys()
|
||||||
|
def itervalues(self):
|
||||||
|
return self.__dict__.itervalues()
|
||||||
|
def iteritems(self):
|
||||||
|
return self.__dict__.iteritems()
|
||||||
|
def viewkeys(self):
|
||||||
|
return self.__dict__.viewkeys()
|
||||||
|
def viewvalues(self):
|
||||||
|
return self.__dict__.viewvalues()
|
||||||
|
def viewitems(self):
|
||||||
|
return self.__dict__.viewitems()
|
||||||
|
def fromkeys(self,S,v=None):
|
||||||
|
return self.__dict__.fromkeys(S,v)
|
||||||
|
def setdefault(self, key, default=None):
|
||||||
|
try:
|
||||||
|
return getattr(self,key)
|
||||||
|
except AttributeError:
|
||||||
|
setattr(self,key,default)
|
||||||
|
return default
|
||||||
|
def clear(self):
|
||||||
|
self.__dict__.clear()
|
||||||
def len(self):
|
def len(self):
|
||||||
return len(self.__dict__)
|
return len(self.__dict__)
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
@@ -182,9 +202,8 @@ class Storage(object):
|
|||||||
values = self.getlist(default)
|
values = self.getlist(default)
|
||||||
return values[0] if values else default
|
return values[0] if values else default
|
||||||
|
|
||||||
|
|
||||||
PICKABLE = (str,int,long,float,bool,list,dict,tuple,set)
|
PICKABLE = (str,int,long,float,bool,list,dict,tuple,set)
|
||||||
def PickleableStorage(data):
|
|
||||||
return Storage(dict((k,v) for (k,v) in data.items() if isinstance(v,PICKABLE)))
|
|
||||||
|
|
||||||
class StorageList(Storage):
|
class StorageList(Storage):
|
||||||
"""
|
"""
|
||||||
|
|||||||
Reference in New Issue
Block a user