magpie.utils

Module Contents

magpie.utils.CONTENT_TYPE_ANY = */*[source]
magpie.utils.CONTENT_TYPE_JSON = application/json[source]
magpie.utils.CONTENT_TYPE_FORM = application/x-www-form-urlencoded[source]
magpie.utils.CONTENT_TYPE_HTML = text/html[source]
magpie.utils.CONTENT_TYPE_PLAIN = text/plain[source]
magpie.utils.SUPPORTED_CONTENT_TYPES[source]
magpie.utils.get_logger(name, level=None)[source]

Immediately sets the logger level to avoid duplicate log outputs from the root logger and this logger when level is NOTSET.

magpie.utils.LOGGER[source]
magpie.utils.print_log(msg, logger=None, level=logging.INFO) → None[source]
magpie.utils.raise_log(msg, exception=Exception, logger=None, level=logging.ERROR) → None[source]
magpie.utils.bool2str(value) → Str[source]
magpie.utils.islambda(func)[source]
magpie.utils.isclass(obj)[source]

Evaluate an object for class type (ie: class definition, not an instance nor any other type).

Parameters:obj – object to evaluate for class type
Returns:(bool) indicating if object is a class
magpie.utils.make_dirs(path)[source]
magpie.utils.get_settings_from_config_ini(config_ini_path, ini_main_section_name='app:magpie_app')[source]
magpie.utils.get_json(response)[source]

Retrieves the ‘JSON’ body of a response using the property/callable according to the response’s implementation.

magpie.utils.get_header(header_name, header_container, default=None, split=None) → Optional[Str][source]

Retrieves header_name by fuzzy match (independently of upper/lower-case and underscore/dash) from various framework implementations of Headers.

If split is specified, the matched header_name is first split with it and the first item is returned. This allows to parse complex headers (e.g.: text/plain; charset=UTF-8 to text/plain with split=';').

Parameters:
  • header_name – header to find.
  • header_container – where to look for header_name.
  • default – value to returned if header_container is invalid or header_name could not be found.
  • split – character(s) to use to split the found header_name.
magpie.utils.convert_response(response) → Response[source]

Converts a response implementation (e.g.: requests.Response) to an equivalent pyramid.response.Response version.

magpie.utils.get_admin_cookies(container, verify=True, raise_message=None) → CookiesType[source]
magpie.utils.get_settings(container) → SettingsType[source]
magpie.utils.patch_magpie_url(container) → SettingsType[source]

Updates potentially missing configuration settings for normal application execution.

magpie.utils.get_magpie_url(container=None) → Str[source]
magpie.utils.get_phoenix_url(container=None) → Str[source]
magpie.utils.get_twitcher_protected_service_url(magpie_service_name, hostname=None)[source]
magpie.utils.log_request_format(request) → Str[source]
magpie.utils.log_request(event)[source]

Subscriber event that logs basic details about the incoming requests.

magpie.utils.log_exception_tween(handler, registry)[source]

Tween factory that logs any exception before re-raising it.

Application errors are marked as ERROR while non critical HTTP errors are marked as WARNING.

class magpie.utils.ExtendedEnumMeta[source]

Bases: enum.EnumMeta

names(cls)[source]

Returns the member names assigned to corresponding enum elements.

values(cls)[source]

Returns the literal values assigned to corresponding enum elements.

get(cls, key_or_value, default=None)[source]

Finds an enum entry by defined name or its value.

Returns the entry directly if it is already a valid enum.

magpie.utils.is_json_body(body)[source]