<spanid="evennia-utils-dbserialize"></span><h1>evennia.utils.dbserialize<aclass="headerlink"href="#module-evennia.utils.dbserialize"title="Permalink to this headline">¶</a></h1>
<p>This module handles serialization of arbitrary python structural data,
intended primarily to be stored in the database. It also supports
storing Django model instances (which plain pickle cannot do).</p>
<p>This serialization is used internally by the server, notably for
storing data in Attributes and for piping data to process pools.</p>
<p>The purpose of dbserialize is to handle all forms of data. For
well-structured non-arbitrary exchange, such as communicating with a
rich web client, a simpler JSON serialization makes more sense.</p>
<p>This module also implements the <strong>SaverList</strong>, <strong>SaverDict</strong> and <strong>SaverSet</strong>
classes. These are iterables that track their position in a nested
structure and makes sure to send updates up to their root. This is
used by Attributes - without it, one would not be able to update mutables
in-situ, e.g <strong>obj.db.mynestedlist[3][5] = 3</strong> would never be saved and
be out of sync with the database.</p>
<dlclass="py function">
<dtid="evennia.utils.dbserialize.to_pickle">
<codeclass="sig-prename descclassname">evennia.utils.dbserialize.</code><codeclass="sig-name descname">to_pickle</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">data</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/utils/dbserialize.html#to_pickle"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.utils.dbserialize.to_pickle"title="Permalink to this definition">¶</a></dt>
<dd><p>This prepares data on arbitrary form to be pickled. It handles any
nested structure and returns data on a form that is safe to pickle
(including having converted any database models to their internal
representation). We also convert any Saver*-type objects back to
their normal representations, they are not pickle-safe.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><p><strong>data</strong> (<em>any</em>) – Data to pickle.</p>
<codeclass="sig-prename descclassname">evennia.utils.dbserialize.</code><codeclass="sig-name descname">from_pickle</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">data</span></em>, <emclass="sig-param"><spanclass="n">db_obj</span><spanclass="o">=</span><spanclass="default_value">None</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/utils/dbserialize.html#from_pickle"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.utils.dbserialize.from_pickle"title="Permalink to this definition">¶</a></dt>
<dd><p>This should be fed a just de-pickled data object. It will be converted back
to a form that may contain database objects again. Note that if a database
object was removed (or changed in-place) in the database, None will be
returned.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><ulclass="simple">
<li><p><strong>data</strong> (<em>any</em>) – Pickled data to unpickle.</p></li>
<li><p><strong>db_obj</strong> (<em>Atribute</em><em>, </em><em>any</em>) – This is the model instance (normally
an Attribute) that _Saver*-type iterables (_SaverList etc)
will save to when they update. It must have a ‘value’ property
that saves assigned data to the database. Skip if not
serializing onto a given object. If db_obj is given, this
function will convert lists, dicts and sets to their
_SaverList, _SaverDict and _SaverSet counterparts.</p></li>
<codeclass="sig-prename descclassname">evennia.utils.dbserialize.</code><codeclass="sig-name descname">do_pickle</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">data</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/utils/dbserialize.html#do_pickle"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.utils.dbserialize.do_pickle"title="Permalink to this definition">¶</a></dt>
<dd><p>Perform pickle to string</p>
</dd></dl>
<dlclass="py function">
<dtid="evennia.utils.dbserialize.do_unpickle">
<codeclass="sig-prename descclassname">evennia.utils.dbserialize.</code><codeclass="sig-name descname">do_unpickle</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">data</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/utils/dbserialize.html#do_unpickle"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.utils.dbserialize.do_unpickle"title="Permalink to this definition">¶</a></dt>
<dd><p>Retrieve pickle from pickled string</p>
</dd></dl>
<dlclass="py function">
<dtid="evennia.utils.dbserialize.dbserialize">
<codeclass="sig-prename descclassname">evennia.utils.dbserialize.</code><codeclass="sig-name descname">dbserialize</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">data</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/utils/dbserialize.html#dbserialize"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.utils.dbserialize.dbserialize"title="Permalink to this definition">¶</a></dt>
<dd><p>Serialize to pickled form in one step</p>
</dd></dl>
<dlclass="py function">
<dtid="evennia.utils.dbserialize.dbunserialize">
<codeclass="sig-prename descclassname">evennia.utils.dbserialize.</code><codeclass="sig-name descname">dbunserialize</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">data</span></em>, <emclass="sig-param"><spanclass="n">db_obj</span><spanclass="o">=</span><spanclass="default_value">None</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/utils/dbserialize.html#dbunserialize"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.utils.dbserialize.dbunserialize"title="Permalink to this definition">¶</a></dt>
<dd><p>Un-serialize in one step. See from_pickle for help db_obj.</p>