Skip to content

Commit

Permalink
Deploying to gh-pages from @ 71599b9 🚀
Browse files Browse the repository at this point in the history
  • Loading branch information
vsoch committed Nov 13, 2024
1 parent 19d734c commit e525234
Show file tree
Hide file tree
Showing 33 changed files with 1,193 additions and 1,789 deletions.
1,349 changes: 0 additions & 1,349 deletions _modules/functools.html

This file was deleted.

7 changes: 1 addition & 6 deletions _modules/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -287,11 +287,6 @@ <h1 id="modules-index--page-root">
All modules for which code is available
</h1>
<ul>
<li>
<a href="functools.html">
functools
</a>
</li>
<li>
<a href="oras/auth.html">
oras.auth
Expand Down Expand Up @@ -375,7 +370,7 @@ <h1 id="modules-index--page-root">
© Copyright 2023, Oras Python Developers.
</div>
Last updated on
Oct 21, 2024.
Nov 13, 2024.
<br/>
Created using
<a href="http://www.sphinx-doc.org/">
Expand Down
2 changes: 1 addition & 1 deletion _modules/oras/auth.html
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ <h1 id="modules-oras-auth--page-root">
© Copyright 2023, Oras Python Developers.
</div>
Last updated on
Oct 21, 2024.
Nov 13, 2024.
<br/>
Created using
<a href="http://www.sphinx-doc.org/">
Expand Down
2 changes: 1 addition & 1 deletion _modules/oras/container.html
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ <h1 id="modules-oras-container--page-root">
© Copyright 2023, Oras Python Developers.
</div>
Last updated on
Oct 21, 2024.
Nov 13, 2024.
<br/>
Created using
<a href="http://www.sphinx-doc.org/">
Expand Down
72 changes: 20 additions & 52 deletions _modules/oras/decorator.html
Original file line number Diff line number Diff line change
Expand Up @@ -298,88 +298,56 @@ <h1 id="modules-oras-decorator--page-root">
<span class="n">__license__</span> <span class="o">=</span> <span class="s2">"Apache-2.0"</span>

<span class="kn">import</span> <span class="nn">time</span>
<span class="kn">from</span> <span class="nn">functools</span> <span class="kn">import</span> <span class="n">partial</span><span class="p">,</span> <span class="n">update_wrapper</span>
<span class="kn">from</span> <span class="nn">functools</span> <span class="kn">import</span> <span class="n">wraps</span>

<span class="kn">import</span> <span class="nn">oras.auth</span>
<span class="kn">from</span> <span class="nn">oras.logger</span> <span class="kn">import</span> <span class="n">logger</span>


<div class="viewcode-block" id="Decorator">
<a class="viewcode-back" href="../../source/oras.html#oras.decorator.Decorator">[docs]</a>
<span class="k">class</span> <span class="nc">Decorator</span><span class="p">:</span>
<span class="w"> </span><span class="sd">"""</span>
<span class="sd"> Shared parent decorator class</span>
<span class="sd"> """</span>

<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">func</span><span class="p">):</span>
<span class="n">update_wrapper</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">func</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">func</span> <span class="o">=</span> <span class="n">func</span>

<span class="k">def</span> <span class="fm">__get__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">obj</span><span class="p">,</span> <span class="n">objtype</span><span class="p">):</span>
<span class="k">return</span> <span class="n">partial</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="fm">__call__</span><span class="p">,</span> <span class="n">obj</span><span class="p">)</span></div>



<div class="viewcode-block" id="ensure_container">
<a class="viewcode-back" href="../../source/oras.html#oras.decorator.ensure_container">[docs]</a>
<span class="k">class</span> <span class="nc">ensure_container</span><span class="p">(</span><span class="n">Decorator</span><span class="p">):</span>
<span class="k">def</span> <span class="nf">ensure_container</span><span class="p">(</span><span class="n">func</span><span class="p">):</span>
<span class="w"> </span><span class="sd">"""</span>
<span class="sd"> Ensure the first argument is a container, and not a string.</span>
<span class="sd"> """</span>

