magpie.owsrequest

The OWSRequest is based on pywps code:

Attributes

CONTENT_TYPE_FORM

CONTENT_TYPE_JSON

CONTENT_TYPE_PLAIN

LOGGER

Classes

OWSParser

OWSGetParser

Basically a case-insensitive query string parser.

OWSPostParser

MultiFormatParser

Functions

get_multiformat_body(→ Any)

Obtains the value of key element from the request body according to specified Content-Type header.

get_header(= None, split, ...)

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

get_logger(→ logging.Logger)

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

is_json_body(→ bool)

ows_parser_factory(→ OWSParser)

Retrieve the appropriate OWSParser parser using the Content-Type header.

Module Contents

magpie.owsrequest.get_multiformat_body(request: pyramid.request.Request, key: magpie.typedefs.Str, default: Any | None = None) Any[source]

Obtains the value of key element from the request body according to specified Content-Type header.

See also

  • get_multiformat_body_checked()

  • get_permission_multiformat_body_checked()

  • get_value_multiformat_body_checked()

magpie.owsrequest.CONTENT_TYPE_FORM = 'application/x-www-form-urlencoded'[source]
magpie.owsrequest.CONTENT_TYPE_JSON = 'application/json'[source]
magpie.owsrequest.CONTENT_TYPE_PLAIN = 'text/plain'[source]
magpie.owsrequest.get_header(header_name: magpie.typedefs.Str, header_container: magpie.typedefs.AnyHeadersType, default: magpie.typedefs.Str | None, magpie.typedefs.Str | List[magpie.typedefs.Str] | None, bool = None, split: magpie.typedefs.Str | List[magpie.typedefs.Str] | None = None, multi: bool = False, pop: bool = False) magpie.typedefs.Str | List[magpie.typedefs.Str] | None[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.

  • multi – Return extracted header as array of multiple values or return a single value on fist match.

  • pop – Remove the header from the container if found.

Returns:

Found header value(s) if applicable.

magpie.owsrequest.get_logger(name: magpie.typedefs.Str, level: int | None = None, force_stdout: bool = None, message_format: magpie.typedefs.Str | None = None, datetime_format: magpie.typedefs.Str | None = None) logging.Logger[source]

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

magpie.owsrequest.is_json_body(body: Any, return_body: bool = False) bool[source]
magpie.owsrequest.LOGGER[source]
magpie.owsrequest.ows_parser_factory(request: pyramid.request.Request) OWSParser[source]

Retrieve the appropriate OWSParser parser using the Content-Type header.

If the Content-Type header is missing or text/plain, and the request has a body, try to parse the body as JSON and set the content-type to application/json if successful.

Handle XML-like Content-Type headers such as application/x-www-form-urlencoded whenever applicable.

Otherwise, use the basic OWSGetParser or OWSPostParser according to the presence of a body. These provide minimal parsing to handle most typical OGC Web Services (OWS) request parameters.

class magpie.owsrequest.OWSParser(request)[source]

Bases: object

parse(param_list)[source]

Parses the initialized request to populate params retrieved from the parser.

Once this method has been called, all expected parameters are guaranteed to exist within :attr`params`. Missing query parameters from the request will be set to None. All query parameter names will be normalized to lower characters for easier retrieval.

Parameters:

param_list – all known query parameters to the service.

abstract _get_param_value(param)[source]
class magpie.owsrequest.OWSGetParser(request)[source]

Bases: OWSParser

Basically a case-insensitive query string parser.

_request_params()[source]
_get_param_value(param)[source]
class magpie.owsrequest.OWSPostParser(request)[source]

Bases: OWSParser

_get_param_value(param)[source]
class magpie.owsrequest.MultiFormatParser(request)[source]

Bases: OWSParser

_get_param_value(param)[source]