PEP 8 comply
This commit is contained in:
parent
4d8c5964a4
commit
c27c96f423
1 changed files with 29 additions and 26 deletions
|
|
@ -37,6 +37,7 @@ __all__ = ("to_pickle", "from_pickle", "do_pickle", "do_unpickle",
|
||||||
|
|
||||||
PICKLE_PROTOCOL = 2
|
PICKLE_PROTOCOL = 2
|
||||||
|
|
||||||
|
|
||||||
def _get_mysql_db_version():
|
def _get_mysql_db_version():
|
||||||
"""
|
"""
|
||||||
This is a helper method for specifically getting the version
|
This is a helper method for specifically getting the version
|
||||||
|
|
@ -93,7 +94,7 @@ def _TO_DATESTRING(obj):
|
||||||
|
|
||||||
|
|
||||||
def _init_globals():
|
def _init_globals():
|
||||||
"Lazy importing to avoid circular import issues"
|
"""Lazy importing to avoid circular import issues"""
|
||||||
global _FROM_MODEL_MAP, _TO_MODEL_MAP, _SESSION_HANDLER
|
global _FROM_MODEL_MAP, _TO_MODEL_MAP, _SESSION_HANDLER
|
||||||
if not _FROM_MODEL_MAP:
|
if not _FROM_MODEL_MAP:
|
||||||
_FROM_MODEL_MAP = defaultdict(str)
|
_FROM_MODEL_MAP = defaultdict(str)
|
||||||
|
|
@ -110,7 +111,7 @@ def _init_globals():
|
||||||
|
|
||||||
|
|
||||||
def _save(method):
|
def _save(method):
|
||||||
"method decorator that saves data to Attribute"
|
"""method decorator that saves data to Attribute"""
|
||||||
def save_wrapper(self, *args, **kwargs):
|
def save_wrapper(self, *args, **kwargs):
|
||||||
self.__doc__ = method.__doc__
|
self.__doc__ = method.__doc__
|
||||||
ret = method(self, *args, **kwargs)
|
ret = method(self, *args, **kwargs)
|
||||||
|
|
@ -127,17 +128,17 @@ class _SaverMutable(object):
|
||||||
will not save the updated value to the database.
|
will not save the updated value to the database.
|
||||||
"""
|
"""
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
"store all properties for tracking the tree"
|
"""store all properties for tracking the tree"""
|
||||||
self._parent = kwargs.pop("_parent", None)
|
self._parent = kwargs.pop("_parent", None)
|
||||||
self._db_obj = kwargs.pop("_db_obj", None)
|
self._db_obj = kwargs.pop("_db_obj", None)
|
||||||
self._data = None
|
self._data = None
|
||||||
|
|
||||||
def __nonzero__(self):
|
def __nonzero__(self):
|
||||||
"Make sure to evaluate as False if empty"
|
"""Make sure to evaluate as False if empty"""
|
||||||
return bool(self._data)
|
return bool(self._data)
|
||||||
|
|
||||||
def _save_tree(self):
|
def _save_tree(self):
|
||||||
"recursively traverse back up the tree, save when we reach the root"
|
"""recursively traverse back up the tree, save when we reach the root"""
|
||||||
if self._parent:
|
if self._parent:
|
||||||
self._parent._save_tree()
|
self._parent._save_tree()
|
||||||
elif self._db_obj:
|
elif self._db_obj:
|
||||||
|
|
@ -146,9 +147,9 @@ class _SaverMutable(object):
|
||||||
logger.log_err("_SaverMutable %s has no root Attribute to save to." % self)
|
logger.log_err("_SaverMutable %s has no root Attribute to save to." % self)
|
||||||
|
|
||||||
def _convert_mutables(self, data):
|
def _convert_mutables(self, data):
|
||||||
"converts mutables to Saver* variants and assigns ._parent property"
|
"""converts mutables to Saver* variants and assigns ._parent property"""
|
||||||
def process_tree(item, parent):
|
def process_tree(item, parent):
|
||||||
"recursively populate the tree, storing parents"
|
"""recursively populate the tree, storing parents"""
|
||||||
dtype = type(item)
|
dtype = type(item)
|
||||||
if dtype in (basestring, int, float, bool, tuple):
|
if dtype in (basestring, int, float, bool, tuple):
|
||||||
return item
|
return item
|
||||||
|
|
@ -218,7 +219,6 @@ class _SaverList(_SaverMutable, MutableSequence):
|
||||||
return self._data.index(value, *args)
|
return self._data.index(value, *args)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class _SaverDict(_SaverMutable, MutableMapping):
|
class _SaverDict(_SaverMutable, MutableMapping):
|
||||||
"""
|
"""
|
||||||
A dict that stores changes to an Attribute when updated
|
A dict that stores changes to an Attribute when updated
|
||||||
|
|
@ -290,8 +290,10 @@ class _SaverDeque(_SaverMutable):
|
||||||
# maxlen property
|
# maxlen property
|
||||||
def _getmaxlen(self):
|
def _getmaxlen(self):
|
||||||
return self._data.maxlen
|
return self._data.maxlen
|
||||||
|
|
||||||
def _setmaxlen(self, value):
|
def _setmaxlen(self, value):
|
||||||
self._data.maxlen = value
|
self._data.maxlen = value
|
||||||
|
|
||||||
def _delmaxlen(self):
|
def _delmaxlen(self):
|
||||||
del self._data.maxlen
|
del self._data.maxlen
|
||||||
maxlen = property(_getmaxlen, _setmaxlen, _delmaxlen)
|
maxlen = property(_getmaxlen, _setmaxlen, _delmaxlen)
|
||||||
|
|
@ -314,7 +316,7 @@ class _SaverDeque(_SaverMutable):
|
||||||
|
|
||||||
#
|
#
|
||||||
# serialization helpers
|
# serialization helpers
|
||||||
#
|
|
||||||
|
|
||||||
def pack_dbobj(item):
|
def pack_dbobj(item):
|
||||||
"""
|
"""
|
||||||
|
|
@ -395,6 +397,7 @@ def pack_session(item):
|
||||||
_GA(item, "conn_time"))
|
_GA(item, "conn_time"))
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def unpack_session(item):
|
def unpack_session(item):
|
||||||
"""
|
"""
|
||||||
Check and convert internal representations back to Sessions.
|
Check and convert internal representations back to Sessions.
|
||||||
|
|
@ -419,7 +422,7 @@ def unpack_session(item):
|
||||||
|
|
||||||
#
|
#
|
||||||
# Access methods
|
# Access methods
|
||||||
#
|
|
||||||
|
|
||||||
def to_pickle(data):
|
def to_pickle(data):
|
||||||
"""
|
"""
|
||||||
|
|
@ -437,7 +440,7 @@ def to_pickle(data):
|
||||||
|
|
||||||
"""
|
"""
|
||||||
def process_item(item):
|
def process_item(item):
|
||||||
"Recursive processor and identification of data"
|
"""Recursive processor and identification of data"""
|
||||||
dtype = type(item)
|
dtype = type(item)
|
||||||
if dtype in (basestring, int, float, bool):
|
if dtype in (basestring, int, float, bool):
|
||||||
return item
|
return item
|
||||||
|
|
@ -466,7 +469,7 @@ def to_pickle(data):
|
||||||
return process_item(data)
|
return process_item(data)
|
||||||
|
|
||||||
|
|
||||||
#@transaction.autocommit
|
# @transaction.autocommit
|
||||||
def from_pickle(data, db_obj=None):
|
def from_pickle(data, db_obj=None):
|
||||||
"""
|
"""
|
||||||
This should be fed a just de-pickled data object. It will be converted back
|
This should be fed a just de-pickled data object. It will be converted back
|
||||||
|
|
@ -489,7 +492,7 @@ def from_pickle(data, db_obj=None):
|
||||||
|
|
||||||
"""
|
"""
|
||||||
def process_item(item):
|
def process_item(item):
|
||||||
"Recursive processor and identification of data"
|
"""Recursive processor and identification of data"""
|
||||||
dtype = type(item)
|
dtype = type(item)
|
||||||
if dtype in (basestring, int, float, bool):
|
if dtype in (basestring, int, float, bool):
|
||||||
return item
|
return item
|
||||||
|
|
@ -518,7 +521,7 @@ def from_pickle(data, db_obj=None):
|
||||||
return item
|
return item
|
||||||
|
|
||||||
def process_tree(item, parent):
|
def process_tree(item, parent):
|
||||||
"Recursive processor, building a parent-tree from iterable data"
|
"""Recursive processor, building a parent-tree from iterable data"""
|
||||||
dtype = type(item)
|
dtype = type(item)
|
||||||
if dtype in (basestring, int, float, bool):
|
if dtype in (basestring, int, float, bool):
|
||||||
return item
|
return item
|
||||||
|
|
@ -590,20 +593,20 @@ def from_pickle(data, db_obj=None):
|
||||||
|
|
||||||
|
|
||||||
def do_pickle(data):
|
def do_pickle(data):
|
||||||
"Perform pickle to string"
|
"""Perform pickle to string"""
|
||||||
return to_str(dumps(data, protocol=PICKLE_PROTOCOL))
|
return to_str(dumps(data, protocol=PICKLE_PROTOCOL))
|
||||||
|
|
||||||
|
|
||||||
def do_unpickle(data):
|
def do_unpickle(data):
|
||||||
"Retrieve pickle from pickled string"
|
"""Retrieve pickle from pickled string"""
|
||||||
return loads(to_str(data))
|
return loads(to_str(data))
|
||||||
|
|
||||||
|
|
||||||
def dbserialize(data):
|
def dbserialize(data):
|
||||||
"Serialize to pickled form in one step"
|
"""Serialize to pickled form in one step"""
|
||||||
return do_pickle(to_pickle(data))
|
return do_pickle(to_pickle(data))
|
||||||
|
|
||||||
|
|
||||||
def dbunserialize(data, db_obj=None):
|
def dbunserialize(data, db_obj=None):
|
||||||
"Un-serialize in one step. See from_pickle for help db_obj."
|
"""Un-serialize in one step. See from_pickle for help db_obj."""
|
||||||
return from_pickle(do_unpickle(data), db_obj=db_obj)
|
return from_pickle(do_unpickle(data), db_obj=db_obj)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue