aspen.request_processor
¶
The request processor dispatches requests to the filesystem, typecasts URL path variables, loads the resource from the filesystem, and then renders and encodes the resource (if it’s dynamic).
-
class
aspen.request_processor.
RequestProcessor
(**kwargs)¶ A core request processor designed for integration into a host framework.
The
kwargs
are for configuration, seeDefaultConfiguration
for valid keys and default values.-
dispatch
(path)¶ Call the dispatcher and inject the path variables into the given path object.
Parameters: path (Path) – the requested path, e.g. '/foo'
Returns: A DispatchResult
object.
-
process
(path, querystring, accept_header, context)¶ Process a request.
Parameters: - path (Path) – the requested path, e.g.
Path('/foo')
- querystring (Querystring) – the query parameters, e.g.
Querystring('?bar=baz')
- accept_header (str) – the value of the HTTP header
Accept
- context (dict) – the context variables passed to dynamic resources
Returns: A 3-tuple
(dispatch_result, resource, output)
. The latter two are set toNone
if dispatching failed.- path (Path) – the requested path, e.g.
-
is_dynamic
(fspath)¶ Given a filesystem path, return a boolean.
-
get_resource_class
(fspath)¶ Given a filesystem path, return a resource class.
-
guess_media_type
(filename)¶ Guess the media type of a file by looking at its extension.
This method is a small wrapper around
mimetypes.guess_type()
. It returnsmedia_type_default
if the guessing fails.
-
-
class
aspen.request_processor.
DefaultConfiguration
¶ Default configuration values.
-
changes_reload
= False¶ Reload files on every request if they’ve been modified. This can be costly, so it should be turned off in production.
-
charset_static
= None¶ The charset of your static files. It ends up as a
charset=
parameter inContent-Type
HTTP headers (if the framework on top of Aspen supports that).
-
dispatcher_class
= None¶ The kind of dispatcher that will be used to route requests to files. By default
UserlandDispatcher
is used, unlesschanges_reload
is set toTrue
, thenHybridDispatcher
is used.
-
encode_output_as
= 'UTF-8'¶ The encoding to use for dynamically-generated output.
-
indices
= ['index.html', 'index.json', 'index', 'index.html.spt', 'index.json.spt', 'index.spt']¶ List of file names that will be treated as directory indexes. The order matters.
-
media_type_default
= 'text/plain'¶ If the
Content-Type
of a response can’t be determined, then this one is used.
-
media_type_json
= 'application/json'¶ The media type to use for the JSON format.
-
project_root
= None¶ The root directory of your project.
-
renderer_default
= 'stdlib_percent'¶ The default renderer for simplates.
-
resource_directories
= []¶ The list of directories containing resource files. Aspen will refuse to load any resource located outside these directories. The www_root directory is automatically added to this list. The project_root directory is added as well if it exists.
-
store_static_files_in_ram
= False¶ If set to
True
, store the contents of static files in RAM.
-
typecasters
= {'float': <function <lambda>>, 'int': <function <lambda>>}¶
-
www_root
= None¶ The root directory of your web app, containing the files it will serve. Defaults to the current directory.
-