Fiole API

Decorators

fiole.route(url, methods=('GET', 'HEAD'), callback=None, status=200)

Register a method for processing requests.

fiole.get(url)

Register a method as capable of processing GET/HEAD requests.

fiole.post(url)

Register a method as capable of processing POST requests.

fiole.put(url)

Register a method as capable of processing PUT requests.

fiole.delete(url)

Register a method as capable of processing DELETE requests.

fiole.errorhandler(code)

Register a method for processing errors of a certain HTTP code.

Helpers

fiole.send_file(request, filename, root=None, content_type=None, buffer_size=65536)

Fetch a static file from the filesystem.

fiole.get_template(name=None, source=None, require=None)

Return a compiled template.

fiole.render_template(template_name=None, source=None, **context)

Render a template with values of the context dictionary.

fiole.engine

Default instance of the Template Engine.

fiole.default_app

Default Fiole application.

fiole.get_app()

Get the Fiole application which is on the top of the stack.

fiole.run_wsgiref(host, port, handler)

Simple HTTPServer that supports WSGI.

fiole.run_fiole(app=default_app, server=run_wsgiref, host=None, port=None)

Run the Fiole web server.

WSGI application

class fiole.Fiole

Web Application.

classmethod push(app=None)

Push a new Fiole application on the stack.

classmethod pop(index=-1)

Remove the Fiole application from the stack.

debug

Enable debugging: don’t catch internal server errors (500) and unhandled exceptions. (default: False)

secret_key

Secret key used to sign secure cookies. (default: unset)

static_folder

Directory where static files are located. (default: ./static)

hooks

List of Hooks which are registered for this application.

handle_request(environ, start_response)

The main handler. Dispatch to the user’s code.

handle_error(exception, environ, level=0)

Deal with the exception and present an error page.

find_matching_url(request)

Search through the methods registered.

route(url, methods=('GET', 'HEAD'), callback=None, status=200)

Register a method for processing requests.

get(url)

Register a method as capable of processing GET/HEAD requests.

post(url)

Register a method as capable of processing POST requests.

put(url)

Register a method as capable of processing PUT requests.

delete(url)

Register a method as capable of processing DELETE requests.

errorhandler(code)

Register a method for processing errors of a certain HTTP code.

encode_signed(name, value)

Return a signed string with timestamp.

decode_signed(name, value, max_age_days=31)

Decode a signed string with timestamp or return None.

send_file(request, filename, root=None, content_type=None, buffer_size=65536)

Fetch a static file from the filesystem.

class fiole.Request(environ)

An object to wrap the environ bits in a friendlier way.

Environment variables are also accessible through Request attributes.

environ

Dictionary of environment variables

path

Path of the request, decoded and with / appended.

method

HTTP method (GET, POST, PUT, ...).

query

Read QUERY_STRING from the environment.

script_name

Read SCRIPT_NAME from the environment.

host_url

Build host URL.

headers

An instance of EnvironHeaders which wraps HTTP headers.

content_length

Header "Content-Length" of the request as integer or 0.

accept

Header "Accept" of the request. Return an Accept instance.

accept_charset

Header "Accept-Charset" of the request. Return an Accept instance.

accept_encoding

Header "Accept-Encoding" of the request. Return an Accept instance.

accept_language

Header "Accept-Language" of the request. Return an Accept instance.

GET

A dictionary of GET parameters.

POST

A dictionary of POST (or PUT) values, including files.

PUT

A dictionary of POST (or PUT) values, including files.

body

Content of the request.

cookies

A dictionary of Cookie.Morsel objects.

Get the value of the cookie with the given name, else default.

Return the given signed cookie if it validates, or None.

get_url(path='', full=False)

Build the absolute URL for an application path.

By default it builds the current request URL with leading and trailing / and no query string. The boolean argument full builds a full URL, incl. host.

class fiole.Response(output, headers=None, status=200, content_type='text/html', wrapped=False)
charset = 'utf-8'
status

Status code of the response as integer (default: 200)

headers

Response headers as HTTPHeaders.

Set the given cookie name/value with the given options.

Delete the cookie with the given name.

