<spanid="evennia-utils-utils"></span><h1>evennia.utils.utils<aclass="headerlink"href="#module-evennia.utils.utils"title="Permalink to this headline">¶</a></h1>
<p>General helper functions that don’t fit neatly under any given category.</p>
<p>They provide some useful string and conversion methods that might
be of use when designing your own game.</p>
<dlclass="py function">
<dtid="evennia.utils.utils.is_iter">
<codeclass="sig-prename descclassname">evennia.utils.utils.</code><codeclass="sig-name descname">is_iter</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">obj</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/utils/utils.html#is_iter"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.utils.utils.is_iter"title="Permalink to this definition">¶</a></dt>
<dd><p>Checks if an object behaves iterably.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><p><strong>obj</strong> (<em>any</em>) – Entity to check for iterability.</p>
</dd>
<dtclass="field-even">Returns</dt>
<ddclass="field-even"><p><em>is_iterable (bool)</em>– If <strong>obj</strong> is iterable or not.</p>
</dd>
</dl>
<pclass="rubric">Notes</p>
<p>Strings are <em>not</em> accepted as iterable (although they are
actually iterable), since string iterations are usually not
what we want to do with a string.</p>
</dd></dl>
<dlclass="py function">
<dtid="evennia.utils.utils.make_iter">
<codeclass="sig-prename descclassname">evennia.utils.utils.</code><codeclass="sig-name descname">make_iter</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">obj</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/utils/utils.html#make_iter"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.utils.utils.make_iter"title="Permalink to this definition">¶</a></dt>
<dd><p>Makes sure that the object is always iterable.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><p><strong>obj</strong> (<em>any</em>) – Object to make iterable.</p>
</dd>
<dtclass="field-even">Returns</dt>
<ddclass="field-even"><p><p><em>iterable (list or iterable)</em>–</p>
<dlclass="simple">
<dt>The same object</dt><dd><p>passed-through or made iterable.</p>
</dd>
</dl>
</p>
</dd>
</dl>
</dd></dl>
<dlclass="py function">
<dtid="evennia.utils.utils.wrap">
<codeclass="sig-prename descclassname">evennia.utils.utils.</code><codeclass="sig-name descname">wrap</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">text</span></em>, <emclass="sig-param"><spanclass="n">width</span><spanclass="o">=</span><spanclass="default_value">None</span></em>, <emclass="sig-param"><spanclass="n">indent</span><spanclass="o">=</span><spanclass="default_value">0</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/utils/utils.html#wrap"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.utils.utils.wrap"title="Permalink to this definition">¶</a></dt>
<dd><p>Safely wrap text to a certain number of characters.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><ulclass="simple">
<li><p><strong>text</strong> (<em>str</em>) – The text to wrap.</p></li>
<li><p><strong>width</strong> (<em>int</em><em>, </em><em>optional</em>) – The number of characters to wrap to.</p></li>
<li><p><strong>indent</strong> (<em>int</em>) – How much to indent each line (with whitespace).</p></li>
<codeclass="sig-prename descclassname">evennia.utils.utils.</code><codeclass="sig-name descname">fill</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">text</span></em>, <emclass="sig-param"><spanclass="n">width</span><spanclass="o">=</span><spanclass="default_value">None</span></em>, <emclass="sig-param"><spanclass="n">indent</span><spanclass="o">=</span><spanclass="default_value">0</span></em><spanclass="sig-paren">)</span><aclass="headerlink"href="#evennia.utils.utils.fill"title="Permalink to this definition">¶</a></dt>
<dd><p>Safely wrap text to a certain number of characters.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><ulclass="simple">
<li><p><strong>text</strong> (<em>str</em>) – The text to wrap.</p></li>
<li><p><strong>width</strong> (<em>int</em><em>, </em><em>optional</em>) – The number of characters to wrap to.</p></li>
<li><p><strong>indent</strong> (<em>int</em>) – How much to indent each line (with whitespace).</p></li>
<codeclass="sig-prename descclassname">evennia.utils.utils.</code><codeclass="sig-name descname">pad</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">text</span></em>, <emclass="sig-param"><spanclass="n">width</span><spanclass="o">=</span><spanclass="default_value">None</span></em>, <emclass="sig-param"><spanclass="n">align</span><spanclass="o">=</span><spanclass="default_value">'c'</span></em>, <emclass="sig-param"><spanclass="n">fillchar</span><spanclass="o">=</span><spanclass="default_value">' '</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/utils/utils.html#pad"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.utils.utils.pad"title="Permalink to this definition">¶</a></dt>
<dd><p>Pads to a given width.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><ulclass="simple">
<li><p><strong>text</strong> (<em>str</em>) – Text to pad.</p></li>
<li><p><strong>width</strong> (<em>int</em><em>, </em><em>optional</em>) – The width to pad to, in characters.</p></li>
<li><p><strong>align</strong> (<em>str</em><em>, </em><em>optional</em>) – This is one of ‘c’, ‘l’ or ‘r’ (center,
left or right).</p></li>
<li><p><strong>fillchar</strong> (<em>str</em><em>, </em><em>optional</em>) – The character to fill with.</p></li>
</ul>
</dd>
<dtclass="field-even">Returns</dt>
<ddclass="field-even"><p><em>text (str)</em>– The padded text.</p>
</dd>
</dl>
</dd></dl>
<dlclass="py function">
<dtid="evennia.utils.utils.crop">
<codeclass="sig-prename descclassname">evennia.utils.utils.</code><codeclass="sig-name descname">crop</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">text</span></em>, <emclass="sig-param"><spanclass="n">width</span><spanclass="o">=</span><spanclass="default_value">None</span></em>, <emclass="sig-param"><spanclass="n">suffix</span><spanclass="o">=</span><spanclass="default_value">'[...]'</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/utils/utils.html#crop"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.utils.utils.crop"title="Permalink to this definition">¶</a></dt>
<dd><p>Crop text to a certain width, throwing away text from too-long
lines.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><ulclass="simple">
<li><p><strong>text</strong> (<em>str</em>) – Text to crop.</p></li>
<li><p><strong>width</strong> (<em>int</em><em>, </em><em>optional</em>) – Width of line to crop, in characters.</p></li>
<li><p><strong>suffix</strong> (<em>str</em><em>, </em><em>optional</em>) – This is appended to the end of cropped
lines to show that the line actually continues. Cropping
will be done so that the suffix will also fit within the
given width. If width is too small to fit both crop and
suffix, the suffix will be dropped.</p></li>
</ul>
</dd>
<dtclass="field-even">Returns</dt>
<ddclass="field-even"><p><em>text (str)</em>– The cropped text.</p>
</dd>
</dl>
</dd></dl>
<dlclass="py function">
<dtid="evennia.utils.utils.dedent">
<codeclass="sig-prename descclassname">evennia.utils.utils.</code><codeclass="sig-name descname">dedent</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">text</span></em>, <emclass="sig-param"><spanclass="n">baseline_index</span><spanclass="o">=</span><spanclass="default_value">None</span></em>, <emclass="sig-param"><spanclass="n">indent</span><spanclass="o">=</span><spanclass="default_value">None</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/utils/utils.html#dedent"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.utils.utils.dedent"title="Permalink to this definition">¶</a></dt>
<dd><p>Safely clean all whitespace at the left of a paragraph.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><ulclass="simple">
<li><p><strong>text</strong> (<em>str</em>) – The text to dedent.</p></li>
<li><p><strong>baseline_index</strong> (<em>int</em><em>, </em><em>optional</em>) – Which row to use as a ‘base’
for the indentation. Lines will be dedented to this level but
no further. If None, indent so as to completely deindent the
least indented text.</p></li>
<li><p><strong>indent</strong> (<em>int</em><em>, </em><em>optional</em>) – If given, force all lines to this indent.
This bypasses <strong>baseline_index</strong>.</p></li>
<spanclass="go">'"1", "2", and "3"'</span>
</pre></div>
</div>
</dd></dl>
<dlclass="py function">
<dtid="evennia.utils.utils.list_to_string">
<codeclass="sig-prename descclassname">evennia.utils.utils.</code><codeclass="sig-name descname">list_to_string</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">iterable</span></em>, <emclass="sig-param"><spanclass="n">sep</span><spanclass="o">=</span><spanclass="default_value">','</span></em>, <emclass="sig-param"><spanclass="n">endsep</span><spanclass="o">=</span><spanclass="default_value">', and'</span></em>, <emclass="sig-param"><spanclass="n">addquote</span><spanclass="o">=</span><spanclass="default_value">False</span></em><spanclass="sig-paren">)</span><aclass="headerlink"href="#evennia.utils.utils.list_to_string"title="Permalink to this definition">¶</a></dt>
<dd><p>This pretty-formats an iterable list as string output, adding an optional
alternative separator to the second to last entry. If <strong>addquote</strong>
is <strong>True</strong>, the outgoing strings will be surrounded by quotes.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><ulclass="simple">
<li><p><strong>iterable</strong> (<em>any</em>) – Usually an iterable to print. Each element must be possible to
present with a string. Note that if this is a generator, it will be
consumed by this operation.</p></li>
<li><p><strong>sep</strong> (<em>str</em><em>, </em><em>optional</em>) – The string to use as a separator for each item in the iterable.</p></li>
<li><p><strong>endsep</strong> (<em>str</em><em>, </em><em>optional</em>) – The last item separator will be replaced with this value.</p></li>
<li><p><strong>addquote</strong> (<em>bool</em><em>, </em><em>optional</em>) – This will surround all outgoing
values with double quotes.</p></li>
</ul>
</dd>
<dtclass="field-even">Returns</dt>
<ddclass="field-even"><p><em>str</em>– The list represented as a string.</p>
</dd>
</dl>
<pclass="rubric">Notes</p>
<p>Default is to use ‘Oxford comma’, like 1, 2, 3, and 4.</p>
<spanclass="go">'"1", "2", and "3"'</span>
</pre></div>
</div>
</dd></dl>
<dlclass="py function">
<dtid="evennia.utils.utils.iter_to_string">
<codeclass="sig-prename descclassname">evennia.utils.utils.</code><codeclass="sig-name descname">iter_to_string</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">iterable</span></em>, <emclass="sig-param"><spanclass="n">sep</span><spanclass="o">=</span><spanclass="default_value">','</span></em>, <emclass="sig-param"><spanclass="n">endsep</span><spanclass="o">=</span><spanclass="default_value">', and'</span></em>, <emclass="sig-param"><spanclass="n">addquote</span><spanclass="o">=</span><spanclass="default_value">False</span></em><spanclass="sig-paren">)</span><aclass="headerlink"href="#evennia.utils.utils.iter_to_string"title="Permalink to this definition">¶</a></dt>
<dd><p>This pretty-formats an iterable list as string output, adding an optional
alternative separator to the second to last entry. If <strong>addquote</strong>
is <strong>True</strong>, the outgoing strings will be surrounded by quotes.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><ulclass="simple">
<li><p><strong>iterable</strong> (<em>any</em>) – Usually an iterable to print. Each element must be possible to
present with a string. Note that if this is a generator, it will be
consumed by this operation.</p></li>
<li><p><strong>sep</strong> (<em>str</em><em>, </em><em>optional</em>) – The string to use as a separator for each item in the iterable.</p></li>
<li><p><strong>endsep</strong> (<em>str</em><em>, </em><em>optional</em>) – The last item separator will be replaced with this value.</p></li>
<li><p><strong>addquote</strong> (<em>bool</em><em>, </em><em>optional</em>) – This will surround all outgoing
values with double quotes.</p></li>
</ul>
</dd>
<dtclass="field-even">Returns</dt>
<ddclass="field-even"><p><em>str</em>– The list represented as a string.</p>
</dd>
</dl>
<pclass="rubric">Notes</p>
<p>Default is to use ‘Oxford comma’, like 1, 2, 3, and 4.</p>
<spanclass="go">'"1", "2", and "3"'</span>
</pre></div>
</div>
</dd></dl>
<dlclass="py function">
<dtid="evennia.utils.utils.wildcard_to_regexp">
<codeclass="sig-prename descclassname">evennia.utils.utils.</code><codeclass="sig-name descname">wildcard_to_regexp</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">instring</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/utils/utils.html#wildcard_to_regexp"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.utils.utils.wildcard_to_regexp"title="Permalink to this definition">¶</a></dt>
<dd><p>Converts a player-supplied string that may have wildcards in it to
regular expressions. This is useful for name matching.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><p><strong>instring</strong> (<em>string</em>) – A string that may potentially contain
wildcards (<strong>*</strong> or <strong>?</strong>).</p>
<dt>A string where wildcards were replaced with</dt><dd><p>regular expressions.</p>
</dd>
</dl>
</p>
</dd>
</dl>
</dd></dl>
<dlclass="py function">
<dtid="evennia.utils.utils.time_format">
<codeclass="sig-prename descclassname">evennia.utils.utils.</code><codeclass="sig-name descname">time_format</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">seconds</span></em>, <emclass="sig-param"><spanclass="n">style</span><spanclass="o">=</span><spanclass="default_value">0</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/utils/utils.html#time_format"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.utils.utils.time_format"title="Permalink to this definition">¶</a></dt>
<dd><p>Function to return a ‘prettified’ version of a value in seconds.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><ulclass="simple">
<li><p><strong>seconds</strong> (<em>int</em>) – Number if seconds to format.</p></li>
<li><p><strong>style</strong> (<em>int</em>) – One of the following styles:
0. “1d 08:30”
1. “1d”
2. “1 day, 8 hours, 30 minutes”
3. “1 day, 8 hours, 30 minutes, 10 seconds”
4. highest unit (like “3 years” or “8 months” or “1 second”)</p></li>
</ul>
</dd>
<dtclass="field-even">Returns</dt>
<ddclass="field-even"><p><em>timeformatted (str)</em>– A pretty time string.</p>
</dd>
</dl>
</dd></dl>
<dlclass="py function">
<dtid="evennia.utils.utils.datetime_format">
<codeclass="sig-prename descclassname">evennia.utils.utils.</code><codeclass="sig-name descname">datetime_format</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">dtobj</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/utils/utils.html#datetime_format"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.utils.utils.datetime_format"title="Permalink to this definition">¶</a></dt>
<dd><p>Pretty-prints the time since a given time.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><p><strong>dtobj</strong> (<em>datetime</em>) – An datetime object, e.g. from Django’s
<dt>A string describing how long ago <strong>dtobj</strong></dt><dd><p>took place.</p>
</dd>
</dl>
</p>
</dd>
</dl>
</dd></dl>
<dlclass="py function">
<dtid="evennia.utils.utils.host_os_is">
<codeclass="sig-prename descclassname">evennia.utils.utils.</code><codeclass="sig-name descname">host_os_is</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">osname</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/utils/utils.html#host_os_is"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.utils.utils.host_os_is"title="Permalink to this definition">¶</a></dt>
<dd><p>Check to see if the host OS matches the query.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><ulclass="simple">
<li><p><strong>osname</strong> (<em>str</em>) – Common names are “posix” (linux/unix/mac) and
“nt” (windows).</p></li>
<li><p><strong>is_os</strong> (<em>bool</em>) – If the os matches or not.</p></li>
</ul>
</dd>
</dl>
</dd></dl>
<dlclass="py function">
<dtid="evennia.utils.utils.get_evennia_version">
<codeclass="sig-prename descclassname">evennia.utils.utils.</code><codeclass="sig-name descname">get_evennia_version</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">mode</span><spanclass="o">=</span><spanclass="default_value">'long'</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/utils/utils.html#get_evennia_version"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.utils.utils.get_evennia_version"title="Permalink to this definition">¶</a></dt>
<dd><p>Helper method for getting the current evennia version.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><p><strong>mode</strong> (<em>str</em><em>, </em><em>optional</em>) – One of:
- long: 0.9.0 rev342453534
- short: 0.9.0
- pretty: Evennia 0.9.0</p>
</dd>
<dtclass="field-even">Returns</dt>
<ddclass="field-even"><p><em>version (str)</em>– The version string.</p>
</dd>
</dl>
</dd></dl>
<dlclass="py function">
<dtid="evennia.utils.utils.pypath_to_realpath">
<codeclass="sig-prename descclassname">evennia.utils.utils.</code><codeclass="sig-name descname">pypath_to_realpath</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">python_path</span></em>, <emclass="sig-param"><spanclass="n">file_ending</span><spanclass="o">=</span><spanclass="default_value">'.py'</span></em>, <emclass="sig-param"><spanclass="n">pypath_prefixes</span><spanclass="o">=</span><spanclass="default_value">None</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/utils/utils.html#pypath_to_realpath"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.utils.utils.pypath_to_realpath"title="Permalink to this definition">¶</a></dt>
<dd><p>Converts a dotted Python path to an absolute path under the
Evennia library directory or under the current game directory.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><ulclass="simple">
<li><p><strong>python_path</strong> (<em>str</em>) – A dot-python path</p></li>
<li><p><strong>file_ending</strong> (<em>str</em>) – A file ending, including the period.</p></li>
<li><p><strong>pypath_prefixes</strong> (<em>list</em>) – A list of paths to test for existence. These
should be on python.path form. EVENNIA_DIR and GAME_DIR are automatically
checked, they need not be added to this list.</p></li>
<dt>All existing, absolute paths created by</dt><dd><p>converting <strong>python_path</strong> to an absolute paths and/or
prepending <strong>python_path</strong> by <strong>settings.EVENNIA_DIR</strong>,
<strong>settings.GAME_DIR</strong> and by**pypath_prefixes** respectively.</p>
</dd>
</dl>
</p>
</dd>
</dl>
<pclass="rubric">Notes</p>
<p>This will also try a few combinations of paths to allow cases
where pypath is given including the “evennia.” or “mygame.”
prefixes.</p>
</dd></dl>
<dlclass="py function">
<dtid="evennia.utils.utils.dbref">
<codeclass="sig-prename descclassname">evennia.utils.utils.</code><codeclass="sig-name descname">dbref</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">inp</span></em>, <emclass="sig-param"><spanclass="n">reqhash</span><spanclass="o">=</span><spanclass="default_value">True</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/utils/utils.html#dbref"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.utils.utils.dbref"title="Permalink to this definition">¶</a></dt>
<dd><p>Converts/checks if input is a valid dbref.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><ulclass="simple">
<li><p><strong>inp</strong> (<em>int</em><em>, </em><em>str</em>) – A database ref on the form N or #N.</p></li>
<li><p><strong>reqhash</strong> (<em>bool</em><em>, </em><em>optional</em>) – Require the #N form to accept
input as a valid dbref.</p></li>
</ul>
</dd>
<dtclass="field-even">Returns</dt>
<ddclass="field-even"><p><p><em>dbref (int or None)</em>–</p>
<dlclass="simple">
<dt>The integer part of the dbref or <strong>None</strong></dt><dd><p>if input was not a valid dbref.</p>
</dd>
</dl>
</p>
</dd>
</dl>
</dd></dl>
<dlclass="py function">
<dtid="evennia.utils.utils.dbref_to_obj">
<codeclass="sig-prename descclassname">evennia.utils.utils.</code><codeclass="sig-name descname">dbref_to_obj</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">inp</span></em>, <emclass="sig-param"><spanclass="n">objclass</span></em>, <emclass="sig-param"><spanclass="n">raise_errors</span><spanclass="o">=</span><spanclass="default_value">True</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/utils/utils.html#dbref_to_obj"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.utils.utils.dbref_to_obj"title="Permalink to this definition">¶</a></dt>
<dd><p>Convert a #dbref to a valid object.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><ulclass="simple">
<li><p><strong>inp</strong> (<em>str</em><em> or </em><em>int</em>) – A valid #dbref.</p></li>
<li><p><strong>objclass</strong> (<em>class</em>) – A valid django model to filter against.</p></li>
<li><p><strong>raise_errors</strong> (<em>bool</em><em>, </em><em>optional</em>) – Whether to raise errors
or return <strong>None</strong> on errors.</p></li>
</ul>
</dd>
<dtclass="field-even">Returns</dt>
<ddclass="field-even"><p><em>obj (Object or None)</em>– An entity loaded from the dbref.</p>
</dd>
<dtclass="field-odd">Raises</dt>
<ddclass="field-odd"><p><strong>Exception</strong>– If <strong>raise_errors</strong> is <strong>True</strong> and
<strong>objclass.objects.get(id=dbref)</strong> did not return a valid
object.</p>
</dd>
</dl>
</dd></dl>
<dlclass="py function">
<dtid="evennia.utils.utils.dbid_to_obj">
<codeclass="sig-prename descclassname">evennia.utils.utils.</code><codeclass="sig-name descname">dbid_to_obj</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">inp</span></em>, <emclass="sig-param"><spanclass="n">objclass</span></em>, <emclass="sig-param"><spanclass="n">raise_errors</span><spanclass="o">=</span><spanclass="default_value">True</span></em><spanclass="sig-paren">)</span><aclass="headerlink"href="#evennia.utils.utils.dbid_to_obj"title="Permalink to this definition">¶</a></dt>
<dd><p>Convert a #dbref to a valid object.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><ulclass="simple">
<li><p><strong>inp</strong> (<em>str</em><em> or </em><em>int</em>) – A valid #dbref.</p></li>
<li><p><strong>objclass</strong> (<em>class</em>) – A valid django model to filter against.</p></li>
<li><p><strong>raise_errors</strong> (<em>bool</em><em>, </em><em>optional</em>) – Whether to raise errors
or return <strong>None</strong> on errors.</p></li>
</ul>
</dd>
<dtclass="field-even">Returns</dt>
<ddclass="field-even"><p><em>obj (Object or None)</em>– An entity loaded from the dbref.</p>
</dd>
<dtclass="field-odd">Raises</dt>
<ddclass="field-odd"><p><strong>Exception</strong>– If <strong>raise_errors</strong> is <strong>True</strong> and
<strong>objclass.objects.get(id=dbref)</strong> did not return a valid
object.</p>
</dd>
</dl>
</dd></dl>
<dlclass="py function">
<dtid="evennia.utils.utils.latinify">
<codeclass="sig-prename descclassname">evennia.utils.utils.</code><codeclass="sig-name descname">latinify</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">string</span></em>, <emclass="sig-param"><spanclass="n">default</span><spanclass="o">=</span><spanclass="default_value">'?'</span></em>, <emclass="sig-param"><spanclass="n">pure_ascii</span><spanclass="o">=</span><spanclass="default_value">False</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/utils/utils.html#latinify"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.utils.utils.latinify"title="Permalink to this definition">¶</a></dt>
<dd><p>Convert a unicode string to “safe” ascii/latin-1 characters.
This is used as a last resort when normal encoding does not work.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><ulclass="simple">
<li><p><strong>string</strong> (<em>str</em>) – A string to convert to ‘safe characters’ convertible
to an latin-1 bytestring later.</p></li>
<li><p><strong>default</strong> (<em>str</em><em>, </em><em>optional</em>) – Characters resisting mapping will be replaced
with this character or string. The intent is to apply an encode operation
<dt>A ‘latinified’ string where each unicode character has been</dt><dd><p>replaced with a ‘safe’ equivalent available in the ascii/latin-1 charset.</p>
</dd>
</dl>
</p>
</dd>
</dl>
<pclass="rubric">Notes</p>
<dlclass="simple">
<dt>This is inspired by the gist by Ricardo Murri:</dt><dd><p><aclass="reference external"href="https://gist.github.com/riccardomurri/3c3ccec30f037be174d3">https://gist.github.com/riccardomurri/3c3ccec30f037be174d3</a></p>
</dd>
</dl>
</dd></dl>
<dlclass="py function">
<dtid="evennia.utils.utils.to_bytes">
<codeclass="sig-prename descclassname">evennia.utils.utils.</code><codeclass="sig-name descname">to_bytes</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">text</span></em>, <emclass="sig-param"><spanclass="n">session</span><spanclass="o">=</span><spanclass="default_value">None</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/utils/utils.html#to_bytes"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.utils.utils.to_bytes"title="Permalink to this definition">¶</a></dt>
<dd><p>Try to encode the given text to bytes, using encodings from settings or from Session. Will
always return a bytes, even if given something that is not str or bytes.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><ulclass="simple">
<li><p><strong>text</strong> (<em>any</em>) – The text to encode to bytes. If bytes, return unchanged. If not a str, convert
to str before converting.</p></li>
<li><p><strong>session</strong> (<aclass="reference internal"href="evennia.server.session.html#evennia.server.session.Session"title="evennia.server.session.Session"><em>Session</em></a><em>, </em><em>optional</em>) – A Session to get encoding info from. Will try this before
<dt>the encoded text following the session’s protocol flag followed by the</dt><dd><p>encodings specified in settings.ENCODINGS. If all attempt fail, log the error and send
the text with “?” in place of problematic characters. If the specified encoding cannot
be found, the protocol flag is reset to utf-8. In any case, returns bytes.</p>
</dd>
</dl>
</p>
</dd>
</dl>
<pclass="rubric">Notes</p>
<p>If <strong>text</strong> is already bytes, return it as is.</p>
</dd></dl>
<dlclass="py function">
<dtid="evennia.utils.utils.to_str">
<codeclass="sig-prename descclassname">evennia.utils.utils.</code><codeclass="sig-name descname">to_str</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">text</span></em>, <emclass="sig-param"><spanclass="n">session</span><spanclass="o">=</span><spanclass="default_value">None</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/utils/utils.html#to_str"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.utils.utils.to_str"title="Permalink to this definition">¶</a></dt>
<dd><p>Try to decode a bytestream to a python str, using encoding schemas from settings
or from Session. Will always return a str(), also if not given a str/bytes.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><ulclass="simple">
<li><p><strong>text</strong> (<em>any</em>) – The text to encode to bytes. If a str, return it. If also not bytes, convert
to str using str() or repr() as a fallback.</p></li>
<li><p><strong>session</strong> (<aclass="reference internal"href="evennia.server.session.html#evennia.server.session.Session"title="evennia.server.session.Session"><em>Session</em></a><em>, </em><em>optional</em>) – A Session to get encoding info from. Will try this before
falling back to settings.ENCODINGS.</p></li>
</ul>
</dd>
<dtclass="field-even">Returns</dt>
<ddclass="field-even"><p><em>decoded_text (str)</em>– The decoded text.</p>
</dd>
</dl>
<pclass="rubric">Notes</p>
<p>If <strong>text</strong> is already str, return it as is.</p>
<codeclass="sig-prename descclassname">evennia.utils.utils.</code><codeclass="sig-name descname">validate_email_address</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">emailaddress</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/utils/utils.html#validate_email_address"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.utils.utils.validate_email_address"title="Permalink to this definition">¶</a></dt>
<dd><p>Checks if an email address is syntactically correct. Makes use
of the django email-validator for consistency.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><p><strong>emailaddress</strong> (<em>str</em>) – Email address to validate.</p>
</dd>
<dtclass="field-even">Returns</dt>
<ddclass="field-even"><p><em>bool</em>– If this is a valid email or not.</p>
</dd>
</dl>
</dd></dl>
<dlclass="py function">
<dtid="evennia.utils.utils.inherits_from">
<codeclass="sig-prename descclassname">evennia.utils.utils.</code><codeclass="sig-name descname">inherits_from</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">obj</span></em>, <emclass="sig-param"><spanclass="n">parent</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/utils/utils.html#inherits_from"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.utils.utils.inherits_from"title="Permalink to this definition">¶</a></dt>
<dd><p>Takes an object and tries to determine if it inherits at <em>any</em>
distance from parent.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><ulclass="simple">
<li><p><strong>obj</strong> (<em>any</em>) – Object to analyze. This may be either an instance or
a class.</p></li>
<li><p><strong>parent</strong> (<em>any</em>) – Can be either an instance, a class or the python
path to the class.</p></li>
</ul>
</dd>
<dtclass="field-even">Returns</dt>
<ddclass="field-even"><p><em>inherits_from (bool)</em>– If <strong>parent</strong> is a parent to <strong>obj</strong> or not.</p>
</dd>
</dl>
<pclass="rubric">Notes</p>
<p>What differentiates this function from Python’s <strong>isinstance()</strong> is the
flexibility in the types allowed for the object and parent being compared.</p>
</dd></dl>
<dlclass="py function">
<dtid="evennia.utils.utils.server_services">
<codeclass="sig-prename descclassname">evennia.utils.utils.</code><codeclass="sig-name descname">server_services</code><spanclass="sig-paren">(</span><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/utils/utils.html#server_services"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.utils.utils.server_services"title="Permalink to this definition">¶</a></dt>
<dd><p>Lists all services active on the Server. Observe that since
services are launched in memory, this function will only return
any results if called from inside the game.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Returns</dt>
<ddclass="field-odd"><p><em>services (dict)</em>– A dict of available services.</p>
</dd>
</dl>
</dd></dl>
<dlclass="py function">
<dtid="evennia.utils.utils.uses_database">
<codeclass="sig-prename descclassname">evennia.utils.utils.</code><codeclass="sig-name descname">uses_database</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">name</span><spanclass="o">=</span><spanclass="default_value">'sqlite3'</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/utils/utils.html#uses_database"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.utils.utils.uses_database"title="Permalink to this definition">¶</a></dt>
<dd><p>Checks if the game is currently using a given database. This is a
shortcut to having to use the full backend name.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><p><strong>name</strong> (<em>str</em>) – One of ‘sqlite3’, ‘mysql’, ‘postgresql’ or ‘oracle’.</p>
</dd>
<dtclass="field-even">Returns</dt>
<ddclass="field-even"><p><em>uses (bool)</em>– If the given database is used or not.</p>
</dd>
</dl>
</dd></dl>
<dlclass="py function">
<dtid="evennia.utils.utils.delay">
<codeclass="sig-prename descclassname">evennia.utils.utils.</code><codeclass="sig-name descname">delay</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">timedelay</span></em>, <emclass="sig-param"><spanclass="n">callback</span></em>, <emclass="sig-param"><spanclass="o">*</span><spanclass="n">args</span></em>, <emclass="sig-param"><spanclass="o">**</span><spanclass="n">kwargs</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/utils/utils.html#delay"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.utils.utils.delay"title="Permalink to this definition">¶</a></dt>
<dd><p>Delay the calling of a callback (function).</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><ulclass="simple">
<li><p><strong>timedelay</strong> (<em>int</em><em> or </em><em>float</em>) – The delay in seconds.</p></li>
<li><p><strong>callback</strong> (<em>callable</em>) – Will be called as <strong>callback(*args, **kwargs)</strong>
after <strong>timedelay</strong> seconds.</p></li>
<li><p><strong>*args</strong>– Will be used as arguments to callback</p></li>
</ul>
</dd>
<dtclass="field-even">Keyword Arguments</dt>
<ddclass="field-even"><ulclass="simple">
<li><p><strong>persistent</strong> (<em>bool</em><em>, </em><em>optional</em>) – If True the delay remains after a server restart.
persistent is False by default.</p></li>
<li><p><strong>any</strong> (<em>any</em>) – Will be used as keyword arguments to callback.</p></li>
<dt>An instance of a task.</dt><dd><p>Refer to, evennia.scripts.taskhandler.TaskHandlerTask</p>
</dd>
</dl>
</p>
</dd>
</dl>
<pclass="rubric">Notes</p>
<p>The task handler (<strong>evennia.scripts.taskhandler.TASK_HANDLER</strong>) will
be called for persistent or non-persistent tasks.
If persistent is set to True, the callback, its arguments
and other keyword arguments will be saved (serialized) in the database,
assuming they can be. The callback will be executed even after
a server restart/reload, taking into account the specified delay
(and server down time).
Keep in mind that persistent tasks arguments and callback should not
use memory references.
If persistent is set to True the delay function will return an int
which is the task’s id intended for use with TASK_HANDLER’s do_task
and remove methods.
All persistent tasks whose time delays have passed will be called on server startup.</p>
</dd></dl>
<dlclass="py function">
<dtid="evennia.utils.utils.repeat">
<codeclass="sig-prename descclassname">evennia.utils.utils.</code><codeclass="sig-name descname">repeat</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">interval</span></em>, <emclass="sig-param"><spanclass="n">callback</span></em>, <emclass="sig-param"><spanclass="n">persistent</span><spanclass="o">=</span><spanclass="default_value">True</span></em>, <emclass="sig-param"><spanclass="n">idstring</span><spanclass="o">=</span><spanclass="default_value">''</span></em>, <emclass="sig-param"><spanclass="n">stop</span><spanclass="o">=</span><spanclass="default_value">False</span></em>, <emclass="sig-param"><spanclass="n">store_key</span><spanclass="o">=</span><spanclass="default_value">None</span></em>, <emclass="sig-param"><spanclass="o">*</span><spanclass="n">args</span></em>, <emclass="sig-param"><spanclass="o">**</span><spanclass="n">kwargs</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/utils/utils.html#repeat"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.utils.utils.repeat"title="Permalink to this definition">¶</a></dt>
<dd><p>Start a repeating task using the TickerHandler.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><ulclass="simple">
<li><p><strong>interval</strong> (<em>int</em>) – How often to call callback.</p></li>
<li><p><strong>callback</strong> (<em>callable</em>) – This will be called with <strong>*args, **kwargs</strong> every
<strong>interval</strong> seconds. This must be possible to pickle regardless
of if <strong>persistent</strong> is set or not!</p></li>
<li><p><strong>persistent</strong> (<em>bool</em><em>, </em><em>optional</em>) – If ticker survives a server reload.</p></li>
<li><p><strong>idstring</strong> (<em>str</em><em>, </em><em>optional</em>) – Separates multiple tickers. This is useful
mainly if wanting to set up multiple repeats for the same
interval/callback but with different args/kwargs.</p></li>
<li><p><strong>stop</strong> (<em>bool</em><em>, </em><em>optional</em>) – If set, use the given parameters to _stop_ a running
ticker instead of creating a new one.</p></li>
<li><p><strong>store_key</strong> (<em>tuple</em><em>, </em><em>optional</em>) – This is only used in combination with <strong>stop</strong> and
should be the return given from the original <strong>repeat</strong> call. If this
is given, all other args except <strong>stop</strong> are ignored.</p></li>
<li><p><strong>*args</strong>– Used as arguments to <strong>callback</strong>.</p></li>
<li><p><strong>**kwargs</strong>– Keyword-arguments to pass to <strong>callback</strong>.</p></li>
</ul>
</dd>
<dtclass="field-even">Returns</dt>
<ddclass="field-even"><p><em>tuple or None</em>– The tuple is the <strong>store_key</strong> - the identifier for the
created ticker. Store this and pass into unrepat() in order to to stop
this ticker later. Returns <strong>None</strong> if <strong>stop=True</strong>.</p>
</dd>
<dtclass="field-odd">Raises</dt>
<ddclass="field-odd"><p><strong>KeyError</strong>– If trying to stop a ticker that was not found.</p>
</dd>
</dl>
</dd></dl>
<dlclass="py function">
<dtid="evennia.utils.utils.unrepeat">
<codeclass="sig-prename descclassname">evennia.utils.utils.</code><codeclass="sig-name descname">unrepeat</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">store_key</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/utils/utils.html#unrepeat"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.utils.utils.unrepeat"title="Permalink to this definition">¶</a></dt>
<dd><p>This is used to stop a ticker previously started with <strong>repeat</strong>.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><p><strong>store_key</strong> (<em>tuple</em>) – This is the return from <strong>repeat</strong>, used to uniquely
identify the ticker to stop. Without the store_key, the ticker
must be stopped by passing its parameters to <strong>TICKER_HANDLER.remove</strong>
directly.</p>
</dd>
<dtclass="field-even">Returns</dt>
<ddclass="field-even"><p><p><em>bool</em>–</p>
<dlclass="simple">
<dt>True if a ticker was stopped, False if not (for example because no</dt><dd><p>matching ticker was found or it was already stopped).</p>
</dd>
</dl>
</p>
</dd>
</dl>
</dd></dl>
<dlclass="py function">
<dtid="evennia.utils.utils.run_async">
<codeclass="sig-prename descclassname">evennia.utils.utils.</code><codeclass="sig-name descname">run_async</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">to_execute</span></em>, <emclass="sig-param"><spanclass="o">*</span><spanclass="n">args</span></em>, <emclass="sig-param"><spanclass="o">**</span><spanclass="n">kwargs</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/utils/utils.html#run_async"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.utils.utils.run_async"title="Permalink to this definition">¶</a></dt>
<dd><p>Runs a function or executes a code snippet asynchronously.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><p><strong>to_execute</strong> (<em>callable</em>) – If this is a callable, it will be
executed with <strong>*args</strong> and non-reserved <strong>**kwargs</strong> as arguments.
The callable will be executed using ProcPool, or in a thread
if ProcPool is not available.</p>
</dd>
<dtclass="field-even">Keyword Arguments</dt>
<ddclass="field-even"><ulclass="simple">
<li><p><strong>at_return</strong> (<em>callable</em>) – Should point to a callable with one
argument. It will be called with the return value from
to_execute.</p></li>
<li><p><strong>at_return_kwargs</strong> (<em>dict</em>) – This dictionary will be used as
keyword arguments to the at_return callback.</p></li>
<li><p><strong>at_err</strong> (<em>callable</em>) – This will be called with a Failure instance
if there is an error in to_execute.</p></li>
<li><p><strong>at_err_kwargs</strong> (<em>dict</em>) – This dictionary will be used as keyword
arguments to the at_err errback.</p></li>
</ul>
</dd>
</dl>
<pclass="rubric">Notes</p>
<p>All other <strong>*args</strong> and <strong>**kwargs</strong> will be passed on to
<strong>to_execute</strong>. Run_async will relay executed code to a thread
or procpool.</p>
<p>Use this function with restrain and only for features/commands
that you know has no influence on the cause-and-effect order of your
game (commands given after the async function might be executed before
it has finished). Accessing the same property from different threads
can lead to unpredicted behaviour if you are not careful (this is called a
“race condition”).</p>
<p>Also note that some databases, notably sqlite3, don’t support access from
multiple threads simultaneously, so if you do heavy database access from
your <strong>to_execute</strong> under sqlite3 you will probably run very slow or even get
<codeclass="sig-prename descclassname">evennia.utils.utils.</code><codeclass="sig-name descname">check_evennia_dependencies</code><spanclass="sig-paren">(</span><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/utils/utils.html#check_evennia_dependencies"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.utils.utils.check_evennia_dependencies"title="Permalink to this definition">¶</a></dt>
<dd><p>Checks the versions of Evennia’s dependencies including making
<dt><strong>False</strong> if a show-stopping version mismatch is</dt><dd><p>found.</p>
</dd>
</dl>
</p>
</dd>
</dl>
</dd></dl>
<dlclass="py function">
<dtid="evennia.utils.utils.has_parent">
<codeclass="sig-prename descclassname">evennia.utils.utils.</code><codeclass="sig-name descname">has_parent</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">basepath</span></em>, <emclass="sig-param"><spanclass="n">obj</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/utils/utils.html#has_parent"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.utils.utils.has_parent"title="Permalink to this definition">¶</a></dt>
<dd><p>Checks if <strong>basepath</strong> is somewhere in obj’s parent tree.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><ulclass="simple">
<li><p><strong>basepath</strong> (<em>str</em>) – Python dotpath to compare against obj path.</p></li>
<li><p><strong>obj</strong> (<em>any</em>) – Object whose path is to be checked.</p></li>
</ul>
</dd>
<dtclass="field-even">Returns</dt>
<ddclass="field-even"><p><em>has_parent (bool)</em>– If the check was successful or not.</p>
</dd>
</dl>
</dd></dl>
<dlclass="py function">
<dtid="evennia.utils.utils.mod_import_from_path">
<codeclass="sig-prename descclassname">evennia.utils.utils.</code><codeclass="sig-name descname">mod_import_from_path</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">path</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/utils/utils.html#mod_import_from_path"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.utils.utils.mod_import_from_path"title="Permalink to this definition">¶</a></dt>
<dd><p>Load a Python module at the specified path.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><p><strong>path</strong> (<em>str</em>) – An absolute path to a Python module to load.</p>
</dd>
<dtclass="field-even">Returns</dt>
<ddclass="field-even"><p><em>(module or None)</em>– An imported module if the path was a valid
Python module. Returns <strong>None</strong> if the import failed.</p>
</dd>
</dl>
</dd></dl>
<dlclass="py function">
<dtid="evennia.utils.utils.mod_import">
<codeclass="sig-prename descclassname">evennia.utils.utils.</code><codeclass="sig-name descname">mod_import</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">module</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/utils/utils.html#mod_import"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.utils.utils.mod_import"title="Permalink to this definition">¶</a></dt>
<dd><p>A generic Python module loader.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><p><strong>module</strong> (<em>str</em><em>, </em><em>module</em>) – This can be either a Python path
(dot-notation like <strong>evennia.objects.models</strong>), an absolute path
(e.g. <strong>/home/eve/evennia/evennia/objects/models.py</strong>) or an
<ddclass="field-even"><p><em>(module or None)</em>– An imported module. If the input argument was
already a module, this is returned as-is, otherwise the path is
parsed and imported. Returns <strong>None</strong> and logs error if import failed.</p>
</dd>
</dl>
</dd></dl>
<dlclass="py function">
<dtid="evennia.utils.utils.all_from_module">
<codeclass="sig-prename descclassname">evennia.utils.utils.</code><codeclass="sig-name descname">all_from_module</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">module</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/utils/utils.html#all_from_module"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.utils.utils.all_from_module"title="Permalink to this definition">¶</a></dt>
<dd><p>Return all global-level variables defined in a module.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><p><strong>module</strong> (<em>str</em><em>, </em><em>module</em>) – This can be either a Python path
(dot-notation like <strong>evennia.objects.models</strong>), an absolute path
(e.g. <strong>/home/eve/evennia/evennia/objects.models.py</strong>) or an
<codeclass="sig-prename descclassname">evennia.utils.utils.</code><codeclass="sig-name descname">callables_from_module</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">module</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/utils/utils.html#callables_from_module"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.utils.utils.callables_from_module"title="Permalink to this definition">¶</a></dt>
<dd><p>Return all global-level callables defined in a module.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><p><strong>module</strong> (<em>str</em><em>, </em><em>module</em>) – A python-path to a module or an actual
module object.</p>
</dd>
<dtclass="field-even">Returns</dt>
<ddclass="field-even"><p><em>callables (dict)</em>– A dict of {name: callable, …} from the module.</p>
</dd>
</dl>
<pclass="rubric">Notes</p>
<p>Will ignore callables whose names start with underscore “_”.</p>
</dd></dl>
<dlclass="py function">
<dtid="evennia.utils.utils.variable_from_module">
<codeclass="sig-prename descclassname">evennia.utils.utils.</code><codeclass="sig-name descname">variable_from_module</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">module</span></em>, <emclass="sig-param"><spanclass="n">variable</span><spanclass="o">=</span><spanclass="default_value">None</span></em>, <emclass="sig-param"><spanclass="n">default</span><spanclass="o">=</span><spanclass="default_value">None</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/utils/utils.html#variable_from_module"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.utils.utils.variable_from_module"title="Permalink to this definition">¶</a></dt>
<dd><p>Retrieve a variable or list of variables from a module. The
variable(s) must be defined globally in the module. If no variable
is given (or a list entry is <strong>None</strong>), all global variables are
extracted from the module.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><ulclass="simple">
<li><p><strong>module</strong> (<em>string</em><em> or </em><em>module</em>) – Python path, absolute path or a module.</p></li>
<li><p><strong>variable</strong> (<em>string</em><em> or </em><em>iterable</em><em>, </em><em>optional</em>) – Single variable name or iterable
of variable names to extract. If not given, all variables in
the module will be returned.</p></li>
<li><p><strong>default</strong> (<em>string</em><em>, </em><em>optional</em>) – Default value to use if a variable fails to
be extracted. Ignored if <strong>variable</strong> is not given.</p></li>
</ul>
</dd>
<dtclass="field-even">Returns</dt>
<ddclass="field-even"><p><em>variables (value or list)</em>– A single value or a list of values
depending on if <strong>variable</strong> is given or not. Errors in lists
are replaced by the <strong>default</strong> argument.</p>
</dd>
</dl>
</dd></dl>
<dlclass="py function">
<dtid="evennia.utils.utils.string_from_module">
<codeclass="sig-prename descclassname">evennia.utils.utils.</code><codeclass="sig-name descname">string_from_module</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">module</span></em>, <emclass="sig-param"><spanclass="n">variable</span><spanclass="o">=</span><spanclass="default_value">None</span></em>, <emclass="sig-param"><spanclass="n">default</span><spanclass="o">=</span><spanclass="default_value">None</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/utils/utils.html#string_from_module"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.utils.utils.string_from_module"title="Permalink to this definition">¶</a></dt>
<dd><p>This is a wrapper for <strong>variable_from_module</strong> that requires return
value to be a string to pass. It’s primarily used by login screen.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><ulclass="simple">
<li><p><strong>module</strong> (<em>string</em><em> or </em><em>module</em>) – Python path, absolute path or a module.</p></li>
<li><p><strong>variable</strong> (<em>string</em><em> or </em><em>iterable</em><em>, </em><em>optional</em>) – Single variable name or iterable
of variable names to extract. If not given, all variables in
the module will be returned.</p></li>
<li><p><strong>default</strong> (<em>string</em><em>, </em><em>optional</em>) – Default value to use if a variable fails to
be extracted. Ignored if <strong>variable</strong> is not given.</p></li>
</ul>
</dd>
<dtclass="field-even">Returns</dt>
<ddclass="field-even"><p><em>variables (value or list)</em>– A single (string) value or a list of values
depending on if <strong>variable</strong> is given or not. Errors in lists (such
as the value not being a string) are replaced by the <strong>default</strong> argument.</p>
<codeclass="sig-prename descclassname">evennia.utils.utils.</code><codeclass="sig-name descname">random_string_from_module</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">module</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/utils/utils.html#random_string_from_module"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.utils.utils.random_string_from_module"title="Permalink to this definition">¶</a></dt>
<dd><p>Returns a random global string from a module.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><p><strong>module</strong> (<em>string</em><em> or </em><em>module</em>) – Python path, absolute path or a module.</p>
</dd>
<dtclass="field-even">Returns</dt>
<ddclass="field-even"><p><em>random (string)</em>– A random stribg variable from <strong>module</strong>.</p>
<codeclass="sig-prename descclassname">evennia.utils.utils.</code><codeclass="sig-name descname">fuzzy_import_from_module</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">path</span></em>, <emclass="sig-param"><spanclass="n">variable</span></em>, <emclass="sig-param"><spanclass="n">default</span><spanclass="o">=</span><spanclass="default_value">None</span></em>, <emclass="sig-param"><spanclass="n">defaultpaths</span><spanclass="o">=</span><spanclass="default_value">None</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/utils/utils.html#fuzzy_import_from_module"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.utils.utils.fuzzy_import_from_module"title="Permalink to this definition">¶</a></dt>
<dd><p>Import a variable based on a fuzzy path. First the literal
<strong>path</strong> will be tried, then all given <strong>defaultpaths</strong> will be
prepended to see a match is found.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><ulclass="simple">
<li><p><strong>path</strong> (<em>str</em>) – Full or partial python path.</p></li>
<li><p><strong>variable</strong> (<em>str</em>) – Name of variable to import from module.</p></li>
<li><p><strong>default</strong> (<em>string</em><em>, </em><em>optional</em>) – Default value to use if a variable fails to
be extracted. Ignored if <strong>variable</strong> is not given.</p></li>
<li><p><strong>defaultpaths</strong> (<em>iterable</em><em>, </em><em>options</em>) – Python paths to attempt in order if
importing directly from <strong>path</strong> doesn’t work.</p></li>
<dt>The variable imported from the module, or <strong>default</strong>, if</dt><dd><p>not found.</p>
</dd>
</dl>
</p>
</dd>
</dl>
</dd></dl>
<dlclass="py function">
<dtid="evennia.utils.utils.class_from_module">
<codeclass="sig-prename descclassname">evennia.utils.utils.</code><codeclass="sig-name descname">class_from_module</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">path</span></em>, <emclass="sig-param"><spanclass="n">defaultpaths</span><spanclass="o">=</span><spanclass="default_value">None</span></em>, <emclass="sig-param"><spanclass="n">fallback</span><spanclass="o">=</span><spanclass="default_value">None</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/utils/utils.html#class_from_module"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.utils.utils.class_from_module"title="Permalink to this definition">¶</a></dt>
<dd><p>Return a class from a module, given the class’ full python path. This is
primarily used to convert db_typeclass_path:s to classes.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><ulclass="simple">
<li><p><strong>path</strong> (<em>str</em>) – Full Python dot-path to module.</p></li>
<li><p><strong>defaultpaths</strong> (<em>iterable</em><em>, </em><em>optional</em>) – If a direct import from <strong>path</strong> fails,
try subsequent imports by prepending those paths to <strong>path</strong>.</p></li>
<li><p><strong>fallback</strong> (<em>str</em>) – If all other attempts fail, use this path as a fallback.
This is intended as a last-resort. In the example of Evennia
loading, this would be a path to a default parent class in the
evennia repo itself.</p></li>
</ul>
</dd>
<dtclass="field-even">Returns</dt>
<ddclass="field-even"><p><em>class (Class)</em>– An uninstantiated class recovered from path.</p>
</dd>
<dtclass="field-odd">Raises</dt>
<ddclass="field-odd"><p><strong>ImportError</strong>– If all loading failed.</p>
</dd>
</dl>
</dd></dl>
<dlclass="py function">
<dtid="evennia.utils.utils.object_from_module">
<codeclass="sig-prename descclassname">evennia.utils.utils.</code><codeclass="sig-name descname">object_from_module</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">path</span></em>, <emclass="sig-param"><spanclass="n">defaultpaths</span><spanclass="o">=</span><spanclass="default_value">None</span></em>, <emclass="sig-param"><spanclass="n">fallback</span><spanclass="o">=</span><spanclass="default_value">None</span></em><spanclass="sig-paren">)</span><aclass="headerlink"href="#evennia.utils.utils.object_from_module"title="Permalink to this definition">¶</a></dt>
<dd><p>Return a class from a module, given the class’ full python path. This is
primarily used to convert db_typeclass_path:s to classes.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><ulclass="simple">
<li><p><strong>path</strong> (<em>str</em>) – Full Python dot-path to module.</p></li>
<li><p><strong>defaultpaths</strong> (<em>iterable</em><em>, </em><em>optional</em>) – If a direct import from <strong>path</strong> fails,
try subsequent imports by prepending those paths to <strong>path</strong>.</p></li>
<li><p><strong>fallback</strong> (<em>str</em>) – If all other attempts fail, use this path as a fallback.
This is intended as a last-resort. In the example of Evennia
loading, this would be a path to a default parent class in the
evennia repo itself.</p></li>
</ul>
</dd>
<dtclass="field-even">Returns</dt>
<ddclass="field-even"><p><em>class (Class)</em>– An uninstantiated class recovered from path.</p>
</dd>
<dtclass="field-odd">Raises</dt>
<ddclass="field-odd"><p><strong>ImportError</strong>– If all loading failed.</p>
</dd>
</dl>
</dd></dl>
<dlclass="py function">
<dtid="evennia.utils.utils.init_new_account">
<codeclass="sig-prename descclassname">evennia.utils.utils.</code><codeclass="sig-name descname">init_new_account</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">account</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/utils/utils.html#init_new_account"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.utils.utils.init_new_account"title="Permalink to this definition">¶</a></dt>
<dd><p>Deprecated.</p>
</dd></dl>
<dlclass="py function">
<dtid="evennia.utils.utils.string_similarity">
<codeclass="sig-prename descclassname">evennia.utils.utils.</code><codeclass="sig-name descname">string_similarity</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">string1</span></em>, <emclass="sig-param"><spanclass="n">string2</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/utils/utils.html#string_similarity"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.utils.utils.string_similarity"title="Permalink to this definition">¶</a></dt>
<dd><p>This implements a “cosine-similarity” algorithm as described for example in
<em>Proceedings of the 22nd International Conference on Computation
Linguistics</em> (Coling 2008), pages 593-600, Manchester, August 2008.
The measure-vectors used is simply a “bag of words” type histogram
(but for letters).</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><ulclass="simple">
<li><p><strong>string1</strong> (<em>str</em>) – String to compare (may contain any number of words).</p></li>
<li><p><strong>string2</strong> (<em>str</em>) – Second string to compare (any number of words).</p></li>
<dt>A value 0…1 rating how similar the two</dt><dd><p>strings are.</p>
</dd>
</dl>
</p>
</dd>
</dl>
</dd></dl>
<dlclass="py function">
<dtid="evennia.utils.utils.string_suggestions">
<codeclass="sig-prename descclassname">evennia.utils.utils.</code><codeclass="sig-name descname">string_suggestions</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">string</span></em>, <emclass="sig-param"><spanclass="n">vocabulary</span></em>, <emclass="sig-param"><spanclass="n">cutoff</span><spanclass="o">=</span><spanclass="default_value">0.6</span></em>, <emclass="sig-param"><spanclass="n">maxnum</span><spanclass="o">=</span><spanclass="default_value">3</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/utils/utils.html#string_suggestions"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.utils.utils.string_suggestions"title="Permalink to this definition">¶</a></dt>
<dd><p>Given a <strong>string</strong> and a <strong>vocabulary</strong>, return a match or a list of
suggestions based on string similarity.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><ulclass="simple">
<li><p><strong>string</strong> (<em>str</em>) – A string to search for.</p></li>
<li><p><strong>vocabulary</strong> (<em>iterable</em>) – A list of available strings.</p></li>
<li><p><strong>cutoff</strong> (<em>int</em><em>, </em><em>0-1</em>) – Limit the similarity matches (the higher
the value, the more exact a match is required).</p></li>
<li><p><strong>maxnum</strong> (<em>int</em>) – Maximum number of suggestions to return.</p></li>
</ul>
</dd>
<dtclass="field-even">Returns</dt>
<ddclass="field-even"><p><em>suggestions (list)</em>– Suggestions from <strong>vocabulary</strong> with a
similarity-rating that higher than or equal to <strong>cutoff</strong>.
<codeclass="sig-prename descclassname">evennia.utils.utils.</code><codeclass="sig-name descname">string_partial_matching</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">alternatives</span></em>, <emclass="sig-param"><spanclass="n">inp</span></em>, <emclass="sig-param"><spanclass="n">ret_index</span><spanclass="o">=</span><spanclass="default_value">True</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/utils/utils.html#string_partial_matching"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.utils.utils.string_partial_matching"title="Permalink to this definition">¶</a></dt>
<dd><p>Partially matches a string based on a list of <strong>alternatives</strong>.
Matching is made from the start of each subword in each
alternative. Case is not important. So e.g. “bi sh sw” or just
“big” or “shiny” or “sw” will match “Big shiny sword”. Scoring is
done to allow to separate by most common denominator. You will get
multiple matches returned if appropriate.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><ulclass="simple">
<li><p><strong>alternatives</strong> (<em>list of str</em>) – A list of possible strings to
<li><p><strong>ret_index</strong> (<em>bool</em><em>, </em><em>optional</em>) – Return list of indices (from alternatives
array) instead of strings.</p></li>
</ul>
</dd>
<dtclass="field-even">Returns</dt>
<ddclass="field-even"><p><em>matches (list)</em>– String-matches or indices if <strong>ret_index</strong> is <strong>True</strong>.</p>
</dd>
</dl>
</dd></dl>
<dlclass="py function">
<dtid="evennia.utils.utils.format_table">
<codeclass="sig-prename descclassname">evennia.utils.utils.</code><codeclass="sig-name descname">format_table</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">table</span></em>, <emclass="sig-param"><spanclass="n">extra_space</span><spanclass="o">=</span><spanclass="default_value">1</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/utils/utils.html#format_table"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.utils.utils.format_table"title="Permalink to this definition">¶</a></dt>
<dd><p>Format a 2D array of strings into a multi-column table.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><ulclass="simple">
<li><p><strong>table</strong> (<em>list</em>) – A list of lists to represent columns in the
table: <strong>[[val,val,val,…], [val,val,val,…], …]</strong>, where
each val will be placed on a separate row in the
column. All columns must have the same number of rows (some
positions may be empty though).</p></li>
<li><p><strong>extra_space</strong> (<em>int</em><em>, </em><em>optional</em>) – Sets how much <em>minimum</em> extra
padding (in characters) should be left between columns.</p></li>
</ul>
</dd>
<dtclass="field-even">Returns</dt>
<ddclass="field-even"><p><em>list</em>– A list of lists representing the rows to print out one by one.</p>
</dd>
</dl>
<pclass="rubric">Notes</p>
<p>The function formats the columns to be as wide as the widest member
of each column.</p>
<p><strong>evennia.utils.evtable</strong> is more powerful than this, but this
function can be useful when the number of columns and rows are
<codeclass="sig-prename descclassname">evennia.utils.utils.</code><codeclass="sig-name descname">percent</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">value</span></em>, <emclass="sig-param"><spanclass="n">minval</span></em>, <emclass="sig-param"><spanclass="n">maxval</span></em>, <emclass="sig-param"><spanclass="n">formatting</span><spanclass="o">=</span><spanclass="default_value">'{:3.1f}%'</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/utils/utils.html#percent"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.utils.utils.percent"title="Permalink to this definition">¶</a></dt>
<dd><p>Get a value in an interval as a percentage of its position
in that interval. This also understands negative numbers.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><ulclass="simple">
<li><p><strong>value</strong> (<em>number</em>) – This should be a value minval<=value<=maxval.</p></li>
<li><p><strong>minval</strong> (<em>number</em><em> or </em><em>None</em>) – Smallest value in interval. This could be None
for an open interval (then return will always be 100%)</p></li>
<li><p><strong>maxval</strong> (<em>number</em><em> or </em><em>None</em>) – Biggest value in interval. This could be None
for an open interval (then return will always be 100%)</p></li>
<li><p><strong>formatted</strong> (<em>str</em><em>, </em><em>optional</em>) – This is a string that should
accept one formatting tag. This will receive the
current value as a percentage. If None, the
raw float will be returned instead.</p></li>
</ul>
</dd>
<dtclass="field-even">Returns</dt>
<ddclass="field-even"><p><em>str or float</em>– The formatted value or the raw percentage as a float.</p>
</dd>
</dl>
<pclass="rubric">Notes</p>
<p>We try to handle a weird interval gracefully.</p>
<ulclass="simple">
<li><p>If either maxval or minval is None (open interval), we (aribtrarily) assume 100%.</p></li>
<li><p>If minval > maxval, we return 0%.</p></li>
<li><p>If minval == maxval == value we are looking at a single value match and return 100%.</p></li>
<li><p>If minval == maxval != value we return 0%.</p></li>
<li><p>If value not in [minval..maxval], we set value to the closest
boundary, so the result will be 0% or 100%, respectively.</p></li>
</ul>
</dd></dl>
<dlclass="py function">
<dtid="evennia.utils.utils.percentile">
<codeclass="sig-prename descclassname">evennia.utils.utils.</code><codeclass="sig-name descname">percentile</code><spanclass="sig-paren">(</span><emclass="sig-param">iterable</em>, <emclass="sig-param">percent</em>, <emclass="sig-param">key=<function <lambda>></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/utils/utils.html#percentile"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.utils.utils.percentile"title="Permalink to this definition">¶</a></dt>
<dd><p>Find the percentile of a list of values.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><ulclass="simple">
<li><p><strong>iterable</strong> (<em>iterable</em>) – A list of values. Note N MUST BE already sorted.</p></li>
<li><p><strong>percent</strong> (<em>float</em>) – A value from 0.0 to 1.0.</p></li>
<ddclass="field-even"><p><em>float</em>– The percentile of the values</p>
</dd>
</dl>
</dd></dl>
<dlclass="py function">
<dtid="evennia.utils.utils.format_grid">
<codeclass="sig-prename descclassname">evennia.utils.utils.</code><codeclass="sig-name descname">format_grid</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">elements</span></em>, <emclass="sig-param"><spanclass="n">width</span><spanclass="o">=</span><spanclass="default_value">78</span></em>, <emclass="sig-param"><spanclass="n">sep</span><spanclass="o">=</span><spanclass="default_value">' '</span></em>, <emclass="sig-param"><spanclass="n">verbatim_elements</span><spanclass="o">=</span><spanclass="default_value">None</span></em>, <emclass="sig-param"><spanclass="n">line_prefix</span><spanclass="o">=</span><spanclass="default_value">''</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/utils/utils.html#format_grid"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.utils.utils.format_grid"title="Permalink to this definition">¶</a></dt>
<dd><p>This helper function makes a ‘grid’ output, where it distributes the given
string-elements as evenly as possible to fill out the given width.
will not work well if the variation of length is very big!</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><ulclass="simple">
<li><p><strong>elements</strong> (<em>iterable</em>) – A 1D list of string elements to put in the grid.</p></li>
<li><p><strong>width</strong> (<em>int</em><em>, </em><em>optional</em>) – The width of the grid area to fill.</p></li>
<li><p><strong>sep</strong> (<em>str</em><em>, </em><em>optional</em>) – The extra separator to put between words. If
set to the empty string, words may run into each other.</p></li>
<li><p><strong>verbatim_elements</strong> (<em>list</em><em>, </em><em>optional</em>) – This is a list of indices pointing to
specific items in the <strong>elements</strong> list. An element at this index will
not be included in the calculation of the slot sizes. It will still
be inserted into the grid at the correct position and may be surrounded
by padding unless filling the entire line. This is useful for embedding
decorations in the grid, such as horizontal bars.</p></li>
<li><p><strong>ignore_ansi</strong> (<em>bool</em><em>, </em><em>optional</em>) – Ignore ansi markups when calculating white spacing.</p></li>
<li><p><strong>line_prefix</strong> (<em>str</em><em>, </em><em>optional</em>) – A prefix to add at the beginning of each line.
This can e.g. be used to preserve line color across line breaks.</p></li>
</ul>
</dd>
<dtclass="field-even">Returns</dt>
<ddclass="field-even"><p><em>list</em>– The grid as a list of ready-formatted rows. We return it
like this to make it easier to insert decorations between rows, such
as horizontal bars.</p>
</dd>
</dl>
</dd></dl>
<dlclass="py function">
<dtid="evennia.utils.utils.get_evennia_pids">
<codeclass="sig-prename descclassname">evennia.utils.utils.</code><codeclass="sig-name descname">get_evennia_pids</code><spanclass="sig-paren">(</span><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/utils/utils.html#get_evennia_pids"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.utils.utils.get_evennia_pids"title="Permalink to this definition">¶</a></dt>
<dd><p>Get the currently valid PIDs (Process IDs) of the Portal and
<codeclass="sig-prename descclassname">evennia.utils.utils.</code><codeclass="sig-name descname">deepsize</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">obj</span></em>, <emclass="sig-param"><spanclass="n">max_depth</span><spanclass="o">=</span><spanclass="default_value">4</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/utils/utils.html#deepsize"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.utils.utils.deepsize"title="Permalink to this definition">¶</a></dt>
<dd><p>Get not only size of the given object, but also the size of
objects referenced by the object, down to <strong>max_depth</strong> distance
from the object.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><ulclass="simple">
<li><p><strong>obj</strong> (<em>object</em>) – the object to be measured.</p></li>
<li><p><strong>max_depth</strong> (<em>int</em><em>, </em><em>optional</em>) – maximum referential distance
from <strong>obj</strong> that <strong>deepsize()</strong> should cover for
measuring objects referenced by <strong>obj</strong>.</p></li>
</ul>
</dd>
<dtclass="field-even">Returns</dt>
<ddclass="field-even"><p><em>size (int)</em>– deepsize of <strong>obj</strong> in Bytes.</p>
</dd>
</dl>
<pclass="rubric">Notes</p>
<p>This measure is necessarily approximate since some
memory is shared between objects. The <strong>max_depth</strong> of 4 is roughly
tested to give reasonable size information about database models
and their handlers.</p>
</dd></dl>
<dlclass="py class">
<dtid="evennia.utils.utils.lazy_property">
<emclass="property">class </em><codeclass="sig-prename descclassname">evennia.utils.utils.</code><codeclass="sig-name descname">lazy_property</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">func</span></em>, <emclass="sig-param"><spanclass="n">name</span><spanclass="o">=</span><spanclass="default_value">None</span></em>, <emclass="sig-param"><spanclass="n">doc</span><spanclass="o">=</span><spanclass="default_value">None</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/utils/utils.html#lazy_property"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.utils.utils.lazy_property"title="Permalink to this definition">¶</a></dt>
<codeclass="sig-name descname">__init__</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">func</span></em>, <emclass="sig-param"><spanclass="n">name</span><spanclass="o">=</span><spanclass="default_value">None</span></em>, <emclass="sig-param"><spanclass="n">doc</span><spanclass="o">=</span><spanclass="default_value">None</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/utils/utils.html#lazy_property.__init__"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.utils.utils.lazy_property.__init__"title="Permalink to this definition">¶</a></dt>
<codeclass="sig-prename descclassname">evennia.utils.utils.</code><codeclass="sig-name descname">strip_control_sequences</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">string</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/utils/utils.html#strip_control_sequences"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.utils.utils.strip_control_sequences"title="Permalink to this definition">¶</a></dt>
<dd><p>Remove non-print text sequences.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><p><strong>string</strong> (<em>str</em>) – Text to strip.</p>
<codeclass="sig-prename descclassname">evennia.utils.utils.</code><codeclass="sig-name descname">calledby</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">callerdepth</span><spanclass="o">=</span><spanclass="default_value">1</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/utils/utils.html#calledby"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.utils.utils.calledby"title="Permalink to this definition">¶</a></dt>
<dd><p>Only to be used for debug purposes. Insert this debug function in
another function; it will print which function called it.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><p><strong>callerdepth</strong> (<em>int</em><em> or </em><em>None</em>) – If None, show entire stack. If int, must be larger than 0.
When > 1, it will print the sequence to that depth.</p>
</dd>
<dtclass="field-even">Returns</dt>
<ddclass="field-even"><p><em>calledby (str)</em>– A debug string detailing the code that called us.</p>
</dd>
</dl>
</dd></dl>
<dlclass="py function">
<dtid="evennia.utils.utils.m_len">
<codeclass="sig-prename descclassname">evennia.utils.utils.</code><codeclass="sig-name descname">m_len</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">target</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/utils/utils.html#m_len"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.utils.utils.m_len"title="Permalink to this definition">¶</a></dt>
<dd><p>Provides length checking for strings with MXP patterns, and falls
back to normal len for other objects.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><p><strong>target</strong> (<em>str</em>) – A string with potential MXP components
to search.</p>
</dd>
<dtclass="field-even">Returns</dt>
<ddclass="field-even"><p><em>length (int)</em>– The length of <strong>target</strong>, ignoring MXP components.</p>
</dd>
</dl>
</dd></dl>
<dlclass="py function">
<dtid="evennia.utils.utils.display_len">
<codeclass="sig-prename descclassname">evennia.utils.utils.</code><codeclass="sig-name descname">display_len</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">target</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/utils/utils.html#display_len"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.utils.utils.display_len"title="Permalink to this definition">¶</a></dt>
<dd><p>Calculate the ‘visible width’ of text. This is not necessarily the same as the
number of characters in the case of certain asian characters. This will also
strip MXP patterns.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><p><strong>target</strong> (<em>any</em>) – Something to measure the length of. If a string, it will be
measured keeping asian-character and MXP links in mind.</p>
</dd>
<dtclass="field-even">Returns</dt>
<ddclass="field-even"><p><em>int</em>– The visible width of the target.</p>
</dd>
</dl>
</dd></dl>
<dlclass="py function">
<dtid="evennia.utils.utils.at_search_result">
<codeclass="sig-prename descclassname">evennia.utils.utils.</code><codeclass="sig-name descname">at_search_result</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">matches</span></em>, <emclass="sig-param"><spanclass="n">caller</span></em>, <emclass="sig-param"><spanclass="n">query</span><spanclass="o">=</span><spanclass="default_value">''</span></em>, <emclass="sig-param"><spanclass="n">quiet</span><spanclass="o">=</span><spanclass="default_value">False</span></em>, <emclass="sig-param"><spanclass="o">**</span><spanclass="n">kwargs</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/utils/utils.html#at_search_result"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.utils.utils.at_search_result"title="Permalink to this definition">¶</a></dt>
<dd><p>This is a generic hook for handling all processing of a search
result, including error reporting. This is also called by the cmdhandler
to manage errors in command lookup.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><ulclass="simple">
<li><p><strong>matches</strong> (<em>list</em>) – This is a list of 0, 1 or more typeclass
instances or Command instances, the matched result of the
search. If 0, a nomatch error should be echoed, and if >1,
multimatch errors should be given. Only if a single match
should the result pass through.</p></li>
<li><p><strong>caller</strong> (<em>Object</em>) – The object performing the search and/or which should</p></li>
<emclass="property">class </em><codeclass="sig-prename descclassname">evennia.utils.utils.</code><codeclass="sig-name descname">LimitedSizeOrderedDict</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="o">*</span><spanclass="n">args</span></em>, <emclass="sig-param"><spanclass="o">**</span><spanclass="n">kwargs</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/utils/utils.html#LimitedSizeOrderedDict"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.utils.utils.LimitedSizeOrderedDict"title="Permalink to this definition">¶</a></dt>
<codeclass="sig-name descname">__init__</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="o">*</span><spanclass="n">args</span></em>, <emclass="sig-param"><spanclass="o">**</span><spanclass="n">kwargs</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/utils/utils.html#LimitedSizeOrderedDict.__init__"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.utils.utils.LimitedSizeOrderedDict.__init__"title="Permalink to this definition">¶</a></dt>
<dd><p>Limited-size ordered dict.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Keyword Arguments</dt>
<ddclass="field-odd"><ulclass="simple">
<li><p><strong>size_limit</strong> (<em>int</em>) – Use this to limit the number of elements
alloweds to be in this list. By default the overshooting elements
will be removed in FIFO order.</p></li>
<li><p><strong>fifo</strong> (<em>bool</em><em>, </em><em>optional</em>) – Defaults to <strong>True</strong>. Remove overshooting elements
in FIFO order. If <strong>False</strong>, remove in FILO order.</p></li>
<codeclass="sig-name descname">update</code><spanclass="sig-paren">(</span><spanclass="optional">[</span><emclass="sig-param">E</em>, <spanclass="optional">]</span><emclass="sig-param">**F</em><spanclass="sig-paren">)</span>→ None. Update D from dict/iterable E and F.<aclass="reference internal"href="../_modules/evennia/utils/utils.html#LimitedSizeOrderedDict.update"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.utils.utils.LimitedSizeOrderedDict.update"title="Permalink to this definition">¶</a></dt>
<dd><p>If E is present and has a .keys() method, then does: for k in E: D[k] = E[k]
If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v
In either case, this is followed by: for k in F: D[k] = F[k]</p>
</dd></dl>
</dd></dl>
<dlclass="py function">
<dtid="evennia.utils.utils.get_game_dir_path">
<codeclass="sig-prename descclassname">evennia.utils.utils.</code><codeclass="sig-name descname">get_game_dir_path</code><spanclass="sig-paren">(</span><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/utils/utils.html#get_game_dir_path"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.utils.utils.get_game_dir_path"title="Permalink to this definition">¶</a></dt>
<dd><p>This is called by settings_default in order to determine the path
of the game directory.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Returns</dt>
<ddclass="field-odd"><p><em>path (str)</em>– Full OS path to the game dir</p>
</dd>
</dl>
</dd></dl>
<dlclass="py function">
<dtid="evennia.utils.utils.get_all_typeclasses">
<codeclass="sig-prename descclassname">evennia.utils.utils.</code><codeclass="sig-name descname">get_all_typeclasses</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">parent</span><spanclass="o">=</span><spanclass="default_value">None</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/utils/utils.html#get_all_typeclasses"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.utils.utils.get_all_typeclasses"title="Permalink to this definition">¶</a></dt>
<dd><p>List available typeclasses from all available modules.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><p><strong>parent</strong> (<em>str</em><em>, </em><em>optional</em>) – If given, only return typeclasses inheriting
(at any distance) from this parent.</p>
</dd>
<dtclass="field-even">Returns</dt>
<ddclass="field-even"><p><em>dict</em>– On the form <strong>{“typeclass.path”: typeclass, …}</strong></p>
</dd>
</dl>
<pclass="rubric">Notes</p>
<p>This will dynamically retrieve all abstract django models inheriting at
any distance from the TypedObject base (aka a Typeclass) so it will
work fine with any custom classes being added.</p>
</dd></dl>
<dlclass="py function">
<dtid="evennia.utils.utils.get_all_cmdsets">
<codeclass="sig-prename descclassname">evennia.utils.utils.</code><codeclass="sig-name descname">get_all_cmdsets</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">parent</span><spanclass="o">=</span><spanclass="default_value">None</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/utils/utils.html#get_all_cmdsets"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.utils.utils.get_all_cmdsets"title="Permalink to this definition">¶</a></dt>
<dd><p>List available cmdsets from all available modules.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><p><strong>parent</strong> (<em>str</em><em>, </em><em>optional</em>) – If given, only return cmdsets inheriting (at
any distance) from this parent.</p>
</dd>
<dtclass="field-even">Returns</dt>
<ddclass="field-even"><p><em>dict</em>– On the form {“cmdset.path”: cmdset, …}</p>
</dd>
</dl>
<pclass="rubric">Notes</p>
<p>This will dynamically retrieve all abstract django models inheriting at
any distance from the CmdSet base so it will work fine with any custom
classes being added.</p>
</dd></dl>
<dlclass="py function">
<dtid="evennia.utils.utils.interactive">
<codeclass="sig-prename descclassname">evennia.utils.utils.</code><codeclass="sig-name descname">interactive</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">func</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/utils/utils.html#interactive"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.utils.utils.interactive"title="Permalink to this definition">¶</a></dt>
<dd><p>Decorator to make a method pausable with <strong>yield(seconds)</strong>
and able to ask for user-input with <strong>response=yield(question)</strong>.
For the question-asking to work, one of the args or kwargs to the
decorated function must be named ‘caller’.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Raises</dt>
<ddclass="field-odd"><ulclass="simple">
<li><p><strong>ValueError</strong>– If asking an interactive question but the decorated
function has no arg or kwarg named ‘caller’.</p></li>
<li><p><strong>ValueError</strong>– If passing non int/float to yield using for pausing.</p></li>
<spanclass="n">caller</span><spanclass="o">.</span><spanclass="n">msg</span><spanclass="p">(</span><spanclass="s2">"This is a test"</span><spanclass="p">)</span>
<spanclass="c1"># ask user (caller) a question</span>
<spanclass="n">response</span><spanclass="o">=</span><spanclass="k">yield</span><spanclass="p">(</span><spanclass="s2">"Do you want to continue waiting?"</span><spanclass="p">)</span>
<codeclass="sig-prename descclassname">evennia.utils.utils.</code><codeclass="sig-name descname">safe_convert_to_types</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">converters</span></em>, <emclass="sig-param"><spanclass="o">*</span><spanclass="n">args</span></em>, <emclass="sig-param"><spanclass="n">raise_errors</span><spanclass="o">=</span><spanclass="default_value">True</span></em>, <emclass="sig-param"><spanclass="o">**</span><spanclass="n">kwargs</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/utils/utils.html#safe_convert_to_types"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.utils.utils.safe_convert_to_types"title="Permalink to this definition">¶</a></dt>
<dd><p>Helper function to safely convert inputs to expected data types.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><ulclass="simple">
<li><p><strong>converters</strong> (<em>tuple</em>) – A tuple <strong>((converter, converter,…), {kwarg: converter, …})</strong> to
match a converter to each element in <strong>*args</strong> and <strong>**kwargs</strong>.
Each converter will will be called with the arg/kwarg-value as the only argument.
If there are too few converters given, the others will simply not be converter. If the
converter is given as the string ‘py’, it attempts to run
<strong>safe_eval</strong>/<strong>literal_eval</strong> on the input arg or kwarg value. It’s possible to
skip the arg/kwarg part of the tuple, an empty tuple/dict will then be assumed.</p></li>
<li><p><strong>*args</strong>– The arguments to convert with <strong>argtypes</strong>.</p></li>
<li><p><strong>raise_errors</strong> (<em>bool</em><em>, </em><em>optional</em>) – If set, raise any errors. This will
abort the conversion at that arg/kwarg. Otherwise, just skip the
conversion of the failing arg/kwarg. This will be set by the FuncParser if
this is used as a part of a FuncParser callable.</p></li>
<li><p><strong>**kwargs</strong>– The kwargs to convert with <strong>kwargtypes</strong></p></li>
</ul>
</dd>
<dtclass="field-even">Returns</dt>
<ddclass="field-even"><p><em>tuple</em>–<strong>(args, kwargs)</strong> in converted form.</p>
</dd>
<dtclass="field-odd">Raises</dt>
<ddclass="field-odd"><ulclass="simple">
<li><p><aclass="reference internal"href="evennia.utils.funcparser.html#evennia.utils.funcparser.ParsingError"title="evennia.utils.funcparser.ParsingError"><strong>utils.funcparser.ParsingError</strong></a>– If parsing failed in the <strong>‘py’</strong>
converter. This also makes this compatible with the FuncParser
interface.</p></li>
<li><p><strong>any</strong>– Any other exception raised from other converters, if raise_errors is True.</p></li>
</ul>
</dd>
</dl>
<pclass="rubric">Notes</p>
<p>This function is often used to validate/convert input from untrusted sources. For
security, the “py”-converter is deliberately limited and uses <strong>safe_eval</strong>/<strong>literal_eval</strong>
which only supports simple expressions or simple containers with literals. NEVER
use the python <strong>eval</strong> or <strong>exec</strong> methods as a converter for any untrusted input! Allowing
untrusted sources to execute arbitrary python on your server is a severe security risk,</p>
<codeclass="sig-prename descclassname">evennia.utils.utils.</code><codeclass="sig-name descname">strip_unsafe_input</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">txt</span></em>, <emclass="sig-param"><spanclass="n">session</span><spanclass="o">=</span><spanclass="default_value">None</span></em>, <emclass="sig-param"><spanclass="n">bypass_perms</span><spanclass="o">=</span><spanclass="default_value">None</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/utils/utils.html#strip_unsafe_input"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.utils.utils.strip_unsafe_input"title="Permalink to this definition">¶</a></dt>
<dd><p>Remove ‘unsafe’ text codes from text; these are used to elimitate
exploits in user-provided data, such as html-tags, line breaks etc.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><ulclass="simple">
<li><p><strong>txt</strong> (<em>str</em>) – The text to clean.</p></li>
<li><p><strong>session</strong> (<aclass="reference internal"href="evennia.server.session.html#evennia.server.session.Session"title="evennia.server.session.Session"><em>Session</em></a><em>, </em><em>optional</em>) – A Session in order to determine if
the check should be bypassed by permission (will be checked
with the ‘perm’ lock, taking permission hierarchies into account).</p></li>
<li><p><strong>bypass_perms</strong> (<em>list</em><em>, </em><em>optional</em>) – Iterable of permission strings
to check for bypassing the strip. If not given, use
<ddclass="field-even"><p><em>str</em>– The cleaned string.</p>
</dd>
</dl>
<pclass="rubric">Notes</p>
<p>The <strong>INPUT_CLEANUP_BYPASS_PERMISSIONS</strong> list defines what account
permissions are required to bypass this strip.</p>
</dd></dl>
<dlclass="py function">
<dtid="evennia.utils.utils.copy_word_case">
<codeclass="sig-prename descclassname">evennia.utils.utils.</code><codeclass="sig-name descname">copy_word_case</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">base_word</span></em>, <emclass="sig-param"><spanclass="n">new_word</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/utils/utils.html#copy_word_case"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.utils.utils.copy_word_case"title="Permalink to this definition">¶</a></dt>
<dd><p>Converts a word to use the same capitalization as a first word.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><ulclass="simple">
<li><p><strong>base_word</strong> (<em>str</em>) – A word to get the capitalization from.</p></li>
<li><p><strong>new_word</strong> (<em>str</em>) – A new word to capitalize in the same way as <strong>base_word</strong>.</p></li>
</ul>
</dd>
<dtclass="field-even">Returns</dt>
<ddclass="field-even"><p><em>str</em>– The <strong>new_word</strong> with capitalization matching the first word.</p>
</dd>
</dl>
<pclass="rubric">Notes</p>
<p>This is meant for words. Longer sentences may get unexpected results.</p>
<p>If the two words have a mix of capital/lower letters _and_ <strong>new_word</strong>
is longer than <strong>base_word</strong>, the excess will retain its original case.</p>
</dd></dl>
<dlclass="py function">
<dtid="evennia.utils.utils.run_in_main_thread">
<codeclass="sig-prename descclassname">evennia.utils.utils.</code><codeclass="sig-name descname">run_in_main_thread</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">function_or_method</span></em>, <emclass="sig-param"><spanclass="o">*</span><spanclass="n">args</span></em>, <emclass="sig-param"><spanclass="o">**</span><spanclass="n">kwargs</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/utils/utils.html#run_in_main_thread"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.utils.utils.run_in_main_thread"title="Permalink to this definition">¶</a></dt>
<dd><p>Force a callable to execute in the main Evennia thread. This is only relevant when
calling code from e.g. web views, which run in a separate threadpool. Use this
to avoid race conditions.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><ulclass="simple">
<li><p><strong>function_or_method</strong> (<em>callable</em>) – A function or method to fire.</p></li>
<li><p><strong>*args</strong>– Will be passed into the callable.</p></li>
<li><p><strong>**kwargs</strong>– Will be passed into the callable.</p></li>
</ul>
</dd>
</dl>
</dd></dl>
<dlclass="py function">
<dtid="evennia.utils.utils.int2str">
<codeclass="sig-prename descclassname">evennia.utils.utils.</code><codeclass="sig-name descname">int2str</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">number</span></em>, <emclass="sig-param"><spanclass="n">adjective</span><spanclass="o">=</span><spanclass="default_value">False</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/utils/utils.html#int2str"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.utils.utils.int2str"title="Permalink to this definition">¶</a></dt>
<dd><p>Convert a number to an English string for better display; so 1 -> one, 2 -> two etc
up until 12, after which it will be ‘13’, ‘14’ etc.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><ulclass="simple">
<li><p><strong>number</strong> (<em>int</em>) – The number to convert. Floats will be converted to ints.</p></li>
<li><p><strong>adjective</strong> (<em>int</em>) – If set, map 1->1st, 2->2nd etc. If unset, map 1->one, 2->two etc.
up to twelve.</p></li>
</ul>
</dd>
<dtclass="field-even">Returns</dt>
<ddclass="field-even"><p><em>str</em>– The number expressed as a string.</p>
</dd>
</dl>
</dd></dl>
<dlclass="py function">
<dtid="evennia.utils.utils.str2int">
<codeclass="sig-prename descclassname">evennia.utils.utils.</code><codeclass="sig-name descname">str2int</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">number</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/utils/utils.html#str2int"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.utils.utils.str2int"title="Permalink to this definition">¶</a></dt>
<dd><p>Converts a string to an integer.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><p><strong>number</strong> (<em>str</em>) – The string to convert. It can be a digit such as “1”, or a number word such as “one”.</p>
</dd>
<dtclass="field-even">Returns</dt>
<ddclass="field-even"><p><em>int</em>– The string represented as an integer.</p>
<codeclass="sig-prename descclassname">evennia.utils.utils.</code><codeclass="sig-name descname">match_ip</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">address</span></em>, <emclass="sig-param"><spanclass="n">pattern</span></em><spanclass="sig-paren">)</span>→ bool<aclass="reference internal"href="../_modules/evennia/utils/utils.html#match_ip"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.utils.utils.match_ip"title="Permalink to this definition">¶</a></dt>
<dd><p>Check if an IP address matches a given pattern. The pattern can be a single IP address
such as 8.8.8.8 or a CIDR-formatted subnet like 10.0.0.0/8</p>
<p>IPv6 is supported to, with CIDR-subnets looking like 2001:db8::/48</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><ulclass="simple">
<li><p><strong>address</strong> (<em>str</em>) – The source address being checked.</p></li>
<li><p><strong>pattern</strong> (<em>str</em>) – The single IP address or subnet to check against.</p></li>
</ul>
</dd>
<dtclass="field-even">Returns</dt>
<ddclass="field-even"><p><em>result (bool)</em>– Whether it was a match or not.</p>
</dd>
</dl>
</dd></dl>
<dlclass="py function">
<dtid="evennia.utils.utils.ip_from_request">
<codeclass="sig-prename descclassname">evennia.utils.utils.</code><codeclass="sig-name descname">ip_from_request</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">request</span></em>, <emclass="sig-param"><spanclass="n">exclude</span><spanclass="o">=</span><spanclass="default_value">None</span></em><spanclass="sig-paren">)</span>→ str<aclass="reference internal"href="../_modules/evennia/utils/utils.html#ip_from_request"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.utils.utils.ip_from_request"title="Permalink to this definition">¶</a></dt>
<dd><p>Retrieves the IP address from a web Request, while respecting X-Forwarded-For and
settings.UPSTREAM_IPS.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><ulclass="simple">
<li><p><strong>request</strong> (<em>django Request</em><em> or </em><em>twisted.web.http.Request</em>) – The web request.</p></li>
<li><p><strong>exclude</strong>– (list, optional): A list of IP addresses to exclude from the check. If left none,
then settings.UPSTREAM_IPS will be used.</p></li>
</ul>
</dd>
<dtclass="field-even">Returns</dt>
<ddclass="field-even"><p><em>ip (str)</em>– The IP address the request originated from.</p>