Skip to content

Commit 6eb9243

Browse files
GitHub Actions
1 parent 4b6b122 commit 6eb9243

File tree

2 files changed

+46
-20
lines changed

2 files changed

+46
-20
lines changed

docs/thimble.html

Lines changed: 46 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<head>
44
<meta charset="utf-8">
55
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1">
6-
<meta name="generator" content="pdoc3 0.11.5">
6+
<meta name="generator" content="pdoc3 0.11.6">
77
<title>thimble API documentation</title>
88
<meta name="description" content="">
99
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/13.0.0/sanitize.min.css" integrity="sha512-y1dtMcuvtTMJc1yPgEqF0ZjQbhnc/bFhyvIyVNb9Zk5mIGtqVaAB1Ttl28su8AvFMOY0EwRbAe+HCLqj6W7/KA==" crossorigin>
@@ -409,28 +409,41 @@ <h2 class="section-title" id="header-classes">Classes</h2>
409409

410410
return add_route
411411

412-
def resolve_route(self, route_pattern):
412+
def resolve_route(self, route_candidate):
413413
&#34;&#34;&#34;
414414
Given a route pattern (METHOD + url_path), look up the corresponding function.
415415

416416
Args:
417-
route_pattern (string): An uppercase HTTP method concatenated with a URL path wich may contain regex (ex: GET/gpio/([0-9+])$)
417+
route_candidate (string): An uppercase HTTP method concatenated with a URL path wich may contain regex (ex: GET/gpio/([0-9+])$)
418418

419419
Returns:
420420
object: reference to function (for non-regex URLs) or tuple with function and regex capture (for regex URLs)
421421
&#34;&#34;&#34;
422422
result = None
423-
if route_pattern in self.routes: # pattern is a fixed string, like: &#39;GET/gpio/2&#39;
424-
result = self.routes[route_pattern]
423+
if self.debug:
424+
print(&#34;Looking for a route matching:&#34;, route_candidate)
425+
if route_candidate in self.routes: # pattern is a non-regex string, like: &#39;GET/gpio/2&#39;
426+
if self.debug:
427+
print(&#34;Route table had an exact match. We&#39;re done!&#34;)
428+
result = self.routes[route_candidate]
425429
else: # pattern may contain regex, like &#39;GET/gpio/([0-9]+)&#39;
426-
for key in self.routes.keys():
427-
regex_match = match(key, route_pattern)
430+
if self.debug:
431+
print(&#34;No exact match in route table. Looking for regex matches...&#34;)
432+
for stored_route in self.routes.keys():
433+
if self.debug:
434+
print(&#34;Examining this route table entry for potential match:&#34;, stored_route)
435+
regex_match = search(&#34;^&#34; + stored_route + &#34;$&#34;, route_candidate)
428436
if regex_match:
429-
func = self.routes[key]
437+
if self.debug:
438+
print(&#34;Found a regex match with:&#34;, stored_route)
439+
func = self.routes[stored_route]
430440
wildcard_value = regex_match.group(1)
431441
if self.debug:
432-
print(f&#39;Wildcard match: {wildcard_value}&#39;)
442+
print(f&#39;Extracted wildcard value: {wildcard_value}&#39;)
433443
result = func, wildcard_value
444+
else:
445+
if self.debug:
446+
print(&#34;No match.&#34;)
434447

435448
return result
436449

@@ -935,42 +948,55 @@ <h2 id="returns">Returns</h2>
935948
<p>nothing</p></div>
936949
</dd>
937950
<dt id="thimble.Thimble.resolve_route"><code class="name flex">
938-
<span>def <span class="ident">resolve_route</span></span>(<span>self, route_pattern)</span>
951+
<span>def <span class="ident">resolve_route</span></span>(<span>self, route_candidate)</span>
939952
</code></dt>
940953
<dd>
941954
<details class="source">
942955
<summary>
943956
<span>Expand source code</span>
944957
</summary>
945-
<pre><code class="python">def resolve_route(self, route_pattern):
958+
<pre><code class="python">def resolve_route(self, route_candidate):
946959
&#34;&#34;&#34;
947960
Given a route pattern (METHOD + url_path), look up the corresponding function.
948961

949962
Args:
950-
route_pattern (string): An uppercase HTTP method concatenated with a URL path wich may contain regex (ex: GET/gpio/([0-9+])$)
963+
route_candidate (string): An uppercase HTTP method concatenated with a URL path wich may contain regex (ex: GET/gpio/([0-9+])$)
951964

952965
Returns:
953966
object: reference to function (for non-regex URLs) or tuple with function and regex capture (for regex URLs)
954967
&#34;&#34;&#34;
955968
result = None
956-
if route_pattern in self.routes: # pattern is a fixed string, like: &#39;GET/gpio/2&#39;
957-
result = self.routes[route_pattern]
969+
if self.debug:
970+
print(&#34;Looking for a route matching:&#34;, route_candidate)
971+
if route_candidate in self.routes: # pattern is a non-regex string, like: &#39;GET/gpio/2&#39;
972+
if self.debug:
973+
print(&#34;Route table had an exact match. We&#39;re done!&#34;)
974+
result = self.routes[route_candidate]
958975
else: # pattern may contain regex, like &#39;GET/gpio/([0-9]+)&#39;
959-
for key in self.routes.keys():
960-
regex_match = match(key, route_pattern)
976+
if self.debug:
977+
print(&#34;No exact match in route table. Looking for regex matches...&#34;)
978+
for stored_route in self.routes.keys():
979+
if self.debug:
980+
print(&#34;Examining this route table entry for potential match:&#34;, stored_route)
981+
regex_match = search(&#34;^&#34; + stored_route + &#34;$&#34;, route_candidate)
961982
if regex_match:
962-
func = self.routes[key]
983+
if self.debug:
984+
print(&#34;Found a regex match with:&#34;, stored_route)
985+
func = self.routes[stored_route]
963986
wildcard_value = regex_match.group(1)
964987
if self.debug:
965-
print(f&#39;Wildcard match: {wildcard_value}&#39;)
988+
print(f&#39;Extracted wildcard value: {wildcard_value}&#39;)
966989
result = func, wildcard_value
990+
else:
991+
if self.debug:
992+
print(&#34;No match.&#34;)
967993

968994
return result</code></pre>
969995
</details>
970996
<div class="desc"><p>Given a route pattern (METHOD + url_path), look up the corresponding function.</p>
971997
<h2 id="args">Args</h2>
972998
<dl>
973-
<dt><strong><code>route_pattern</code></strong> :&ensp;<code>string</code></dt>
999+
<dt><strong><code>route_candidate</code></strong> :&ensp;<code>string</code></dt>
9741000
<dd>An uppercase HTTP method concatenated with a URL path wich may contain regex (ex: GET/gpio/([0-9+])$)</dd>
9751001
</dl>
9761002
<h2 id="returns">Returns</h2>
@@ -1288,7 +1314,7 @@ <h4><code><a title="thimble.Thimble" href="#thimble.Thimble">Thimble</a></code><
12881314
</nav>
12891315
</main>
12901316
<footer id="footer">
1291-
<p>Generated by <a href="https://pdoc3.github.io/pdoc" title="pdoc: Python API documentation generator"><cite>pdoc</cite> 0.11.5</a>.</p>
1317+
<p>Generated by <a href="https://pdoc3.github.io/pdoc" title="pdoc: Python API documentation generator"><cite>pdoc</cite> 0.11.6</a>.</p>
12921318
</footer>
12931319
</body>
12941320
</html>

thimble.mpy

348 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)