Sign and timestamp a cookie so it cannot be forged.

send(environ, start_response)

Send the headers and return the body of the response.

class fiole.HTTPHeaders(headers=None)

An object that stores some headers.

An instance of HTTPHeaders is an iterable. It yields tuples (header_name, value). Additionally it provides a dict-like interface to access or change individual headers.

__getitem__(name)

Access the header by name. This method is case-insensitive and the first matching header is returned. It returns None if the header does not exist.

get(name, default=None)

Return the default value if the header doesn’t exist.

get_all(name)

Return a list of all the values for the header.

add(name, value, **kw)

Add a new header tuple to the list.

set(name, value, **kw)

Remove all header tuples for key and add a new one.

setdefault(name, value)

Add a new header if not present. Return the value.

to_list(charset='iso-8859-1')

Convert the headers into a list.

keys()
values()
items()
class fiole.EnvironHeaders(environ)

Headers from a WSGI environment. Read-only view.

__getitem__(name)

Access the header by name. This method is case-insensitive and returns None if the header does not exist.

get(name, default=None)

Return the default value if the header doesn’t exist.

get_all(name)

Return a list of all the values for the header.

keys()
values()
items()
class fiole.Accept(header_name, value)

Represent an Accept-style header.

__contains__(offer)

Return True if the given offer is listed in the accepted types.

quality(offer)

Return the quality of the given offer.

best_match(offers, default_match=None)

Return the best match in the sequence of offered types.

exception fiole.HTTPError(message, hide_traceback=False)

Base exception for HTTP errors.

exception fiole.BadRequest(message, hide_traceback=True)
exception fiole.Forbidden(message, hide_traceback=True)
exception fiole.NotFound(message, hide_traceback=True)
exception fiole.MethodNotAllowed(message, hide_traceback=True)
exception fiole.Redirect(url)

Redirect the user to a different URL.

exception fiole.InternalServerError(message, hide_traceback=False)

Template engine

class fiole.Engine(loader=None, parser=None, template_class=None)

Assemble the template engine.

global_vars

This mapping contains additional globals which are injected in the generated source. Two special globals are used internally and must not be modified: _r and _i. The functions str and escape (alias e) are also added here. They are used as filters. They can be replaced by C extensions for performance (see Webext). Any object can be added to this registry for usage in the templates, either as function or filter.

default_filters

The list of filters which are applied to all template expressions {{ ... }}. Set to None to remove all default filters, for performance. (default: [‘str’])

clear()

Remove all compiled templates from the internal cache.

get_template(name=None, **kwargs)

Return a compiled template.

The optional keyword argument default_filters overrides the setting which is configured on the Engine.

remove(name)

Remove given name from the internal cache.

import_name(name, **kwargs)

Compile and return a template as module.

class fiole.Template

Simple template class.

name

Name of the template (it can be None).

render(context)
render(**context)

Render the template with these arguments (either a dictionary or keyword arguments).

class fiole.Loader(templates=None)

Load templates.

templates - a dict where key corresponds to template name and value to template content.

template_folder

Directory where template files are located. (default: ./templates)

list_names()

List all keys from internal dict.

load(name, source=None)

Return template by name.

class fiole.Lexer(lexer_rules)

Tokenize input source per rules supplied.

tokenize(source)

Translate source into an iterable of tokens.

class fiole.Parser(token_start='%', var_start='{{', var_end='}}', line_join='\')

Include basic statements, variables processing and markup.

tokenize(source)

Translate source into an iterable of tokens.

end_continue(tokens)

If token is continue prepend it with end token so it simulates a closed block.

parse_iter(tokens)

Process and yield groups of tokens.

class fiole.BlockBuilder(indent='', lineno=0, nodes=(), default_filters=None)
filters = {'e': 'escape'}

A mapping of declared template filters (aliases of globals). This mapping can be extended. The globals can be extended too, see Engine.global_vars.

rules

A mapping of tokens with list of methods, to generate the source code.

add(lineno, code)

Add Python code to the source.

compile_code(name)

Compile the generated source code.

Table Of Contents

Previous topic

Build templates

Next topic

Developer’s notes

This Page