selector Module¶
selector - WSGI handler delegation. (AKA routing.)
-
class
selector.
ByMethod
¶ Bases:
object
Base class for dispatching to method named by REQUEST_METHOD.
-
exception
selector.
MappingFileError
¶ Bases:
exceptions.Exception
Raised to signal a syntax error in a mapping file.
-
class
selector.
MiddlewareComposer
(app, rules)¶ Bases:
object
Compose middleware based on list of rules.
-
exception
selector.
PathExpressionParserError
¶ Bases:
exceptions.Exception
Raised to signal a syntax error in a path expression.
-
class
selector.
Selector
(mappings=None, prefix='', parser=None, wrap=None, mapfile=None, consume_path=True)¶ Bases:
object
WSGI middleware for URL paths and HTTP method based delegation.
-
add
(path, method_dict=None, prefix=None, **http_methods)¶ Add a mapping.
HTTP methods can be specified in a dict or using key word args, but kwargs will override if both are given.
-
select
(path, method)¶ Figure out which app to delegate to or send 404 or 405.
-
slurp
(mappings, prefix=None, parser=None, wrap=None)¶ Slurp in a whole list (or any iterable) of mappings.
Mappings take the form of
(PATH_EXPRESSION, HTTP_METHOD_TO_WSGI_APP_DICT)
-
slurp_file
(filename, prefix=None, parser=None, wrap=None)¶ Read mappings from a simple text file. (See README.md.)
-
static
status404
(environ, start_response)¶ Default WSGI 404 app.
-
static
status405
(environ, start_response)¶ Default WSGI 405 app.
-
-
class
selector.
SimpleParser
(patterns=None)¶ Bases:
object
Callable to turn path expressions into regexes with named groups.
SimpleParser()("/hello/{name}") == r"^\/hello\/(?P<name>[^\^.]+)$"
See README.md for details.
-
default_pattern
= 'chunk'¶
-
end
= '}'¶
-
oend
= ']'¶
-
ostart
= '['¶
-
start
= '{'¶
-
-
selector.
expose
(obj)¶ Set obj._exposed = True and return obj.
-
selector.
method_not_allowed
(environ, start_response)¶ Default WSGI 405 app.
-
selector.
not_found
(environ, start_response)¶ Default WSGI 404 app.
-
selector.
opliant
(meth)¶ Decorate a bound wsgi callable taking args from wsgiorg.routing_args.
class App(object): @opliant def __call__(self, environ, start_response, arg1, arg2, foo='bar'): ...
-
selector.
pliant
(func)¶ Decorate an unbound wsgi callable taking args from wsgiorg.routing_args.
@pliant def app(environ, start_response, arg1, arg2, foo='bar'): ...