MCPcopy Index your code
hub / github.com/fluentpython/example-code-2e / yieldroutes

Function yieldroutes

21-async/mojifinder/bottle.py:2637–2654  ·  view source on GitHub ↗

Return a generator for routes that match the signature (name, args) of the func parameter. This may yield more than one route if the function takes optional keyword arguments. The output is best described by example:: a() -> '/a' b(x, y) -> '/b/ / '

(func)

Source from the content-addressed store, hash-verified

2635
2636
2637def yieldroutes(func):
2638 """ Return a generator for routes that match the signature (name, args)
2639 of the func parameter. This may yield more than one route if the function
2640 takes optional keyword arguments. The output is best described by example::
2641
2642 a() -> '/a'
2643 b(x, y) -> '/b/<x>/<y>'
2644 c(x, y=5) -> '/c/<x>' and '/c/<x>/<y>'
2645 d(x=5, y=6) -> '/d' and '/d/<x>' and '/d/<x>/<y>'
2646 """
2647 path = '/' + func.__name__.replace('__','/').lstrip('/')
2648 spec = getargspec(func)
2649 argc = len(spec[0]) - len(spec[3] or [])
2650 path += ('/<%s>' * argc) % tuple(spec[0][:argc])
2651 yield path
2652 for arg in spec[0][argc:]:
2653 path += '/<%s>' % arg
2654 yield path
2655
2656
2657def path_shift(script_name, path_info, shift=1):

Callers 1

decoratorMethod · 0.85

Calls 1

replaceMethod · 0.45

Tested by

no test coverage detected