URI building and routing classes. Ported from webapp2, refactored to support Python versions > 2.7, 3.0
Interface for URI routes.
The custom handler method, if handler is a class.
The handler, imported and ready for dispatching.
The uri regex template.
The handler or string in dotted notation to be lazily imported.
Route name, used to build URIs.
True if this route is only used for URI generation and never matches.
Matches all routes against a request object.
The first one that matches is returned.
Parameters: | request – A Request instance. |
---|---|
Returns: | A tuple (route, args, kwargs) if a route matched, or None. |
Returns a URI for this route.
Parameters: |
|
---|---|
Returns: | An absolute or relative URI. |
Generator to get all routes from a route.
Yields: | This route or all nested routes that it contains. |
---|
A route that is compatible with webapp’s routing mechanism.
URI building is not implemented as webapp has rudimentar support for it, and this is the most unknown webapp feature anyway.
Lazy regex compiler.
Matches this route against the current request.
See also
A route definition that maps a URI path to a handler.
The initial concept was based on Another Do-It-Yourself Framework, by Ian Bicking.
Default parameters values.
Sequence of allowed HTTP methods. If not set, all methods are allowed.
Sequence of allowed URI schemes. If not set, all schemes are allowed.
Lazy route template parser.
Matches this route against the current request.
Raises: | exc.HTTPMethodNotAllowed if the route defines methods and the request method isn’t allowed. |
---|
See also
Returns a URI for this route.
See also
A URI router used to match, dispatch and build URIs.
Class used when the route is set as a tuple.
alias of SimpleRoute
All routes that can be matched.
All routes that can be built.
Handler classes imported lazily.
Adds a route to this router.
Parameters: | route – A Route instance or, for simple routes, a tuple (regex, handler). |
---|
Sets the function called to match URIs.
Parameters: | func – A function that receives (router, request) and returns a tuple (route, args, kwargs) if any route matches, or raise exc.HTTPNotFound if no route matched or exc.HTTPMethodNotAllowed if a route matched but the HTTP method was not allowed. |
---|
Sets the function called to build URIs.
Parameters: | func – A function that receives (router, request, name, args, kwargs) and returns a URI. |
---|
Sets the function called to dispatch the handler.
Parameters: | func – A function that receives (router, request, response) and returns the value returned by the dispatched handler. |
---|
Sets the function that adapts loaded handlers for dispatching.
Parameters: | func – A function that receives (router, handler) and returns a handler callable. |
---|
Matches all routes against a request object.
The first one that matches is returned.
Parameters: | request – A Request instance. |
---|---|
Returns: | A tuple (route, args, kwargs) if a route matched, or None. |
Raises: | exc.HTTPNotFound if no route matched or exc.HTTPMethodNotAllowed if a route matched but the HTTP method was not allowed. |
Returns a URI for a named Route.
Parameters: |
|
---|---|
Returns: | An absolute or relative URI. |
Dispatches a handler.
Parameters: |
|
---|---|
Raises: | exc.HTTPNotFound if no route matched or exc.HTTPMethodNotAllowed if a route matched but the HTTP method was not allowed. |
Returns: | The returned value from the handler. |
Adapts a handler for dispatching.
Because handlers use or implement different dispatching mechanisms, they can be wrapped to use a unified API for dispatching. This way webapp2 can support, for example, a RequestHandler class and function views or, for compatibility purposes, a webapp.RequestHandler class. The adapters follow the same router dispatching API but dispatch each handler type differently.
Parameters: | handler – A handler callable. |
---|---|
Returns: | A wrapped handler callable. |
Matches all routes against a request object.
The first one that matches is returned.
Parameters: | request – A Request instance. |
---|---|
Returns: | A tuple (route, args, kwargs) if a route matched, or None. |
Raises: | exc.HTTPNotFound if no route matched or exc.HTTPMethodNotAllowed if a route matched but the HTTP method was not allowed. |
Returns a URI for a named Route.
Parameters: |
|
---|---|
Returns: | An absolute or relative URI. |
Dispatches a handler.
Parameters: |
|
---|---|
Raises: | exc.HTTPNotFound if no route matched or exc.HTTPMethodNotAllowed if a route matched but the HTTP method was not allowed. |
Returns: | The returned value from the handler. |
Adapts a handler for dispatching.
Because handlers use or implement different dispatching mechanisms, they can be wrapped to use a unified API for dispatching. This way webapp2 can support, for example, a RequestHandler class and function views or, for compatibility purposes, a webapp.RequestHandler class. The adapters follow the same router dispatching API but dispatch each handler type differently.
Parameters: | handler – A handler callable. |
---|---|
Returns: | A wrapped handler callable. |