Skip to content

Commit

Permalink
Updated documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions committed Jan 30, 2024
1 parent bb3ddce commit 1cd41ff
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
19 changes: 8 additions & 11 deletions _modules/apis_core/utils/normalize.html
Original file line number Diff line number Diff line change
Expand Up @@ -91,23 +91,20 @@ <h1>Source code for apis_core.utils.normalize</h1><div class="highlight"><pre>
<span class="c1"># SPDX-License-Identifier: MIT</span>

<span class="kn">import</span> <span class="nn">re</span>
<span class="kn">import</span> <span class="nn">tomllib</span>
<span class="kn">from</span> <span class="nn">apis_core.utils.settings</span> <span class="kn">import</span> <span class="n">clean_uri_mapping_file</span>
<span class="kn">from</span> <span class="nn">yaml</span> <span class="kn">import</span> <span class="n">safe_load</span>


<div class="viewcode-block" id="clean_uri">
<a class="viewcode-back" href="../../../modules/apis_core.utils.html#apis_core.utils.normalize.clean_uri">[docs]</a>
<span class="k">def</span> <span class="nf">clean_uri</span><span class="p">(</span><span class="n">uri</span><span class="p">:</span> <span class="nb">str</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">str</span><span class="p">:</span>
<span class="k">if</span> <span class="n">uri</span><span class="p">:</span>
<span class="n">settings</span> <span class="o">=</span> <span class="n">safe_load</span><span class="p">(</span><span class="n">clean_uri_mapping_file</span><span class="p">()</span><span class="o">.</span><span class="n">read_text</span><span class="p">())</span>
<span class="k">for</span> <span class="n">mapping</span> <span class="ow">in</span> <span class="n">settings</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;mappings&quot;</span><span class="p">,</span> <span class="p">[]):</span>
<span class="n">domain</span> <span class="o">=</span> <span class="n">mapping</span><span class="p">[</span><span class="s2">&quot;domain&quot;</span><span class="p">]</span>
<span class="n">regex</span> <span class="o">=</span> <span class="n">mapping</span><span class="p">[</span><span class="s2">&quot;regex&quot;</span><span class="p">]</span>
<span class="n">replace</span> <span class="o">=</span> <span class="n">mapping</span><span class="p">[</span><span class="s2">&quot;replace&quot;</span><span class="p">]</span>
<span class="k">if</span> <span class="n">domain</span> <span class="ow">in</span> <span class="n">uri</span><span class="p">:</span>
<span class="n">m</span> <span class="o">=</span> <span class="n">re</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="n">regex</span><span class="p">,</span> <span class="n">uri</span><span class="p">)</span>
<span class="k">if</span> <span class="n">m</span><span class="p">:</span>
<span class="n">uri</span> <span class="o">=</span> <span class="n">replace</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">m</span><span class="o">.</span><span class="n">group</span><span class="p">(</span><span class="mi">1</span><span class="p">))</span>
<span class="n">settings</span> <span class="o">=</span> <span class="n">tomllib</span><span class="o">.</span><span class="n">loads</span><span class="p">(</span><span class="n">clean_uri_mapping_file</span><span class="p">()</span><span class="o">.</span><span class="n">read_text</span><span class="p">())</span>
<span class="k">if</span> <span class="n">uri</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
<span class="k">for</span> <span class="n">entry</span> <span class="ow">in</span> <span class="n">settings</span><span class="o">.</span><span class="n">values</span><span class="p">():</span>
<span class="n">regex</span> <span class="o">=</span> <span class="n">entry</span><span class="p">[</span><span class="s2">&quot;regex&quot;</span><span class="p">]</span>
<span class="n">replace</span> <span class="o">=</span> <span class="n">entry</span><span class="p">[</span><span class="s2">&quot;replace&quot;</span><span class="p">]</span>
<span class="k">if</span> <span class="n">m</span> <span class="o">:=</span> <span class="n">re</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="n">regex</span><span class="p">,</span> <span class="n">uri</span><span class="p">):</span>
<span class="n">uri</span> <span class="o">=</span> <span class="n">replace</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">m</span><span class="o">.</span><span class="n">group</span><span class="p">(</span><span class="mi">1</span><span class="p">))</span>
<span class="k">return</span> <span class="n">uri</span></div>

</pre></div>
Expand Down
3 changes: 2 additions & 1 deletion _modules/apis_core/utils/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ <h1>Source code for apis_core.utils.settings</h1><div class="highlight"><pre>
<span></span><span class="c1"># SPDX-FileCopyrightText: 2023 Birger Schacht</span>
<span class="c1"># SPDX-License-Identifier: MIT</span>

<span class="kn">import</span> <span class="nn">os</span>
<span class="kn">from</span> <span class="nn">pathlib</span> <span class="kn">import</span> <span class="n">Path</span>
<span class="kn">from</span> <span class="nn">django.conf</span> <span class="kn">import</span> <span class="n">settings</span>

Expand All @@ -105,7 +106,7 @@ <h1>Source code for apis_core.utils.settings</h1><div class="highlight"><pre>
<div class="viewcode-block" id="clean_uri_mapping_file">
<a class="viewcode-back" href="../../../modules/apis_core.utils.html#apis_core.utils.settings.clean_uri_mapping_file">[docs]</a>
<span class="k">def</span> <span class="nf">clean_uri_mapping_file</span><span class="p">()</span> <span class="o">-&gt;</span> <span class="n">Path</span><span class="p">:</span>
<span class="n">default</span> <span class="o">=</span> <span class="n">default_settings</span><span class="p">()</span> <span class="o">/</span> <span class="s2">&quot;URI_replace_settings.yml&quot;</span>
<span class="n">default</span> <span class="o">=</span> <span class="n">Path</span><span class="p">(</span><span class="vm">__file__</span><span class="p">)</span><span class="o">.</span><span class="n">parent</span> <span class="o">/</span> <span class="s2">&quot;clean_uri.toml&quot;</span>
<span class="n">mapping_file</span> <span class="o">=</span> <span class="nb">getattr</span><span class="p">(</span><span class="n">settings</span><span class="p">,</span> <span class="s2">&quot;CLEANURI_MAPPINGS&quot;</span><span class="p">,</span> <span class="n">default</span><span class="p">)</span>
<span class="k">return</span> <span class="n">Path</span><span class="p">(</span><span class="n">mapping_file</span><span class="p">)</span></div>

Expand Down

0 comments on commit 1cd41ff

Please sign in to comment.