django.utils.safestring.SafeBytes - Unused since Django 2.0.
This commit is contained in:
parent
5d594f25be
commit
ad8b1d81d5
1 changed files with 16 additions and 10 deletions
|
|
@ -28,11 +28,12 @@ except ImportError:
|
||||||
from pickle import dumps, loads
|
from pickle import dumps, loads
|
||||||
from django.core.exceptions import ObjectDoesNotExist
|
from django.core.exceptions import ObjectDoesNotExist
|
||||||
from django.contrib.contenttypes.models import ContentType
|
from django.contrib.contenttypes.models import ContentType
|
||||||
from django.utils.safestring import SafeString, SafeBytes
|
from django.utils.safestring import SafeString
|
||||||
from evennia.utils.utils import uses_database, is_iter, to_str, to_bytes
|
from evennia.utils.utils import uses_database, is_iter, to_str, to_bytes
|
||||||
from evennia.utils import logger
|
from evennia.utils import logger
|
||||||
|
|
||||||
__all__ = ("to_pickle", "from_pickle", "do_pickle", "do_unpickle", "dbserialize", "dbunserialize")
|
__all__ = ("to_pickle", "from_pickle", "do_pickle",
|
||||||
|
"do_unpickle", "dbserialize", "dbunserialize")
|
||||||
|
|
||||||
PICKLE_PROTOCOL = 2
|
PICKLE_PROTOCOL = 2
|
||||||
|
|
||||||
|
|
@ -116,13 +117,15 @@ def _init_globals():
|
||||||
global _FROM_MODEL_MAP, _TO_MODEL_MAP, _SESSION_HANDLER, _IGNORE_DATETIME_MODELS
|
global _FROM_MODEL_MAP, _TO_MODEL_MAP, _SESSION_HANDLER, _IGNORE_DATETIME_MODELS
|
||||||
if not _FROM_MODEL_MAP:
|
if not _FROM_MODEL_MAP:
|
||||||
_FROM_MODEL_MAP = defaultdict(str)
|
_FROM_MODEL_MAP = defaultdict(str)
|
||||||
_FROM_MODEL_MAP.update(dict((c.model, c.natural_key()) for c in ContentType.objects.all()))
|
_FROM_MODEL_MAP.update(dict((c.model, c.natural_key())
|
||||||
|
for c in ContentType.objects.all()))
|
||||||
if not _TO_MODEL_MAP:
|
if not _TO_MODEL_MAP:
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
|
||||||
_TO_MODEL_MAP = defaultdict(str)
|
_TO_MODEL_MAP = defaultdict(str)
|
||||||
_TO_MODEL_MAP.update(
|
_TO_MODEL_MAP.update(
|
||||||
dict((c.natural_key(), c.model_class()) for c in ContentType.objects.all())
|
dict((c.natural_key(), c.model_class())
|
||||||
|
for c in ContentType.objects.all())
|
||||||
)
|
)
|
||||||
_IGNORE_DATETIME_MODELS = []
|
_IGNORE_DATETIME_MODELS = []
|
||||||
for src_key, dst_key in settings.ATTRIBUTE_STORED_MODEL_RENAME:
|
for src_key, dst_key in settings.ATTRIBUTE_STORED_MODEL_RENAME:
|
||||||
|
|
@ -185,7 +188,8 @@ class _SaverMutable(object):
|
||||||
)
|
)
|
||||||
self._db_obj.value = self
|
self._db_obj.value = self
|
||||||
else:
|
else:
|
||||||
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"""
|
||||||
|
|
@ -201,7 +205,8 @@ class _SaverMutable(object):
|
||||||
return dat
|
return dat
|
||||||
elif dtype == dict:
|
elif dtype == dict:
|
||||||
dat = _SaverDict(_parent=parent)
|
dat = _SaverDict(_parent=parent)
|
||||||
dat._data.update((key, process_tree(val, dat)) for key, val in item.items())
|
dat._data.update((key, process_tree(val, dat))
|
||||||
|
for key, val in item.items())
|
||||||
return dat
|
return dat
|
||||||
elif dtype == set:
|
elif dtype == set:
|
||||||
dat = _SaverSet(_parent=parent)
|
dat = _SaverSet(_parent=parent)
|
||||||
|
|
@ -549,7 +554,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 (str, int, float, bool, bytes, SafeString, SafeBytes):
|
if dtype in (str, int, float, bool, bytes, SafeString):
|
||||||
return item
|
return item
|
||||||
elif dtype == tuple:
|
elif dtype == tuple:
|
||||||
return tuple(process_item(val) for val in item)
|
return tuple(process_item(val) for val in item)
|
||||||
|
|
@ -577,7 +582,8 @@ def to_pickle(data):
|
||||||
except TypeError:
|
except TypeError:
|
||||||
return item
|
return item
|
||||||
except Exception:
|
except Exception:
|
||||||
logger.log_error(f"The object {item} of type {type(item)} could not be stored.")
|
logger.log_error(
|
||||||
|
f"The object {item} of type {type(item)} could not be stored.")
|
||||||
raise
|
raise
|
||||||
|
|
||||||
return process_item(data)
|
return process_item(data)
|
||||||
|
|
@ -609,7 +615,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 (str, int, float, bool, bytes, SafeString, SafeBytes):
|
if dtype in (str, int, float, bool, bytes, SafeString):
|
||||||
return item
|
return item
|
||||||
elif _IS_PACKED_DBOBJ(item):
|
elif _IS_PACKED_DBOBJ(item):
|
||||||
# this must be checked before tuple
|
# this must be checked before tuple
|
||||||
|
|
@ -638,7 +644,7 @@ def from_pickle(data, db_obj=None):
|
||||||
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 (str, int, float, bool, bytes, SafeString, SafeBytes):
|
if dtype in (str, int, float, bool, bytes, SafeString):
|
||||||
return item
|
return item
|
||||||
elif _IS_PACKED_DBOBJ(item):
|
elif _IS_PACKED_DBOBJ(item):
|
||||||
# this must be checked before tuple
|
# this must be checked before tuple
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue