%PDF- %PDF-
Direktori : /usr/share/doc/python3-routes/html/modules/ |
Current File : //usr/share/doc/python3-routes/html/modules/mapper.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.mapper – Mapper and Sub-Mapper — 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.route – Route" href="route.html" /> <link rel="prev" title="routes – Routes Common Classes and Functions" href="routes.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="route.html" title="routes.route – Route" accesskey="N">next</a> |</li> <li class="right" > <a href="routes.html" title="routes – Routes Common Classes and Functions" 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.mapper</span></code> – Mapper and Sub-Mapper</a></li> </ul> </div> <div class="document"> <div class="documentwrapper"> <div class="bodywrapper"> <div class="body" role="main"> <section id="module-routes.mapper"> <span id="routes-mapper-mapper-and-sub-mapper"></span><h1><a class="reference internal" href="#module-routes.mapper" title="routes.mapper"><code class="xref py py-mod docutils literal notranslate"><span class="pre">routes.mapper</span></code></a> – Mapper and Sub-Mapper<a class="headerlink" href="#module-routes.mapper" title="Permalink to this headline">¶</a></h1> <p>Mapper and Sub-Mapper</p> <section id="module-contents"> <h2>Module Contents<a class="headerlink" href="#module-contents" title="Permalink to this headline">¶</a></h2> <dl class="py class"> <dt class="sig sig-object py" id="routes.mapper.SubMapperParent"> <em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">routes.mapper.</span></span><span class="sig-name descname"><span class="pre">SubMapperParent</span></span><a class="headerlink" href="#routes.mapper.SubMapperParent" title="Permalink to this definition">¶</a></dt> <dd><p>Base class for Mapper and SubMapper, both of which may be the parent of SubMapper objects</p> <dl class="py method"> <dt class="sig sig-object py" id="routes.mapper.SubMapperParent.collection"> <span class="sig-name descname"><span class="pre">collection</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">collection_name</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">resource_name</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">path_prefix</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">member_prefix</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'/{id}'</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">controller</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">collection_actions</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">['index',</span> <span class="pre">'create',</span> <span class="pre">'new']</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">member_actions</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">['show',</span> <span class="pre">'update',</span> <span class="pre">'delete',</span> <span class="pre">'edit']</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">member_options</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#routes.mapper.SubMapperParent.collection" title="Permalink to this definition">¶</a></dt> <dd><p>Create a submapper that represents a collection.</p> <p>This results in a <a class="reference internal" href="#routes.mapper.SubMapper" title="routes.mapper.SubMapper"><code class="xref py py-class docutils literal notranslate"><span class="pre">routes.mapper.SubMapper</span></code></a> object, with a <code class="docutils literal notranslate"><span class="pre">member</span></code> property of the same type that represents the collection’s member resources.</p> <p>Its interface is the same as the <code class="docutils literal notranslate"><span class="pre">submapper</span></code> together with <code class="docutils literal notranslate"><span class="pre">member_prefix</span></code>, <code class="docutils literal notranslate"><span class="pre">member_actions</span></code> and <code class="docutils literal notranslate"><span class="pre">member_options</span></code> which are passed to the <code class="docutils literal notranslate"><span class="pre">member</span></code> submapper as <code class="docutils literal notranslate"><span class="pre">path_prefix</span></code>, <code class="docutils literal notranslate"><span class="pre">actions</span></code> and keyword arguments respectively.</p> <p>Example:</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">from</span> <span class="nn">routes.util</span> <span class="kn">import</span> <span class="n">url_for</span> <span class="gp">>>> </span><span class="nb">map</span> <span class="o">=</span> <span class="n">Mapper</span><span class="p">(</span><span class="n">controller_scan</span><span class="o">=</span><span class="kc">None</span><span class="p">)</span> <span class="gp">>>> </span><span class="n">c</span> <span class="o">=</span> <span class="nb">map</span><span class="o">.</span><span class="n">collection</span><span class="p">(</span><span class="s1">'entries'</span><span class="p">,</span> <span class="s1">'entry'</span><span class="p">)</span> <span class="gp">>>> </span><span class="n">c</span><span class="o">.</span><span class="n">member</span><span class="o">.</span><span class="n">link</span><span class="p">(</span><span class="s1">'ping'</span><span class="p">,</span> <span class="n">method</span><span class="o">=</span><span class="s1">'POST'</span><span class="p">)</span> <span class="gp">>>> </span><span class="n">url_for</span><span class="p">(</span><span class="s1">'entries'</span><span class="p">)</span> <span class="o">==</span> <span class="s1">'/entries'</span> <span class="go">True</span> <span class="gp">>>> </span><span class="n">url_for</span><span class="p">(</span><span class="s1">'edit_entry'</span><span class="p">,</span> <span class="nb">id</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span> <span class="o">==</span> <span class="s1">'/entries/1/edit'</span> <span class="go">True</span> <span class="gp">>>> </span><span class="n">url_for</span><span class="p">(</span><span class="s1">'ping_entry'</span><span class="p">,</span> <span class="nb">id</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span> <span class="o">==</span> <span class="s1">'/entries/1/ping'</span> <span class="go">True</span> </pre></div> </div> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="routes.mapper.SubMapperParent.submapper"> <span class="sig-name descname"><span class="pre">submapper</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kargs</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#routes.mapper.SubMapperParent.submapper" title="Permalink to this definition">¶</a></dt> <dd><p>Create a partial version of the Mapper with the designated options set</p> <p>This results in a <a class="reference internal" href="#routes.mapper.SubMapper" title="routes.mapper.SubMapper"><code class="xref py py-class docutils literal notranslate"><span class="pre">routes.mapper.SubMapper</span></code></a> object.</p> <p>If keyword arguments provided to this method also exist in the keyword arguments provided to the submapper, their values will be merged with the saved options going first.</p> <p>In addition to <a class="reference internal" href="route.html#routes.route.Route" title="routes.route.Route"><code class="xref py py-class docutils literal notranslate"><span class="pre">routes.route.Route</span></code></a> arguments, submapper can also take a <code class="docutils literal notranslate"><span class="pre">path_prefix</span></code> argument which will be prepended to the path of all routes that are connected.</p> <p>Example:</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="nb">map</span> <span class="o">=</span> <span class="n">Mapper</span><span class="p">(</span><span class="n">controller_scan</span><span class="o">=</span><span class="kc">None</span><span class="p">)</span> <span class="gp">>>> </span><span class="nb">map</span><span class="o">.</span><span class="n">connect</span><span class="p">(</span><span class="s1">'home'</span><span class="p">,</span> <span class="s1">'/'</span><span class="p">,</span> <span class="n">controller</span><span class="o">=</span><span class="s1">'home'</span><span class="p">,</span> <span class="n">action</span><span class="o">=</span><span class="s1">'splash'</span><span class="p">)</span> <span class="gp">>>> </span><span class="nb">map</span><span class="o">.</span><span class="n">matchlist</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">name</span> <span class="o">==</span> <span class="s1">'home'</span> <span class="go">True</span> <span class="gp">>>> </span><span class="n">m</span> <span class="o">=</span> <span class="nb">map</span><span class="o">.</span><span class="n">submapper</span><span class="p">(</span><span class="n">controller</span><span class="o">=</span><span class="s1">'home'</span><span class="p">)</span> <span class="gp">>>> </span><span class="n">m</span><span class="o">.</span><span class="n">connect</span><span class="p">(</span><span class="s1">'index'</span><span class="p">,</span> <span class="s1">'/index'</span><span class="p">,</span> <span class="n">action</span><span class="o">=</span><span class="s1">'index'</span><span class="p">)</span> <span class="gp">>>> </span><span class="nb">map</span><span class="o">.</span><span class="n">matchlist</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">name</span> <span class="o">==</span> <span class="s1">'index'</span> <span class="go">True</span> <span class="gp">>>> </span><span class="nb">map</span><span class="o">.</span><span class="n">matchlist</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">defaults</span><span class="p">[</span><span class="s1">'controller'</span><span class="p">]</span> <span class="o">==</span> <span class="s1">'home'</span> <span class="go">True</span> </pre></div> </div> <p>Optional <code class="docutils literal notranslate"><span class="pre">collection_name</span></code> and <code class="docutils literal notranslate"><span class="pre">resource_name</span></code> arguments are used in the generation of route names by the <code class="docutils literal notranslate"><span class="pre">action</span></code> and <code class="docutils literal notranslate"><span class="pre">link</span></code> methods. These in turn are used by the <code class="docutils literal notranslate"><span class="pre">index</span></code>, <code class="docutils literal notranslate"><span class="pre">new</span></code>, <code class="docutils literal notranslate"><span class="pre">create</span></code>, <code class="docutils literal notranslate"><span class="pre">show</span></code>, <code class="docutils literal notranslate"><span class="pre">edit</span></code>, <code class="docutils literal notranslate"><span class="pre">update</span></code> and <code class="docutils literal notranslate"><span class="pre">delete</span></code> methods which may be invoked indirectly by listing them in the <code class="docutils literal notranslate"><span class="pre">actions</span></code> argument. If the <code class="docutils literal notranslate"><span class="pre">formatted</span></code> argument is set to <code class="docutils literal notranslate"><span class="pre">True</span></code> (the default), generated paths are given the suffix ‘{.format}’ which matches or generates an optional format extension.</p> <p>Example:</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">from</span> <span class="nn">routes.util</span> <span class="kn">import</span> <span class="n">url_for</span> <span class="gp">>>> </span><span class="nb">map</span> <span class="o">=</span> <span class="n">Mapper</span><span class="p">(</span><span class="n">controller_scan</span><span class="o">=</span><span class="kc">None</span><span class="p">)</span> <span class="gp">>>> </span><span class="n">m</span> <span class="o">=</span> <span class="nb">map</span><span class="o">.</span><span class="n">submapper</span><span class="p">(</span><span class="n">path_prefix</span><span class="o">=</span><span class="s1">'/entries'</span><span class="p">,</span> <span class="n">collection_name</span><span class="o">=</span><span class="s1">'entries'</span><span class="p">,</span> <span class="n">resource_name</span><span class="o">=</span><span class="s1">'entry'</span><span class="p">,</span> <span class="n">actions</span><span class="o">=</span><span class="p">[</span><span class="s1">'index'</span><span class="p">,</span> <span class="s1">'new'</span><span class="p">])</span> <span class="gp">>>> </span><span class="n">url_for</span><span class="p">(</span><span class="s1">'entries'</span><span class="p">)</span> <span class="o">==</span> <span class="s1">'/entries'</span> <span class="go">True</span> <span class="gp">>>> </span><span class="n">url_for</span><span class="p">(</span><span class="s1">'new_entry'</span><span class="p">,</span> <span class="nb">format</span><span class="o">=</span><span class="s1">'xml'</span><span class="p">)</span> <span class="o">==</span> <span class="s1">'/entries/new.xml'</span> <span class="go">True</span> </pre></div> </div> </dd></dl> </dd></dl> <dl class="py class"> <dt class="sig sig-object py" id="routes.mapper.SubMapper"> <em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">routes.mapper.</span></span><span class="sig-name descname"><span class="pre">SubMapper</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">obj</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">resource_name</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">collection_name</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">actions</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">formatted</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#routes.mapper.SubMapper" title="Permalink to this definition">¶</a></dt> <dd><p>Partial mapper for use with_options</p> <dl class="py method"> <dt class="sig sig-object py" id="routes.mapper.SubMapper.action"> <span class="sig-name descname"><span class="pre">action</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">action</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">method</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'GET'</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">formatted</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#routes.mapper.SubMapper.action" title="Permalink to this definition">¶</a></dt> <dd><p>Generates a named route at the base path of a submapper.</p> <p>Example:</p> <div class="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="n">url_for</span> <span class="gp">>>> </span><span class="nb">map</span> <span class="o">=</span> <span class="n">Mapper</span><span class="p">(</span><span class="n">controller_scan</span><span class="o">=</span><span class="kc">None</span><span class="p">)</span> <span class="gp">>>> </span><span class="n">c</span> <span class="o">=</span> <span class="nb">map</span><span class="o">.</span><span class="n">submapper</span><span class="p">(</span><span class="n">path_prefix</span><span class="o">=</span><span class="s1">'/entries'</span><span class="p">,</span> <span class="n">controller</span><span class="o">=</span><span class="s1">'entry'</span><span class="p">)</span> <span class="gp">>>> </span><span class="n">c</span><span class="o">.</span><span class="n">action</span><span class="p">(</span><span class="n">action</span><span class="o">=</span><span class="s1">'index'</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="s1">'entries'</span><span class="p">,</span> <span class="n">formatted</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span> <span class="gp">>>> </span><span class="n">c</span><span class="o">.</span><span class="n">action</span><span class="p">(</span><span class="n">action</span><span class="o">=</span><span class="s1">'create'</span><span class="p">,</span> <span class="n">method</span><span class="o">=</span><span class="s1">'POST'</span><span class="p">)</span> <span class="gp">>>> </span><span class="n">url_for</span><span class="p">(</span><span class="n">controller</span><span class="o">=</span><span class="s1">'entry'</span><span class="p">,</span> <span class="n">action</span><span class="o">=</span><span class="s1">'index'</span><span class="p">,</span> <span class="n">method</span><span class="o">=</span><span class="s1">'GET'</span><span class="p">)</span> <span class="o">==</span> <span class="s1">'/entries'</span> <span class="go">True</span> <span class="gp">>>> </span><span class="n">url_for</span><span class="p">(</span><span class="n">controller</span><span class="o">=</span><span class="s1">'entry'</span><span class="p">,</span> <span class="n">action</span><span class="o">=</span><span class="s1">'index'</span><span class="p">,</span> <span class="n">method</span><span class="o">=</span><span class="s1">'GET'</span><span class="p">,</span> <span class="nb">format</span><span class="o">=</span><span class="s1">'xml'</span><span class="p">)</span> <span class="o">==</span> <span class="s1">'/entries.xml'</span> <span class="go">True</span> <span class="gp">>>> </span><span class="n">url_for</span><span class="p">(</span><span class="n">controller</span><span class="o">=</span><span class="s1">'entry'</span><span class="p">,</span> <span class="n">action</span><span class="o">=</span><span class="s1">'create'</span><span class="p">,</span> <span class="n">method</span><span class="o">=</span><span class="s1">'POST'</span><span class="p">)</span> <span class="o">==</span> <span class="s1">'/entries'</span> <span class="go">True</span> </pre></div> </div> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="routes.mapper.SubMapper.add_actions"> <span class="sig-name descname"><span class="pre">add_actions</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">actions</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#routes.mapper.SubMapper.add_actions" title="Permalink to this definition">¶</a></dt> <dd></dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="routes.mapper.SubMapper.connect"> <span class="sig-name descname"><span class="pre">connect</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">routename</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">path</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#routes.mapper.SubMapper.connect" title="Permalink to this definition">¶</a></dt> <dd></dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="routes.mapper.SubMapper.create"> <span class="sig-name descname"><span class="pre">create</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#routes.mapper.SubMapper.create" title="Permalink to this definition">¶</a></dt> <dd><p>Generates the “create” action for a collection submapper.</p> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="routes.mapper.SubMapper.delete"> <span class="sig-name descname"><span class="pre">delete</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#routes.mapper.SubMapper.delete" title="Permalink to this definition">¶</a></dt> <dd><p>Generates the “delete” action for a collection member submapper.</p> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="routes.mapper.SubMapper.edit"> <span class="sig-name descname"><span class="pre">edit</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#routes.mapper.SubMapper.edit" title="Permalink to this definition">¶</a></dt> <dd><p>Generates the “edit” link for a collection member submapper.</p> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="routes.mapper.SubMapper.index"> <span class="sig-name descname"><span class="pre">index</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#routes.mapper.SubMapper.index" title="Permalink to this definition">¶</a></dt> <dd><p>Generates the “index” action for a collection submapper.</p> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="routes.mapper.SubMapper.link"> <span class="sig-name descname"><span class="pre">link</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">rel</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">name</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">action</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">method</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'GET'</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">formatted</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#routes.mapper.SubMapper.link" title="Permalink to this definition">¶</a></dt> <dd><p>Generates a named route for a subresource.</p> <p>Example:</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">from</span> <span class="nn">routes.util</span> <span class="kn">import</span> <span class="n">url_for</span> <span class="gp">>>> </span><span class="nb">map</span> <span class="o">=</span> <span class="n">Mapper</span><span class="p">(</span><span class="n">controller_scan</span><span class="o">=</span><span class="kc">None</span><span class="p">)</span> <span class="gp">>>> </span><span class="n">c</span> <span class="o">=</span> <span class="nb">map</span><span class="o">.</span><span class="n">collection</span><span class="p">(</span><span class="s1">'entries'</span><span class="p">,</span> <span class="s1">'entry'</span><span class="p">)</span> <span class="gp">>>> </span><span class="n">c</span><span class="o">.</span><span class="n">link</span><span class="p">(</span><span class="s1">'recent'</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="s1">'recent_entries'</span><span class="p">)</span> <span class="gp">>>> </span><span class="n">c</span><span class="o">.</span><span class="n">member</span><span class="o">.</span><span class="n">link</span><span class="p">(</span><span class="s1">'ping'</span><span class="p">,</span> <span class="n">method</span><span class="o">=</span><span class="s1">'POST'</span><span class="p">,</span> <span class="n">formatted</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span> <span class="gp">>>> </span><span class="n">url_for</span><span class="p">(</span><span class="s1">'entries'</span><span class="p">)</span> <span class="o">==</span> <span class="s1">'/entries'</span> <span class="go">True</span> <span class="gp">>>> </span><span class="n">url_for</span><span class="p">(</span><span class="s1">'recent_entries'</span><span class="p">)</span> <span class="o">==</span> <span class="s1">'/entries/recent'</span> <span class="go">True</span> <span class="gp">>>> </span><span class="n">url_for</span><span class="p">(</span><span class="s1">'ping_entry'</span><span class="p">,</span> <span class="nb">id</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span> <span class="o">==</span> <span class="s1">'/entries/1/ping'</span> <span class="go">True</span> <span class="gp">>>> </span><span class="n">url_for</span><span class="p">(</span><span class="s1">'ping_entry'</span><span class="p">,</span> <span class="nb">id</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span> <span class="nb">format</span><span class="o">=</span><span class="s1">'xml'</span><span class="p">)</span> <span class="o">==</span> <span class="s1">'/entries/1/ping.xml'</span> <span class="go">True</span> </pre></div> </div> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="routes.mapper.SubMapper.new"> <span class="sig-name descname"><span class="pre">new</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#routes.mapper.SubMapper.new" title="Permalink to this definition">¶</a></dt> <dd><p>Generates the “new” link for a collection submapper.</p> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="routes.mapper.SubMapper.show"> <span class="sig-name descname"><span class="pre">show</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#routes.mapper.SubMapper.show" title="Permalink to this definition">¶</a></dt> <dd><p>Generates the “show” action for a collection member submapper.</p> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="routes.mapper.SubMapper.update"> <span class="sig-name descname"><span class="pre">update</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#routes.mapper.SubMapper.update" title="Permalink to this definition">¶</a></dt> <dd><p>Generates the “update” action for a collection member submapper.</p> </dd></dl> </dd></dl> <dl class="py class"> <dt class="sig sig-object py" id="routes.mapper.Mapper"> <em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">routes.mapper.</span></span><span class="sig-name descname"><span class="pre">Mapper</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">controller_scan=<function</span> <span class="pre">controller_scan></span></span></em>, <em class="sig-param"><span class="n"><span class="pre">directory=None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">always_scan=False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">register=True</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">explicit=True</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#routes.mapper.Mapper" title="Permalink to this definition">¶</a></dt> <dd><p>Mapper handles URL generation and URL recognition in a web application.</p> <p>Mapper is built handling dictionary’s. It is assumed that the web application will handle the dictionary returned by URL recognition to dispatch appropriately.</p> <p>URL generation is done by passing keyword parameters into the generate function, a URL is then returned.</p> <p>Create a new Mapper instance</p> <p>All keyword arguments are optional.</p> <dl> <dt><code class="docutils literal notranslate"><span class="pre">controller_scan</span></code></dt><dd><p>Function reference that will be used to return a list of valid controllers used during URL matching. If <code class="docutils literal notranslate"><span class="pre">directory</span></code> keyword arg is present, it will be passed into the function during its call. This option defaults to a function that will scan a directory for controllers.</p> <p>Alternatively, a list of controllers or None can be passed in which are assumed to be the definitive list of controller names valid when matching ‘controller’.</p> </dd> <dt><code class="docutils literal notranslate"><span class="pre">directory</span></code></dt><dd><p>Passed into controller_scan for the directory to scan. It should be an absolute path if using the default <code class="docutils literal notranslate"><span class="pre">controller_scan</span></code> function.</p> </dd> <dt><code class="docutils literal notranslate"><span class="pre">always_scan</span></code></dt><dd><p>Whether or not the <code class="docutils literal notranslate"><span class="pre">controller_scan</span></code> function should be run during every URL match. This is typically a good idea during development so the server won’t need to be restarted anytime a controller is added.</p> </dd> <dt><code class="docutils literal notranslate"><span class="pre">register</span></code></dt><dd><p>Boolean used to determine if the Mapper should use <code class="docutils literal notranslate"><span class="pre">request_config</span></code> to register itself as the mapper. Since it’s done on a thread-local basis, this is typically best used during testing though it won’t hurt in other cases.</p> </dd> <dt><code class="docutils literal notranslate"><span class="pre">explicit</span></code></dt><dd><p>Boolean used to determine if routes should be connected with implicit defaults of:</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="p">{</span><span class="s1">'controller'</span><span class="p">:</span><span class="s1">'content'</span><span class="p">,</span><span class="s1">'action'</span><span class="p">:</span><span class="s1">'index'</span><span class="p">,</span><span class="s1">'id'</span><span class="p">:</span><span class="kc">None</span><span class="p">}</span> </pre></div> </div> <p>When set to True, these defaults will not be added to route connections and <code class="docutils literal notranslate"><span class="pre">url_for</span></code> will not use Route memory.</p> </dd> </dl> <p>Additional attributes that may be set after mapper initialization (ie, map.ATTRIBUTE = ‘something’):</p> <dl class="simple"> <dt><code class="docutils literal notranslate"><span class="pre">encoding</span></code></dt><dd><p>Used to indicate alternative encoding/decoding systems to use with both incoming URL’s, and during Route generation when passed a Unicode string. Defaults to ‘utf-8’.</p> </dd> <dt><code class="docutils literal notranslate"><span class="pre">decode_errors</span></code></dt><dd><p>How to handle errors in the encoding, generally ignoring any chars that don’t convert should be sufficient. Defaults to ‘ignore’.</p> </dd> <dt><code class="docutils literal notranslate"><span class="pre">minimization</span></code></dt><dd><p>Boolean used to indicate whether or not Routes should minimize URL’s and the generated URL’s, or require every part where it appears in the path. Defaults to False.</p> </dd> <dt><code class="docutils literal notranslate"><span class="pre">hardcode_names</span></code></dt><dd><p>Whether or not Named Routes result in the default options for the route being used <em>or</em> if they actually force url generation to use the route. Defaults to False.</p> </dd> </dl> <dl class="py method"> <dt class="sig sig-object py" id="routes.mapper.Mapper.connect"> <span class="sig-name descname"><span class="pre">connect</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kargs</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#routes.mapper.Mapper.connect" title="Permalink to this definition">¶</a></dt> <dd><p>Create and connect a new Route to the Mapper.</p> <p>Usage:</p> <div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">m</span> <span class="o">=</span> <span class="n">Mapper</span><span class="p">()</span> <span class="n">m</span><span class="o">.</span><span class="n">connect</span><span class="p">(</span><span class="s1">':controller/:action/:id'</span><span class="p">)</span> <span class="n">m</span><span class="o">.</span><span class="n">connect</span><span class="p">(</span><span class="s1">'date/:year/:month/:day'</span><span class="p">,</span> <span class="n">controller</span><span class="o">=</span><span class="s2">"blog"</span><span class="p">,</span> <span class="n">action</span><span class="o">=</span><span class="s2">"view"</span><span class="p">)</span> <span class="n">m</span><span class="o">.</span><span class="n">connect</span><span class="p">(</span><span class="s1">'archives/:page'</span><span class="p">,</span> <span class="n">controller</span><span class="o">=</span><span class="s2">"blog"</span><span class="p">,</span> <span class="n">action</span><span class="o">=</span><span class="s2">"by_page"</span><span class="p">,</span> <span class="n">requirements</span> <span class="o">=</span> <span class="p">{</span> <span class="s1">'page'</span><span class="p">:</span><span class="s1">'\d{1,2}'</span> <span class="p">})</span> <span class="n">m</span><span class="o">.</span><span class="n">connect</span><span class="p">(</span><span class="s1">'category_list'</span><span class="p">,</span> <span class="s1">'archives/category/:section'</span><span class="p">,</span> <span class="n">controller</span><span class="o">=</span><span class="s1">'blog'</span><span class="p">,</span> <span class="n">action</span><span class="o">=</span><span class="s1">'category'</span><span class="p">,</span> <span class="n">section</span><span class="o">=</span><span class="s1">'home'</span><span class="p">,</span> <span class="nb">type</span><span class="o">=</span><span class="s1">'list'</span><span class="p">)</span> <span class="n">m</span><span class="o">.</span><span class="n">connect</span><span class="p">(</span><span class="s1">'home'</span><span class="p">,</span> <span class="s1">''</span><span class="p">,</span> <span class="n">controller</span><span class="o">=</span><span class="s1">'blog'</span><span class="p">,</span> <span class="n">action</span><span class="o">=</span><span class="s1">'view'</span><span class="p">,</span> <span class="n">section</span><span class="o">=</span><span class="s1">'home'</span><span class="p">)</span> </pre></div> </div> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="routes.mapper.Mapper.create_regs"> <span class="sig-name descname"><span class="pre">create_regs</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#routes.mapper.Mapper.create_regs" title="Permalink to this definition">¶</a></dt> <dd><p>Atomically creates regular expressions for all connected routes</p> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="routes.mapper.Mapper.extend"> <span class="sig-name descname"><span class="pre">extend</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">routes</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">path_prefix</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">''</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#routes.mapper.Mapper.extend" title="Permalink to this definition">¶</a></dt> <dd><p>Extends the mapper routes with a list of Route objects</p> <p>If a path_prefix is provided, all the routes will have their path prepended with the path_prefix.</p> <p>Example:</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="nb">map</span> <span class="o">=</span> <span class="n">Mapper</span><span class="p">(</span><span class="n">controller_scan</span><span class="o">=</span><span class="kc">None</span><span class="p">)</span> <span class="gp">>>> </span><span class="nb">map</span><span class="o">.</span><span class="n">connect</span><span class="p">(</span><span class="s1">'home'</span><span class="p">,</span> <span class="s1">'/'</span><span class="p">,</span> <span class="n">controller</span><span class="o">=</span><span class="s1">'home'</span><span class="p">,</span> <span class="n">action</span><span class="o">=</span><span class="s1">'splash'</span><span class="p">)</span> <span class="gp">>>> </span><span class="nb">map</span><span class="o">.</span><span class="n">matchlist</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">name</span> <span class="o">==</span> <span class="s1">'home'</span> <span class="go">True</span> <span class="gp">>>> </span><span class="n">routes</span> <span class="o">=</span> <span class="p">[</span><span class="n">Route</span><span class="p">(</span><span class="s1">'index'</span><span class="p">,</span> <span class="s1">'/index.htm'</span><span class="p">,</span> <span class="n">controller</span><span class="o">=</span><span class="s1">'home'</span><span class="p">,</span> <span class="gp">... </span> <span class="n">action</span><span class="o">=</span><span class="s1">'index'</span><span class="p">)]</span> <span class="gp">>>> </span><span class="nb">map</span><span class="o">.</span><span class="n">extend</span><span class="p">(</span><span class="n">routes</span><span class="p">)</span> <span class="gp">>>> </span><span class="nb">len</span><span class="p">(</span><span class="nb">map</span><span class="o">.</span><span class="n">matchlist</span><span class="p">)</span> <span class="o">==</span> <span class="mi">2</span> <span class="go">True</span> <span class="gp">>>> </span><span class="nb">map</span><span class="o">.</span><span class="n">extend</span><span class="p">(</span><span class="n">routes</span><span class="p">,</span> <span class="n">path_prefix</span><span class="o">=</span><span class="s1">'/subapp'</span><span class="p">)</span> <span class="gp">>>> </span><span class="nb">len</span><span class="p">(</span><span class="nb">map</span><span class="o">.</span><span class="n">matchlist</span><span class="p">)</span> <span class="o">==</span> <span class="mi">3</span> <span class="go">True</span> <span class="gp">>>> </span><span class="nb">map</span><span class="o">.</span><span class="n">matchlist</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span><span class="o">.</span><span class="n">routepath</span> <span class="o">==</span> <span class="s1">'/subapp/index.htm'</span> <span class="go">True</span> </pre></div> </div> <div class="admonition note"> <p class="admonition-title">Note</p> <p>This function does not merely extend the mapper with the given list of routes, it actually creates new routes with identical calling arguments.</p> </div> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="routes.mapper.Mapper.generate"> <span class="sig-name descname"><span class="pre">generate</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kargs</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#routes.mapper.Mapper.generate" title="Permalink to this definition">¶</a></dt> <dd><p>Generate a route from a set of keywords</p> <p>Returns the url text, or None if no URL could be generated.</p> <div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">m</span><span class="o">.</span><span class="n">generate</span><span class="p">(</span><span class="n">controller</span><span class="o">=</span><span class="s1">'content'</span><span class="p">,</span><span class="n">action</span><span class="o">=</span><span class="s1">'view'</span><span class="p">,</span><span class="nb">id</span><span class="o">=</span><span class="mi">10</span><span class="p">)</span> </pre></div> </div> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="routes.mapper.Mapper.make_route"> <span class="sig-name descname"><span class="pre">make_route</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kargs</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#routes.mapper.Mapper.make_route" title="Permalink to this definition">¶</a></dt> <dd><p>Make a new Route object</p> <p>A subclass can override this method to use a custom Route class.</p> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="routes.mapper.Mapper.match"> <span class="sig-name descname"><span class="pre">match</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">url</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">environ</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#routes.mapper.Mapper.match" title="Permalink to this definition">¶</a></dt> <dd><p>Match a URL against against one of the routes contained.</p> <p>Will return None if no valid match is found.</p> <div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">resultdict</span> <span class="o">=</span> <span class="n">m</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="s1">'/joe/sixpack'</span><span class="p">)</span> </pre></div> </div> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="routes.mapper.Mapper.redirect"> <span class="sig-name descname"><span class="pre">redirect</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">match_path</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">destination_path</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#routes.mapper.Mapper.redirect" title="Permalink to this definition">¶</a></dt> <dd><p>Add a redirect route to the mapper</p> <p>Redirect routes bypass the wrapped WSGI application and instead result in a redirect being issued by the RoutesMiddleware. As such, this method is only meaningful when using RoutesMiddleware.</p> <p>By default, a 302 Found status code is used, this can be changed by providing a <code class="docutils literal notranslate"><span class="pre">_redirect_code</span></code> keyword argument which will then be used instead. Note that the entire status code string needs to be present.</p> <p>When using keyword arguments, all arguments that apply to matching will be used for the match, while generation specific options will be used during generation. Thus all options normally available to connected Routes may be used with redirect routes as well.</p> <p>Example:</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="nb">map</span> <span class="o">=</span> <span class="n">Mapper</span><span class="p">()</span> <span class="nb">map</span><span class="o">.</span><span class="n">redirect</span><span class="p">(</span><span class="s1">'/legacyapp/archives/{url:.*}'</span><span class="p">,</span> <span class="s1">'/archives/</span><span class="si">{url}</span><span class="s1">'</span><span class="p">)</span> <span class="nb">map</span><span class="o">.</span><span class="n">redirect</span><span class="p">(</span><span class="s1">'/home/index'</span><span class="p">,</span> <span class="s1">'/'</span><span class="p">,</span> <span class="n">_redirect_code</span><span class="o">=</span><span class="s1">'301 Moved Permanently'</span><span class="p">)</span> </pre></div> </div> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="routes.mapper.Mapper.resource"> <span class="sig-name descname"><span class="pre">resource</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">member_name</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">collection_name</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#routes.mapper.Mapper.resource" title="Permalink to this definition">¶</a></dt> <dd><p>Generate routes for a controller resource</p> <p>The member_name name should be the appropriate singular version of the resource given your locale and used with members of the collection. The collection_name name will be used to refer to the resource collection methods and should be a plural version of the member_name argument. By default, the member_name name will also be assumed to map to a controller you create.</p> <p>The concept of a web resource maps somewhat directly to ‘CRUD’ operations. The overlying things to keep in mind is that mapping a resource is about handling creating, viewing, and editing that resource.</p> <p>All keyword arguments are optional.</p> <dl> <dt><code class="docutils literal notranslate"><span class="pre">controller</span></code></dt><dd><p>If specified in the keyword args, the controller will be the actual controller used, but the rest of the naming conventions used for the route names and URL paths are unchanged.</p> </dd> <dt><code class="docutils literal notranslate"><span class="pre">collection</span></code></dt><dd><p>Additional action mappings used to manipulate/view the entire set of resources provided by the controller.</p> <p>Example:</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="nb">map</span><span class="o">.</span><span class="n">resource</span><span class="p">(</span><span class="s1">'message'</span><span class="p">,</span> <span class="s1">'messages'</span><span class="p">,</span> <span class="n">collection</span><span class="o">=</span><span class="p">{</span><span class="s1">'rss'</span><span class="p">:</span><span class="s1">'GET'</span><span class="p">})</span> <span class="c1"># GET /message/rss (maps to the rss action)</span> <span class="c1"># also adds named route "rss_message"</span> </pre></div> </div> </dd> <dt><code class="docutils literal notranslate"><span class="pre">member</span></code></dt><dd><p>Additional action mappings used to access an individual ‘member’ of this controllers resources.</p> <p>Example:</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="nb">map</span><span class="o">.</span><span class="n">resource</span><span class="p">(</span><span class="s1">'message'</span><span class="p">,</span> <span class="s1">'messages'</span><span class="p">,</span> <span class="n">member</span><span class="o">=</span><span class="p">{</span><span class="s1">'mark'</span><span class="p">:</span><span class="s1">'POST'</span><span class="p">})</span> <span class="c1"># POST /message/1/mark (maps to the mark action)</span> <span class="c1"># also adds named route "mark_message"</span> </pre></div> </div> </dd> <dt><code class="docutils literal notranslate"><span class="pre">new</span></code></dt><dd><p>Action mappings that involve dealing with a new member in the controller resources.</p> <p>Example:</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="nb">map</span><span class="o">.</span><span class="n">resource</span><span class="p">(</span><span class="s1">'message'</span><span class="p">,</span> <span class="s1">'messages'</span><span class="p">,</span> <span class="n">new</span><span class="o">=</span><span class="p">{</span><span class="s1">'preview'</span><span class="p">:</span><span class="s1">'POST'</span><span class="p">})</span> <span class="c1"># POST /message/new/preview (maps to the preview action)</span> <span class="c1"># also adds a url named "preview_new_message"</span> </pre></div> </div> </dd> <dt><code class="docutils literal notranslate"><span class="pre">path_prefix</span></code></dt><dd><p>Prepends the URL path for the Route with the path_prefix given. This is most useful for cases where you want to mix resources or relations between resources.</p> </dd> <dt><code class="docutils literal notranslate"><span class="pre">name_prefix</span></code></dt><dd><p>Perpends the route names that are generated with the name_prefix given. Combined with the path_prefix option, it’s easy to generate route names and paths that represent resources that are in relations.</p> <p>Example:</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="nb">map</span><span class="o">.</span><span class="n">resource</span><span class="p">(</span><span class="s1">'message'</span><span class="p">,</span> <span class="s1">'messages'</span><span class="p">,</span> <span class="n">controller</span><span class="o">=</span><span class="s1">'categories'</span><span class="p">,</span> <span class="n">path_prefix</span><span class="o">=</span><span class="s1">'/category/:category_id'</span><span class="p">,</span> <span class="n">name_prefix</span><span class="o">=</span><span class="s2">"category_"</span><span class="p">)</span> <span class="c1"># GET /category/7/message/1</span> <span class="c1"># has named route "category_message"</span> </pre></div> </div> </dd> </dl> <p><code class="docutils literal notranslate"><span class="pre">requirements</span></code></p> <blockquote> <div><p>A dictionary that restricts the matching of a variable. Can be used when matching variables with path_prefix.</p> <p>Example:</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="nb">map</span><span class="o">.</span><span class="n">resource</span><span class="p">(</span><span class="s1">'message'</span><span class="p">,</span> <span class="s1">'messages'</span><span class="p">,</span> <span class="n">path_prefix</span><span class="o">=</span><span class="s1">'</span><span class="si">{project_id}</span><span class="s1">/'</span><span class="p">,</span> <span class="n">requirements</span><span class="o">=</span><span class="p">{</span><span class="s2">"project_id"</span><span class="p">:</span> <span class="sa">R</span><span class="s2">"\d+"</span><span class="p">})</span> <span class="c1"># POST /01234/message</span> <span class="c1"># success, project_id is set to "01234"</span> <span class="c1"># POST /foo/message</span> <span class="c1"># 404 not found, won't be matched by this route</span> </pre></div> </div> </div></blockquote> <dl> <dt><code class="docutils literal notranslate"><span class="pre">parent_resource</span></code></dt><dd><p>A <code class="docutils literal notranslate"><span class="pre">dict</span></code> containing information about the parent resource, for creating a nested resource. It should contain the <code class="docutils literal notranslate"><span class="pre">member_name</span></code> and <code class="docutils literal notranslate"><span class="pre">collection_name</span></code> of the parent resource. This <code class="docutils literal notranslate"><span class="pre">dict</span></code> will be available via the associated <code class="docutils literal notranslate"><span class="pre">Route</span></code> object which can be accessed during a request via <code class="docutils literal notranslate"><span class="pre">request.environ['routes.route']</span></code></p> <p>If <code class="docutils literal notranslate"><span class="pre">parent_resource</span></code> is supplied and <code class="docutils literal notranslate"><span class="pre">path_prefix</span></code> isn’t, <code class="docutils literal notranslate"><span class="pre">path_prefix</span></code> will be generated from <code class="docutils literal notranslate"><span class="pre">parent_resource</span></code> as “<parent collection name>/:<parent member name>_id”.</p> <p>If <code class="docutils literal notranslate"><span class="pre">parent_resource</span></code> is supplied and <code class="docutils literal notranslate"><span class="pre">name_prefix</span></code> isn’t, <code class="docutils literal notranslate"><span class="pre">name_prefix</span></code> will be generated from <code class="docutils literal notranslate"><span class="pre">parent_resource</span></code> as “<parent member name>_”.</p> <p>Example:</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">from</span> <span class="nn">routes.util</span> <span class="kn">import</span> <span class="n">url_for</span> <span class="gp">>>> </span><span class="n">m</span> <span class="o">=</span> <span class="n">Mapper</span><span class="p">()</span> <span class="gp">>>> </span><span class="n">m</span><span class="o">.</span><span class="n">resource</span><span class="p">(</span><span class="s1">'location'</span><span class="p">,</span> <span class="s1">'locations'</span><span class="p">,</span> <span class="gp">... </span> <span class="n">parent_resource</span><span class="o">=</span><span class="nb">dict</span><span class="p">(</span><span class="n">member_name</span><span class="o">=</span><span class="s1">'region'</span><span class="p">,</span> <span class="gp">... </span> <span class="n">collection_name</span><span class="o">=</span><span class="s1">'regions'</span><span class="p">))</span> <span class="gp">>>> </span><span class="c1"># path_prefix is "regions/:region_id"</span> <span class="gp">>>> </span><span class="c1"># name prefix is "region_"</span> <span class="gp">>>> </span><span class="n">url_for</span><span class="p">(</span><span class="s1">'region_locations'</span><span class="p">,</span> <span class="n">region_id</span><span class="o">=</span><span class="mi">13</span><span class="p">)</span> <span class="go">'/regions/13/locations'</span> <span class="gp">>>> </span><span class="n">url_for</span><span class="p">(</span><span class="s1">'region_new_location'</span><span class="p">,</span> <span class="n">region_id</span><span class="o">=</span><span class="mi">13</span><span class="p">)</span> <span class="go">'/regions/13/locations/new'</span> <span class="gp">>>> </span><span class="n">url_for</span><span class="p">(</span><span class="s1">'region_location'</span><span class="p">,</span> <span class="n">region_id</span><span class="o">=</span><span class="mi">13</span><span class="p">,</span> <span class="nb">id</span><span class="o">=</span><span class="mi">60</span><span class="p">)</span> <span class="go">'/regions/13/locations/60'</span> <span class="gp">>>> </span><span class="n">url_for</span><span class="p">(</span><span class="s1">'region_edit_location'</span><span class="p">,</span> <span class="n">region_id</span><span class="o">=</span><span class="mi">13</span><span class="p">,</span> <span class="nb">id</span><span class="o">=</span><span class="mi">60</span><span class="p">)</span> <span class="go">'/regions/13/locations/60/edit'</span> </pre></div> </div> <p>Overriding generated <code class="docutils literal notranslate"><span class="pre">path_prefix</span></code>:</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">m</span> <span class="o">=</span> <span class="n">Mapper</span><span class="p">()</span> <span class="gp">>>> </span><span class="n">m</span><span class="o">.</span><span class="n">resource</span><span class="p">(</span><span class="s1">'location'</span><span class="p">,</span> <span class="s1">'locations'</span><span class="p">,</span> <span class="gp">... </span> <span class="n">parent_resource</span><span class="o">=</span><span class="nb">dict</span><span class="p">(</span><span class="n">member_name</span><span class="o">=</span><span class="s1">'region'</span><span class="p">,</span> <span class="gp">... </span> <span class="n">collection_name</span><span class="o">=</span><span class="s1">'regions'</span><span class="p">),</span> <span class="gp">... </span> <span class="n">path_prefix</span><span class="o">=</span><span class="s1">'areas/:area_id'</span><span class="p">)</span> <span class="gp">>>> </span><span class="c1"># name prefix is "region_"</span> <span class="gp">>>> </span><span class="n">url_for</span><span class="p">(</span><span class="s1">'region_locations'</span><span class="p">,</span> <span class="n">area_id</span><span class="o">=</span><span class="mi">51</span><span class="p">)</span> <span class="go">'/areas/51/locations'</span> </pre></div> </div> <p>Overriding generated <code class="docutils literal notranslate"><span class="pre">name_prefix</span></code>:</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">m</span> <span class="o">=</span> <span class="n">Mapper</span><span class="p">()</span> <span class="gp">>>> </span><span class="n">m</span><span class="o">.</span><span class="n">resource</span><span class="p">(</span><span class="s1">'location'</span><span class="p">,</span> <span class="s1">'locations'</span><span class="p">,</span> <span class="gp">... </span> <span class="n">parent_resource</span><span class="o">=</span><span class="nb">dict</span><span class="p">(</span><span class="n">member_name</span><span class="o">=</span><span class="s1">'region'</span><span class="p">,</span> <span class="gp">... </span> <span class="n">collection_name</span><span class="o">=</span><span class="s1">'regions'</span><span class="p">),</span> <span class="gp">... </span> <span class="n">name_prefix</span><span class="o">=</span><span class="s1">''</span><span class="p">)</span> <span class="gp">>>> </span><span class="c1"># path_prefix is "regions/:region_id"</span> <span class="gp">>>> </span><span class="n">url_for</span><span class="p">(</span><span class="s1">'locations'</span><span class="p">,</span> <span class="n">region_id</span><span class="o">=</span><span class="mi">51</span><span class="p">)</span> <span class="go">'/regions/51/locations'</span> </pre></div> </div> </dd> </dl> </dd></dl> <dl class="py method"> <dt class="sig sig-object py" id="routes.mapper.Mapper.routematch"> <span class="sig-name descname"><span class="pre">routematch</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">url</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">environ</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#routes.mapper.Mapper.routematch" title="Permalink to this definition">¶</a></dt> <dd><p>Match a URL against against one of the routes contained.</p> <p>Will return None if no valid match is found, otherwise a result dict and a route object is returned.</p> <div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">resultdict</span><span class="p">,</span> <span class="n">route_obj</span> <span class="o">=</span> <span class="n">m</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="s1">'/joe/sixpack'</span><span class="p">)</span> </pre></div> </div> </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.mapper</span></code> – Mapper and Sub-Mapper</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="routes.html" title="previous chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">routes</span></code> – Routes Common Classes and Functions</a></p> <h4>Next topic</h4> <p class="topless"><a href="route.html" title="next chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">routes.route</span></code> – Route</a></p> <div role="note" aria-label="source link"> <h3>This Page</h3> <ul class="this-page-menu"> <li><a href="../_sources/modules/mapper.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="route.html" title="routes.route – Route" >next</a> |</li> <li class="right" > <a href="routes.html" title="routes – Routes Common Classes and Functions" >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.mapper</span></code> – Mapper and Sub-Mapper</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>