MCPcopy Create free account
hub / github.com/datapane/datapane / match

Method match

python-client/src/datapane/_vendor/bottle.py:453–487  ·  view source on GitHub ↗

Return a (target, url_args) tuple or raise HTTPError(400/404/405).

(self, environ)

Source from the content-addressed store, hash-verified

451 raise RouteBuildError('Missing URL argument: %r' % E.args[0])
452
453 def match(self, environ):
454 """ Return a (target, url_args) tuple or raise HTTPError(400/404/405). """
455 verb = environ['REQUEST_METHOD'].upper()
456 path = environ['PATH_INFO'] or '/'
457
458 methods = ('PROXY', 'HEAD', 'GET', 'ANY') if verb == 'HEAD' else ('PROXY', verb, 'ANY')
459
460 for method in methods:
461 if method in self.static and path in self.static[method]:
462 target, getargs = self.static[method][path]
463 return target, getargs(path) if getargs else {}
464 elif method in self.dyna_regexes:
465 for combined, rules in self.dyna_regexes[method]:
466 match = combined(path)
467 if match:
468 target, getargs = rules[match.lastindex - 1]
469 return target, getargs(path) if getargs else {}
470
471 # No matching route found. Collect alternative methods for 405 response
472 allowed = set([])
473 nocheck = set(methods)
474 for method in set(self.static) - nocheck:
475 if path in self.static[method]:
476 allowed.add(method)
477 for method in set(self.dyna_regexes) - allowed - nocheck:
478 for combined, rules in self.dyna_regexes[method]:
479 match = combined(path)
480 if match:
481 allowed.add(method)
482 if allowed:
483 allow_header = ",".join(sorted(allowed))
484 raise HTTPError(405, "Method not allowed.", Allow=allow_header)
485
486 # No matching route and no alternative method found. We give up
487 raise HTTPError(404, "Not found: " + repr(path))
488
489
490class Route(object):

Callers 2

matchMethod · 0.45
_handleMethod · 0.45

Calls 2

HTTPErrorClass · 0.85
addMethod · 0.80

Tested by

no test coverage detected