|
3 | 3 | <head> |
4 | 4 | <meta charset="utf-8"> |
5 | 5 | <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"> |
7 | 7 | <title>thimble API documentation</title> |
8 | 8 | <meta name="description" content=""> |
9 | 9 | <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> |
409 | 409 |
|
410 | 410 | return add_route |
411 | 411 |
|
412 | | - def resolve_route(self, route_pattern): |
| 412 | + def resolve_route(self, route_candidate): |
413 | 413 | """ |
414 | 414 | Given a route pattern (METHOD + url_path), look up the corresponding function. |
415 | 415 |
|
416 | 416 | 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+])$) |
418 | 418 |
|
419 | 419 | Returns: |
420 | 420 | object: reference to function (for non-regex URLs) or tuple with function and regex capture (for regex URLs) |
421 | 421 | """ |
422 | 422 | result = None |
423 | | - if route_pattern in self.routes: # pattern is a fixed string, like: 'GET/gpio/2' |
424 | | - result = self.routes[route_pattern] |
| 423 | + if self.debug: |
| 424 | + print("Looking for a route matching:", route_candidate) |
| 425 | + if route_candidate in self.routes: # pattern is a non-regex string, like: 'GET/gpio/2' |
| 426 | + if self.debug: |
| 427 | + print("Route table had an exact match. We're done!") |
| 428 | + result = self.routes[route_candidate] |
425 | 429 | else: # pattern may contain regex, like 'GET/gpio/([0-9]+)' |
426 | | - for key in self.routes.keys(): |
427 | | - regex_match = match(key, route_pattern) |
| 430 | + if self.debug: |
| 431 | + print("No exact match in route table. Looking for regex matches...") |
| 432 | + for stored_route in self.routes.keys(): |
| 433 | + if self.debug: |
| 434 | + print("Examining this route table entry for potential match:", stored_route) |
| 435 | + regex_match = search("^" + stored_route + "$", route_candidate) |
428 | 436 | if regex_match: |
429 | | - func = self.routes[key] |
| 437 | + if self.debug: |
| 438 | + print("Found a regex match with:", stored_route) |
| 439 | + func = self.routes[stored_route] |
430 | 440 | wildcard_value = regex_match.group(1) |
431 | 441 | if self.debug: |
432 | | - print(f'Wildcard match: {wildcard_value}') |
| 442 | + print(f'Extracted wildcard value: {wildcard_value}') |
433 | 443 | result = func, wildcard_value |
| 444 | + else: |
| 445 | + if self.debug: |
| 446 | + print("No match.") |
434 | 447 |
|
435 | 448 | return result |
436 | 449 |
|
@@ -935,42 +948,55 @@ <h2 id="returns">Returns</h2> |
935 | 948 | <p>nothing</p></div> |
936 | 949 | </dd> |
937 | 950 | <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> |
939 | 952 | </code></dt> |
940 | 953 | <dd> |
941 | 954 | <details class="source"> |
942 | 955 | <summary> |
943 | 956 | <span>Expand source code</span> |
944 | 957 | </summary> |
945 | | -<pre><code class="python">def resolve_route(self, route_pattern): |
| 958 | +<pre><code class="python">def resolve_route(self, route_candidate): |
946 | 959 | """ |
947 | 960 | Given a route pattern (METHOD + url_path), look up the corresponding function. |
948 | 961 |
|
949 | 962 | 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+])$) |
951 | 964 |
|
952 | 965 | Returns: |
953 | 966 | object: reference to function (for non-regex URLs) or tuple with function and regex capture (for regex URLs) |
954 | 967 | """ |
955 | 968 | result = None |
956 | | - if route_pattern in self.routes: # pattern is a fixed string, like: 'GET/gpio/2' |
957 | | - result = self.routes[route_pattern] |
| 969 | + if self.debug: |
| 970 | + print("Looking for a route matching:", route_candidate) |
| 971 | + if route_candidate in self.routes: # pattern is a non-regex string, like: 'GET/gpio/2' |
| 972 | + if self.debug: |
| 973 | + print("Route table had an exact match. We're done!") |
| 974 | + result = self.routes[route_candidate] |
958 | 975 | else: # pattern may contain regex, like 'GET/gpio/([0-9]+)' |
959 | | - for key in self.routes.keys(): |
960 | | - regex_match = match(key, route_pattern) |
| 976 | + if self.debug: |
| 977 | + print("No exact match in route table. Looking for regex matches...") |
| 978 | + for stored_route in self.routes.keys(): |
| 979 | + if self.debug: |
| 980 | + print("Examining this route table entry for potential match:", stored_route) |
| 981 | + regex_match = search("^" + stored_route + "$", route_candidate) |
961 | 982 | if regex_match: |
962 | | - func = self.routes[key] |
| 983 | + if self.debug: |
| 984 | + print("Found a regex match with:", stored_route) |
| 985 | + func = self.routes[stored_route] |
963 | 986 | wildcard_value = regex_match.group(1) |
964 | 987 | if self.debug: |
965 | | - print(f'Wildcard match: {wildcard_value}') |
| 988 | + print(f'Extracted wildcard value: {wildcard_value}') |
966 | 989 | result = func, wildcard_value |
| 990 | + else: |
| 991 | + if self.debug: |
| 992 | + print("No match.") |
967 | 993 |
|
968 | 994 | return result</code></pre> |
969 | 995 | </details> |
970 | 996 | <div class="desc"><p>Given a route pattern (METHOD + url_path), look up the corresponding function.</p> |
971 | 997 | <h2 id="args">Args</h2> |
972 | 998 | <dl> |
973 | | -<dt><strong><code>route_pattern</code></strong> : <code>string</code></dt> |
| 999 | +<dt><strong><code>route_candidate</code></strong> : <code>string</code></dt> |
974 | 1000 | <dd>An uppercase HTTP method concatenated with a URL path wich may contain regex (ex: GET/gpio/([0-9+])$)</dd> |
975 | 1001 | </dl> |
976 | 1002 | <h2 id="returns">Returns</h2> |
@@ -1288,7 +1314,7 @@ <h4><code><a title="thimble.Thimble" href="#thimble.Thimble">Thimble</a></code>< |
1288 | 1314 | </nav> |
1289 | 1315 | </main> |
1290 | 1316 | <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> |
1292 | 1318 | </footer> |
1293 | 1319 | </body> |
1294 | 1320 | </html> |
0 commit comments