<spanid="evennia-server-throttle"></span><h1>evennia.server.throttle<aclass="headerlink"href="#module-evennia.server.throttle"title="Permalink to this headline">¶</a></h1>
<dlclass="py class">
<dtid="evennia.server.throttle.Throttle">
<emclass="property">class </em><codeclass="sig-prename descclassname">evennia.server.throttle.</code><codeclass="sig-name descname">Throttle</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="o">**</span><spanclass="n">kwargs</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/server/throttle.html#Throttle"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.server.throttle.Throttle"title="Permalink to this definition">¶</a></dt>
<codeclass="sig-name descname">error_msg</code><emclass="property"> = 'Too many failed attempts; you must wait a few minutes before trying again.'</em><aclass="headerlink"href="#evennia.server.throttle.Throttle.error_msg"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">kwargs</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/server/throttle.html#Throttle.__init__"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.server.throttle.Throttle.__init__"title="Permalink to this definition">¶</a></dt>
<dd><p>Allows setting of throttle parameters.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Keyword Arguments</dt>
<ddclass="field-odd"><ulclass="simple">
<li><p><strong>name</strong> (<em>str</em>) – Name of this throttle.</p></li>
<li><p><strong>limit</strong> (<em>int</em>) – Max number of failures before imposing limiter. If <strong>None</strong>,
the throttle is disabled.</p></li>
<li><p><strong>timeout</strong> (<em>int</em>) – number of timeout seconds after
max number of tries has been reached.</p></li>
<li><p><strong>cache_size</strong> (<em>int</em>) – Max number of attempts to record per IP within a
rolling window; this is NOT the same as the limit after which
<codeclass="sig-name descname">get_cache_key</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/server/throttle.html#Throttle.get_cache_key"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.server.throttle.Throttle.get_cache_key"title="Permalink to this definition">¶</a></dt>
<dd><p>Creates a ‘prefixed’ key containing arbitrary terms to prevent key
collisions in the same namespace.</p>
</dd></dl>
<dlclass="py method">
<dtid="evennia.server.throttle.Throttle.touch">
<codeclass="sig-name descname">touch</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">key</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/server/throttle.html#Throttle.touch"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.server.throttle.Throttle.touch"title="Permalink to this definition">¶</a></dt>
<dd><p>Refreshes the timeout on a given key and ensures it is recorded in the
key register.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><p><strong>key</strong> (<em>str</em>) – Key of entry to renew.</p>
</dd>
</dl>
</dd></dl>
<dlclass="py method">
<dtid="evennia.server.throttle.Throttle.get">
<codeclass="sig-name descname">get</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">ip</span><spanclass="o">=</span><spanclass="default_value">None</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/server/throttle.html#Throttle.get"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.server.throttle.Throttle.get"title="Permalink to this definition">¶</a></dt>
<dd><p>Convenience function that returns the storage table, or part of.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><p><strong>ip</strong> (<em>str</em><em>, </em><em>optional</em>) – IP address of requestor</p>
<dt>When no IP is provided, returns a dict of all</dt><dd><p>current IPs being tracked and the timestamps of their recent
failures.</p>
</dd>
<dt>timestamps (deque): When an IP is provided, returns a deque of</dt><dd><p>timestamps of recent failures only for that IP.</p>
</dd>
</dl>
</p>
</dd>
</dl>
</dd></dl>
<dlclass="py method">
<dtid="evennia.server.throttle.Throttle.update">
<codeclass="sig-name descname">update</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">ip</span></em>, <emclass="sig-param"><spanclass="n">failmsg</span><spanclass="o">=</span><spanclass="default_value">'Exceeded threshold.'</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/server/throttle.html#Throttle.update"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.server.throttle.Throttle.update"title="Permalink to this definition">¶</a></dt>
<dd><p>Store the time of the latest failure.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><ulclass="simple">
<li><p><strong>ip</strong> (<em>str</em>) – IP address of requestor</p></li>
<li><p><strong>failmsg</strong> (<em>str</em><em>, </em><em>optional</em>) – Message to display in logs upon activation
of throttle.</p></li>
</ul>
</dd>
<dtclass="field-even">Returns</dt>
<ddclass="field-even"><p>None</p>
</dd>
</dl>
</dd></dl>
<dlclass="py method">
<dtid="evennia.server.throttle.Throttle.remove">
<codeclass="sig-name descname">remove</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">ip</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/server/throttle.html#Throttle.remove"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.server.throttle.Throttle.remove"title="Permalink to this definition">¶</a></dt>
<dd><p>Clears data stored for an IP from the throttle.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><p><strong>ip</strong> (<em>str</em>) – IP to clear.</p>
<codeclass="sig-name descname">record_ip</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">ip</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/server/throttle.html#Throttle.record_ip"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.server.throttle.Throttle.record_ip"title="Permalink to this definition">¶</a></dt>
<dd><p>Tracks keys as they are added to the cache (since there is no way to
get a list of keys after-the-fact).</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><p><strong>ip</strong> (<em>str</em>) – IP being added to cache. This should be the original
<codeclass="sig-name descname">unrecord_ip</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">ip</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/server/throttle.html#Throttle.unrecord_ip"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.server.throttle.Throttle.unrecord_ip"title="Permalink to this definition">¶</a></dt>
<dd><p>Forces removal of a key from the key registry.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><p><strong>ip</strong> (<em>str</em>) – IP to remove from list of keys.</p>
</dd>
</dl>
</dd></dl>
<dlclass="py method">
<dtid="evennia.server.throttle.Throttle.check">
<codeclass="sig-name descname">check</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">ip</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/server/throttle.html#Throttle.check"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.server.throttle.Throttle.check"title="Permalink to this definition">¶</a></dt>
<dd><p>This will check the session’s address against the
storage dictionary to check they haven’t spammed too many
fails recently.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><p><strong>ip</strong> (<em>str</em>) – IP address of requestor</p>