%PDF- %PDF-
| Direktori : /proc/thread-self/root/usr/share/doc/python3-routes/html/modules/ |
| Current File : //proc/thread-self/root/usr/share/doc/python3-routes/html/modules/routes.html |
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />
<title>routes – Routes Common Classes and Functions — Routes 2.5.0 documentation</title>
<link rel="stylesheet" type="text/css" href="../_static/pygments.css" />
<link rel="stylesheet" type="text/css" href="../_static/classic.css" />
<script data-url_root="../" id="documentation_options" src="../_static/documentation_options.js"></script>
<script src="../_static/jquery.js"></script>
<script src="../_static/underscore.js"></script>
<script src="../_static/doctools.js"></script>
<link rel="index" title="Index" href="../genindex.html" />
<link rel="search" title="Search" href="../search.html" />
<link rel="next" title="routes.mapper – Mapper and Sub-Mapper" href="mapper.html" />
<link rel="prev" title="Routes Modules" href="index.html" />
</head><body>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="mapper.html" title="routes.mapper – Mapper and Sub-Mapper"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="index.html" title="Routes Modules"
accesskey="P">previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../index.html">Routes 2.5.0 documentation</a> »</li>
<li class="nav-item nav-item-1"><a href="index.html" accesskey="U">Routes Modules</a> »</li>
<li class="nav-item nav-item-this"><a href=""><code class="xref py py-mod docutils literal notranslate"><span class="pre">routes</span></code> – Routes Common Classes and Functions</a></li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<section id="module-routes">
<span id="routes-routes-common-classes-and-functions"></span><h1><a class="reference internal" href="#module-routes" title="routes"><code class="xref py py-mod docutils literal notranslate"><span class="pre">routes</span></code></a> – Routes Common Classes and Functions<a class="headerlink" href="#module-routes" title="Permalink to this headline">¶</a></h1>
<p>Provides common classes and functions most users will want access to.</p>
<section id="module-contents">
<h2>Module Contents<a class="headerlink" href="#module-contents" title="Permalink to this headline">¶</a></h2>
<dl class="py function">
<dt class="sig sig-object py" id="routes.request_config">
<span class="sig-prename descclassname"><span class="pre">routes.</span></span><span class="sig-name descname"><span class="pre">request_config</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">original</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#routes.request_config" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the Routes RequestConfig object.</p>
<p>To get the Routes RequestConfig:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">from</span> <span class="nn">routes</span> <span class="kn">import</span> <span class="o">*</span>
<span class="gp">>>> </span><span class="n">config</span> <span class="o">=</span> <span class="n">request_config</span><span class="p">()</span>
</pre></div>
</div>
<p>The following attributes must be set on the config object every request:</p>
<dl>
<dt>mapper</dt><dd><p>mapper should be a Mapper instance thats ready for use</p>
</dd>
<dt>host</dt><dd><p>host is the hostname of the webapp</p>
</dd>
<dt>protocol</dt><dd><p>protocol is the protocol of the current request</p>
</dd>
<dt>mapper_dict</dt><dd><p>mapper_dict should be the dict returned by mapper.match()</p>
</dd>
<dt>redirect</dt><dd><p>redirect should be a function that issues a redirect,
and takes a url as the sole argument</p>
</dd>
<dt>prefix (optional)</dt><dd><p>Set if the application is moved under a URL prefix. Prefix
will be stripped before matching, and prepended on generation</p>
</dd>
<dt>environ (optional)</dt><dd><p>Set to the WSGI environ for automatic prefix support if the
webapp is underneath a ‘SCRIPT_NAME’</p>
<p>Setting the environ will use information in environ to try and
populate the host/protocol/mapper_dict options if you’ve already
set a mapper.</p>
</dd>
</dl>
<p><strong>Using your own requst local</strong></p>
<p>If you have your own request local object that you’d like to use instead
of the default thread local provided by Routes, you can configure Routes
to use it:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">routes</span> <span class="kn">import</span> <span class="n">request_config</span><span class="p">()</span>
<span class="n">config</span> <span class="o">=</span> <span class="n">request_config</span><span class="p">()</span>
<span class="k">if</span> <span class="nb">hasattr</span><span class="p">(</span><span class="n">config</span><span class="p">,</span> <span class="s1">'using_request_local'</span><span class="p">):</span>
<span class="n">config</span><span class="o">.</span><span class="n">request_local</span> <span class="o">=</span> <span class="n">YourLocalCallable</span>
<span class="n">config</span> <span class="o">=</span> <span class="n">request_config</span><span class="p">()</span>
</pre></div>
</div>
<p>Once you have configured request_config, its advisable you retrieve it
again to get the object you wanted. The variable you assign to
request_local is assumed to be a callable that will get the local config
object you wish.</p>
<p>This example tests for the presence of the ‘using_request_local’ attribute
which will be present if you haven’t assigned it yet. This way you can
avoid repeat assignments of the request specific callable.</p>
<p>Should you want the original object, perhaps to change the callable its
using or stop this behavior, call request_config(original=True).</p>
</dd></dl>
<dl class="py class">
<dt class="sig sig-object py" id="routes._RequestConfig">
<em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">routes.</span></span><span class="sig-name descname"><span class="pre">_RequestConfig</span></span><a class="headerlink" href="#routes._RequestConfig" title="Permalink to this definition">¶</a></dt>
<dd><p>RequestConfig thread-local singleton</p>
<p>The Routes RequestConfig object is a thread-local singleton that should
be initialized by the web framework that is utilizing Routes.</p>
<dl class="py method">
<dt class="sig sig-object py" id="routes._RequestConfig.load_wsgi_environ">
<span class="sig-name descname"><span class="pre">load_wsgi_environ</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">environ</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#routes._RequestConfig.load_wsgi_environ" title="Permalink to this definition">¶</a></dt>
<dd><p>Load the protocol/server info from the environ and store it.
Also, match the incoming URL if there’s already a mapper, and
store the resulting match dict in mapper_dict.</p>
</dd></dl>
</dd></dl>
</section>
</section>
<div class="clearer"></div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<h3><a href="../index.html">Table of Contents</a></h3>
<ul>
<li><a class="reference internal" href="#"><code class="xref py py-mod docutils literal notranslate"><span class="pre">routes</span></code> – Routes Common Classes and Functions</a><ul>
<li><a class="reference internal" href="#module-contents">Module Contents</a></li>
</ul>
</li>
</ul>
<h4>Previous topic</h4>
<p class="topless"><a href="index.html"
title="previous chapter">Routes Modules</a></p>
<h4>Next topic</h4>
<p class="topless"><a href="mapper.html"
title="next chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">routes.mapper</span></code> – Mapper and Sub-Mapper</a></p>
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="../_sources/modules/routes.rst.txt"
rel="nofollow">Show Source</a></li>
</ul>
</div>
<div id="searchbox" style="display: none" role="search">
<h3 id="searchlabel">Quick search</h3>
<div class="searchformwrapper">
<form class="search" action="../search.html" method="get">
<input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/>
<input type="submit" value="Go" />
</form>
</div>
</div>
<script>$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="mapper.html" title="routes.mapper – Mapper and Sub-Mapper"
>next</a> |</li>
<li class="right" >
<a href="index.html" title="Routes Modules"
>previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../index.html">Routes 2.5.0 documentation</a> »</li>
<li class="nav-item nav-item-1"><a href="index.html" >Routes Modules</a> »</li>
<li class="nav-item nav-item-this"><a href=""><code class="xref py py-mod docutils literal notranslate"><span class="pre">routes</span></code> – Routes Common Classes and Functions</a></li>
</ul>
</div>
<div class="footer" role="contentinfo">
© Copyright 2005-2022, Ben Bangert, Mike Orr, and numerous contributers.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 4.3.2.
</div>
</body>
</html>