<span class="k">def</span> <span class="fm">__call__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="bp">cls</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="nd">@wraps</span><span class="p">(</span><span class="n">func</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">wrapper</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="k">if</span> <span class="s2">"container"</span> <span class="ow">in</span> <span class="n">kwargs</span><span class="p">:</span>
<span class="n">kwargs</span><span class="p">[</span><span class="s2">"container"</span><span class="p">]</span> <span class="o">=</span> <span class="bp">cls</span><span class="o">.</span><span class="n">get_container</span><span class="p">(</span><span class="n">kwargs</span><span class="p">[</span><span class="s2">"container"</span><span class="p">])</span>
<span class="k">elif</span> <span class="n">args</span><span class="p">:</span>
<span class="n">container</span> <span class="o">=</span> <span class="bp">cls</span><span class="o">.</span><span class="n">get_container</span><span class="p">(</span><span class="n">args</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
<span class="n">args</span> <span class="o">=</span> <span class="p">(</span><span class="n">container</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">[</span><span class="mi">1</span><span class="p">:])</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">func</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span></div>



<div class="viewcode-block" id="classretry">
<a class="viewcode-back" href="../../source/oras.html#oras.decorator.classretry">[docs]</a>
<span class="k">class</span> <span class="nc">classretry</span><span class="p">(</span><span class="n">Decorator</span><span class="p">):</span>
<span class="w"> </span><span class="sd">"""</span>
<span class="sd"> Retry a function that is part of a class</span>
<span class="sd"> """</span>

<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">func</span><span class="p">,</span> <span class="n">attempts</span><span class="o">=</span><span class="mi">5</span><span class="p">,</span> <span class="n">timeout</span><span class="o">=</span><span class="mi">2</span><span class="p">):</span>
<span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="n">func</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">attempts</span> <span class="o">=</span> <span class="n">attempts</span>
<span class="bp">self</span><span class="o">.</span><span class="n">timeout</span> <span class="o">=</span> <span class="n">timeout</span>
<span class="k">return</span> <span class="n">func</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>

<span class="k">def</span> <span class="fm">__call__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="bp">cls</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="n">attempt</span> <span class="o">=</span> <span class="mi">0</span>
<span class="n">attempts</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">attempts</span>
<span class="n">timeout</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">timeout</span>
<span class="k">while</span> <span class="n">attempt</span> <span class="o">&lt;</span> <span class="n">attempts</span><span class="p">:</span>
<span class="k">try</span><span class="p">:</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">func</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
<span class="k">except</span> <span class="n">oras</span><span class="o">.</span><span class="n">auth</span><span class="o">.</span><span class="n">AuthenticationException</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
<span class="k">raise</span> <span class="n">e</span>
<span class="k">except</span> <span class="ne">Exception</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
<span class="n">sleep</span> <span class="o">=</span> <span class="n">timeout</span> <span class="o">+</span> <span class="mi">3</span><span class="o">**</span><span class="n">attempt</span>
<span class="n">logger</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="sa">f</span><span class="s2">"Retrying in </span><span class="si">{</span><span class="n">sleep</span><span class="si">}</span><span class="s2"> seconds - error: </span><span class="si">{</span><span class="n">e</span><span class="si">}</span><span class="s2">"</span><span class="p">)</span>
<span class="n">time</span><span class="o">.</span><span class="n">sleep</span><span class="p">(</span><span class="n">sleep</span><span class="p">)</span>
<span class="n">attempt</span> <span class="o">+=</span> <span class="mi">1</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">func</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span></div>
<span class="k">return</span> <span class="n">wrapper</span></div>



<div class="viewcode-block" id="retry">
<a class="viewcode-back" href="../../source/oras.html#oras.decorator.retry">[docs]</a>
<span class="k">def</span> <span class="nf">retry</span><span class="p">(</span><span class="n">attempts</span><span class="p">,</span> <span class="n">timeout</span><span class="o">=</span><span class="mi">2</span><span class="p">):</span>
<span class="k">def</span> <span class="nf">retry</span><span class="p">(</span><span class="n">attempts</span><span class="o">=</span><span class="mi">5</span><span class="p">,</span> <span class="n">timeout</span><span class="o">=</span><span class="mi">2</span><span class="p">):</span>
<span class="w"> </span><span class="sd">"""</span>
<span class="sd"> A simple retry decorator</span>
<span class="sd"> """</span>

<span class="k">def</span> <span class="nf">decorator</span><span class="p">(</span><span class="n">func</span><span class="p">):</span>
<span class="nd">@wraps</span><span class="p">(</span><span class="n">func</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">inner</span><span class="p">(</span><span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="n">attempt</span> <span class="o">=</span> <span class="mi">0</span>
<span class="k">while</span> <span class="n">attempt</span> <span class="o">&lt;</span> <span class="n">attempts</span><span class="p">:</span>
<span class="k">try</span><span class="p">:</span>
<span class="k">return</span> <span class="n">func</span><span class="p">(</span><span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
<span class="n">res</span> <span class="o">=</span> <span class="n">func</span><span class="p">(</span><span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
<span class="k">if</span> <span class="n">res</span><span class="o">.</span><span class="n">status_code</span> <span class="o">==</span> <span class="mi">500</span><span class="p">:</span>
<span class="k">try</span><span class="p">:</span>
<span class="n">msg</span> <span class="o">=</span> <span class="n">res</span><span class="o">.</span><span class="n">json</span><span class="p">()</span>
<span class="k">for</span> <span class="n">error</span> <span class="ow">in</span> <span class="n">msg</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">"errors"</span><span class="p">,</span> <span class="p">[]):</span>
<span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">error</span><span class="p">,</span> <span class="nb">dict</span><span class="p">)</span> <span class="ow">and</span> <span class="s2">"message"</span> <span class="ow">in</span> <span class="n">error</span><span class="p">:</span>
<span class="n">logger</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="n">error</span><span class="p">[</span><span class="s2">"message"</span><span class="p">])</span>
<span class="k">except</span> <span class="ne">Exception</span><span class="p">:</span>
<span class="k">pass</span>
<span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="sa">f</span><span class="s2">"Issue with </span><span class="si">{</span><span class="n">res</span><span class="o">.</span><span class="n">request</span><span class="o">.</span><span class="n">url</span><span class="si">}</span><span class="s2">: </span><span class="si">{</span><span class="n">res</span><span class="o">.</span><span class="n">reason</span><span class="si">}</span><span class="s2">"</span><span class="p">)</span>
<span class="k">return</span> <span class="n">res</span>
<span class="k">except</span> <span class="n">oras</span><span class="o">.</span><span class="n">auth</span><span class="o">.</span><span class="n">AuthenticationException</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
<span class="k">raise</span> <span class="n">e</span>
<span class="k">except</span> <span class="ne">Exception</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
Expand Down Expand Up @@ -412,7 +380,7 @@ <h1 id="modules-oras-decorator--page-root">
© Copyright 2023, Oras Python Developers.
</div>
Last updated on
Oct 21, 2024.
Nov 13, 2024.
<br/>
Created using
<a href="http://www.sphinx-doc.org/">
Expand Down
2 changes: 1 addition & 1 deletion _modules/oras/defaults.html
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ <h1 id="modules-oras-defaults--page-root">
© Copyright 2023, Oras Python Developers.
</div>
Last updated on
Oct 21, 2024.
Nov 13, 2024.
<br/>
Created using
<a href="http://www.sphinx-doc.org/">
Expand Down
2 changes: 1 addition & 1 deletion _modules/oras/logger.html
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,7 @@ <h1 id="modules-oras-logger--page-root">
© Copyright 2023, Oras Python Developers.
</div>
Last updated on
Oct 21, 2024.
Nov 13, 2024.
<br/>
Created using
<a href="http://www.sphinx-doc.org/">
Expand Down
2 changes: 1 addition & 1 deletion _modules/oras/main/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ <h1 id="modules-oras-main-login--page-root">
© Copyright 2023, Oras Python Developers.
</div>
Last updated on
Oct 21, 2024.
Nov 13, 2024.
<br/>
Created using
<a href="http://www.sphinx-doc.org/">
Expand Down
2 changes: 1 addition & 1 deletion _modules/oras/oci.html
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ <h1 id="modules-oras-oci--page-root">
© Copyright 2023, Oras Python Developers.
</div>
Last updated on
Oct 21, 2024.
Nov 13, 2024.
<br/>
Created using
<a href="http://www.sphinx-doc.org/">
Expand Down
Loading

0 comments on commit e525234

Please sign in to comment.