Package translate :: Package misc :: Module selector :: Class Selector
[hide private]
[frames] | no frames]

Class Selector

source code


WSGI middleware for URL paths and HTTP method based delegation.

see http://lukearno.com/projects/selector/

mappings are given are an iterable that returns tuples like this:

(path_expression, http_methods_dict, optional_prefix)

Instance Methods [hide private]
 
__init__(self, mappings=None, prefix='', parser=None, wrap=None, mapfile=None, consume_path=True)
Initialize selector.
source code
 
slurp(self, mappings, prefix=None, parser=None, wrap=None)
Slurp in a whole list (or iterable) of mappings.
source code
 
add(self, path, method_dict=None, prefix=None, **http_methods)
Add a mapping.
source code
 
__call__(self, environ, start_response)
Delegate request to the appropriate WSGI app.
source code
 
select(self, path, method)
Figure out which app to delegate to or send 404 or 405.
source code
 
slurp_file(self, the_file, prefix=None, parser=None, wrap=None)
Read mappings from a simple text file.
source code
 
_parse_line(self, line, path, methods)
Parse one line of a mapping file.
source code

Inherited from object: __delattr__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __str__

Static Methods [hide private]
 
status405(environ, start_response)
Respond with a 405 and appropriate Allow header.
source code
 
status404(environ, start_response)
Respond with a 404.
source code
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, mappings=None, prefix='', parser=None, wrap=None, mapfile=None, consume_path=True)
(Constructor)

source code 

Initialize selector.

Overrides: object.__init__

slurp(self, mappings, prefix=None, parser=None, wrap=None)

source code 

Slurp in a whole list (or iterable) of mappings.

Prefix and parser args will override self.parser and self.args for the given mappings.

add(self, path, method_dict=None, prefix=None, **http_methods)

source code 

Add a mapping.

HTTP methods can be specified in a dict or using kwargs, but kwargs will override if both are given.

Prefix will override self.prefix for this mapping.

slurp_file(self, the_file, prefix=None, parser=None, wrap=None)

source code 
Read mappings from a simple text file.

== Format looks like this: ==

{{{

# Comments if first non-whitespace char on line is '#'
# Blank lines are ignored

/foo/{id}[/]
    GET somemodule:some_wsgi_app
    POST pak.subpak.mod:other_wsgi_app

@prefix /myapp
/path[/]
    GET module:app
    POST package.module:get_app('foo')
    PUT package.module:FooApp('hello', resolve('module.setting'))

@parser :lambda x: x
@prefix 
^/spam/eggs[/]$
    GET mod:regex_mapped_app

}}}

@prefix and @parser directives take effect 
until the end of the file or until changed

_parse_line(self, line, path, methods)

source code 

Parse one line of a mapping file.

This method is for the use of selector.slurp_file.