application package#

Subpackages#

Submodules#

application.bundler module#

This module handles the (optional) bundling of site files, which can improve performance by decreasing the number of HTTP requests needed to load content.

application.bundler.bundle()#

Bundle all relevant site files.

Return type:

None

application.bundler.bundle_css(path)#

Resolve all imports in a CSS file and bundle into a single (minified) monolithic file.

Parameters:

path (str) – The path to the file.

Return type:

None

application.bundler.bundle_js(path)#

Resolve all imports in a JS file and bundle into a single (minified) monolithic file.

Parameters:

path (str) – The path to the file.

Return type:

None

application.bundler.get_bundled_path(path)#

Get the path of the bundled version of a file, if any.

Parameters:

path (str) – The path of the non-bundled version of the file.

Returns:

The path of the bundled version of the file,

or None if no bundled version exists.

Return type:

str | None

application.bundler.no_bundle()#

Remove any bundled files, if they exist.

Return type:

None

application.tokens module#

This module handles JWT token creation, decoding, and validation for user sessions and API keys.

application.tokens.create_user_token(username)#

Generate a JWT token for a given username and start a session.

This function creates a JWT token using the provided username and a randomly generated token ID. The token is signed using a private key and the RS256 algorithm. After generating the token, it starts a session with the token and username.

Parameters:

username (str) – The username for which the token is being created.

Returns:

The generated JWT token.

Return type:

str

application.tokens.decode_cookies(cookies)#

Decodes a string of cookies into a dictionary.

Parameters:

cookies (str) – A string containing cookies in the format ‘key1=value1; key2=value2; …’.

Returns:

A dictionary where the keys are cookie names and the values are cookie values.

Return type:

dict

application.tokens.decode_user_token(token)#

Decodes a JWT token using a global public key.

Parameters:

token (str) – The JWT token to decode.

Returns:

The decoded token payload.

Return type:

dict

Raises:

InvalidJWTError – If the token is expired or invalid.

application.tokens.get_request_token()#

Extracts the authorization token from the request headers.

The function checks for the ‘Authorization’ header first. If not found, it looks for the ‘Cookie’ header and attempts to decode it to find the ‘Authorization’ token. If neither is found, it returns None.

Returns:

The extracted token if present and valid, otherwise None.

Return type:

str

application.tokens.init()#

Initialize the JWT token system by loading the private and public keys.

Return type:

None

application.tokens.token_is_valid(token)#

Check if the provided token is valid.

This function checks the validity of a token by verifying if it is either a valid session token or a valid API key.

Parameters:

token (str) – The token to be validated.

Returns:

True if the token is valid, False otherwise.

Return type:

bool

Module contents#

This module initializes the Flask application and sets up the database.

It includes the application configuration, schema loading, and route initialization.

application.init(*, no_auth=False, blob_path=None, database_url='')#

Initialize the application and database.

Parameters:
  • no_auth (bool) – Flag to disable authentication. Default is False.

  • blob_path (str, optional) – Path to the blob storage. Default is None.

  • database_url (str) – URL to the database. Default is an empty string.

Returns:

The initialized Flask application instance.

Return type:

Flask