django_evolution.compat.picklers

Compatibility methods for pickle operations.

Functions

pickle_dumps(obj)

Return a pickled representation of an object.

pickle_loads(pickled_str)

Return the unpickled data from a pickle payload.

Classes

DjangoCompatUnpickler(file, *[, ...])

Unpickler compatible with changes to Django class/module paths.

SortedDict(*args, **kwargs)

Compatibility for unpickling a SortedDict.

class django_evolution.compat.picklers.SortedDict(*args, **kwargs)

Bases: dict

Compatibility for unpickling a SortedDict.

Old signatures may use an old Django SortedDict structure, which does not exist in modern versions. This changes any construction of this data structure into a collections.OrderedDict.

static __new__(cls, *args, **kwargs)

Construct an instance of the class.

Parameters:
  • *args (tuple) – Positional arguments to pass to the constructor.

  • **kwargs (dict) – Keyword arguments to pass to the constructor.

Returns:

The new instance.

Return type:

collections.OrderedDict

class django_evolution.compat.picklers.DjangoCompatUnpickler(file, *, fix_imports=True, encoding='ASCII', errors='strict', buffers=None)

Bases: _Unpickler

Unpickler compatible with changes to Django class/module paths.

This provides compatibility across Django versions for various field types, updating referenced module paths for fields to a standard location so that the fields can be located on all Django versions.

find_class(module, name)

Return the class for a given module and class name.

If looking up a class from django.db.models.fields, the class will instead be looked up from django.db.models, fixing lookups on some Django versions.

Parameters:
  • module (unicode) – The module path.

  • name (unicode) – The class name.

Returns:

The resulting class.

Return type:

type

Raises:

AttributeError – The class could not be found in the module.

django_evolution.compat.picklers.pickle_dumps(obj)

Return a pickled representation of an object.

This will always use Pickle protocol 0, which is the default on Python 2, for compatibility across Python 2 and 3.

Changed in version 3.0: Moved from django_evolution.compat.py23.

Parameters:

obj (object) – The object to dump.

Returns:

The Unicode pickled representation of the object, safe for storing in the database.

Return type:

unicode

django_evolution.compat.picklers.pickle_loads(pickled_str)

Return the unpickled data from a pickle payload.

Changed in version 3.0: Moved from django_evolution.compat.py23.

Parameters:

pickled_str (bytes) – The pickled data.

Returns:

The unpickled data.

Return type:

object