zask package

Submodules

zask.config module

zask.config

  1. remove useless methods of flask.config
  2. update docstring
copyright:
  1. 2015 by the J5
license:

BSD, see LICENSE for more details.

copyright:
  1. 2015 by the Werkzeug Team, see AUTHORS for more details.
license:

BSD, see LICENSE for more details.

class zask.config.Config(root_path, defaults=None)[source]

Bases: dict

Works exactly like a dict but provides ways to fill it from files or special dictionaries. There are two common patterns to populate the config.

You can fill the config from a config file:

app.config.from_pyfile('yourconfig.cfg')

Only uppercase keys are added to the config. This makes it possible to use lowercase values in the config file for temporary values that are not added to the config or to define the config keys in the same file that implements the application.

Probably the most interesting way to load configurations is from an environment variable pointing to a file:

app.config.from_envvar('YOURAPPLICATION_SETTINGS')

In this case before launching the application you have to set this environment variable to the file you want to use. On Linux and OS X use the export statement:

export YOURAPPLICATION_SETTINGS='/path/to/config/file'

On windows use set instead.

Parameters:
  • root_path – path to which files are read relative from. When the config object is created by the application, this is the application’s root_path.
  • defaults – an optional dictionary of default values
from_envvar(variable_name, silent=False)[source]

Loads a configuration from an environment variable pointing to a configuration file. This is basically just a shortcut with nicer error messages for this line of code:

app.config.from_pyfile(os.environ['YOURAPPLICATION_SETTINGS'])
Parameters:
  • variable_name – name of the environment variable
  • silent – set to True if you want silent failure for missing files.
Returns:

bool. True if able to load config, False otherwise.

from_object(obj)[source]

Updates the values from the given object. An object can be of one of the following two types:

  • a string: in this case the object with that name will be imported
  • an actual object reference: that object is used directly

Objects are usually either modules or classes.

Just the uppercase variables in that object are stored in the config. Example usage:

app.config.from_object('yourapplication.default_config')
from yourapplication import default_config
app.config.from_object(default_config)

You should not use this function to load the actual configuration but rather configuration defaults. The actual config should be loaded with from_pyfile() and ideally from a location not within the package because the package might be installed system wide.

Parameters:obj – an import name or object
from_pyfile(filename, silent=False)[source]

Updates the values in the config from a Python file. This function behaves as if the file was imported as module with the from_object() function.

Parameters:
  • filename – the filename of the config. This can either be an absolute filename or a filename relative to the root path.
  • silent – set to True if you want silent failure for missing files.
get_namespace(namespace, lowercase=True, trim_namespace=True)[source]

Returns a dictionary containing a subset of configuration options that match the specified namespace/prefix. Example usage:

config['IMAGE_STORE_TYPE'] = 'fs'
config['IMAGE_STORE_PATH'] = '/var/app/images'
config['IMAGE_STORE_BASE_URL'] = 'http://img.website.com'
image_store_config = config.get_namespace('IMAGE_STORE_')

The resulting dictionary image_store would look like:

{
    'type': 'fs',
    'path': '/var/app/images',
    'base_url': 'http://img.website.com'
}

This is often useful when configuration options map directly to keyword arguments in functions or class constructors.

Parameters:
  • namespace – a configuration namespace
  • lowercase – a flag indicating if the keys of the resulting dictionary should be lowercase
  • trim_namespace – a flag indicating if the keys of the resulting dictionary should not include the namespace

zask.logging module

zask.logging

Implements the logging support for Zask.

copyright:
  1. 2015 by the J5.
license:

BSD, see LICENSE for more details.

zask.logging.create_logger(config)[source]

Creates a logger for the application. Logger’s behavior depend on DEBUG flag.Furthermore this function also removes all attached handlers in case there was a logger with the log name before.

zask.logging.debug_handler()[source]
zask.logging.production_handler(config)[source]

zask.utils module

zask.utils

  1. remove useless methods of werkzeug.utils
  2. add get_root_path
copyright:
  1. 2015 by the J5.
license:

BSD, see LICENSE for more details.

copyright:
  1. 2015 by the Werkzeug Team, see AUTHORS for more details.
license:

BSD, see LICENSE for more details.

exception zask.utils.ImportStringError(import_name, exception)[source]

Bases: exceptions.ImportError

Provides information about a failed import_string() attempt.

exception = None

Wrapped exception.

import_name = None

String in dotted notation that failed to be imported.

zask.utils.get_root_path(import_name)[source]
zask.utils.import_string(import_name, silent=False)[source]

Imports an object based on a string. This is useful if you want to use import paths as endpoints or something similar. An import path can be specified either in dotted notation (xml.sax.saxutils.escape) or with a colon as object delimiter (xml.sax.saxutils:escape).

If silent is True the return value will be None if the import fails.

Parameters:
  • import_name – the dotted name for the object to import.
  • silent – if set to True import errors are ignored and None is returned instead.
Returns:

imported object

Module contents

class zask.LocalContext[source]

Bases: object

get_request_cxt()[source]
class zask.Zask(import_name)[source]

Bases: object

logger