MCPcopy
hub / github.com/fluentpython/example-code-2e / route

Method route

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

A decorator to bind a function to a request URL. Example:: @app.route('/hello/:name') def hello(name): return 'Hello %s' % name The ``:name`` part is a wildcard. See :class:`Router` for syntax details. :param

(self, path=None, method='GET', callback=None, name=None,
              apply=None, skip=None, **config)

Source from the content-addressed store, hash-verified

780 if DEBUG: route.prepare()
781
782 def route(self, path=None, method='GET', callback=None, name=None,
783 apply=None, skip=None, **config):
784 """ A decorator to bind a function to a request URL. Example::
785
786 @app.route('/hello/:name')
787 def hello(name):
788 return 'Hello %s' % name
789
790 The ``:name`` part is a wildcard. See :class:`Router` for syntax
791 details.
792
793 :param path: Request path or a list of paths to listen to. If no
794 path is specified, it is automatically generated from the
795 signature of the function.
796 :param method: HTTP method (`GET`, `POST`, `PUT`, ...) or a list of
797 methods to listen to. (default: `GET`)
798 :param callback: An optional shortcut to avoid the decorator
799 syntax. ``route(..., callback=func)`` equals ``route(...)(func)``
800 :param name: The name for this route. (default: None)
801 :param apply: A decorator or plugin or a list of plugins. These are
802 applied to the route callback in addition to installed plugins.
803 :param skip: A list of plugins, plugin classes or names. Matching
804 plugins are not installed to this route. ``True`` skips all.
805
806 Any additional keyword arguments are stored as route-specific
807 configuration and passed to plugins (see :meth:`Plugin.apply`).
808 """
809 if callable(path): path, callback = None, path
810 plugins = makelist(apply)
811 skiplist = makelist(skip)
812 def decorator(callback):
813 # TODO: Documentation and tests
814 if isinstance(callback, basestring): callback = load(callback)
815 for rule in makelist(path) or yieldroutes(callback):
816 for verb in makelist(method):
817 verb = verb.upper()
818 route = Route(self, rule, verb, callback, name=name,
819 plugins=plugins, skiplist=skiplist, **config)
820 self.add_route(route)
821 return callback
822 return decorator(callback) if callback else decorator
823
824 def get(self, path=None, method='GET', **options):
825 """ Equals :meth:`route`. """

Callers 5

mountMethod · 0.95
getMethod · 0.95
postMethod · 0.95
putMethod · 0.95
deleteMethod · 0.95

Calls 2

makelistFunction · 0.85
decoratorFunction · 0.85

Tested by

no test coverage detected