cowbird.api.requests

Module Contents

Functions

check_value(→ None)

Validates the value against specified type and pattern.

get_request_method_content(request)

get_multiformat_body_raw(→ Any)

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

get_multiformat_body(→ str)

Obtains and validates the matched value under key element from the request body.

get_path_param(→ str)

Obtains the matched value located at the expected position of the specified path variable.

get_query_param(→ Any)

Retrieves a query string value by name (case insensitive), or returns the default if not present.

Attributes

LOGGER

cowbird.api.requests.LOGGER[source]
cowbird.api.requests.check_value(value: Any, param_name: str, check_type: Any = str, pattern: Optional[Union[str, bool]] = ax.PARAM_REGEX, http_error: Optional[Type[pyramid.httpexceptions.HTTPError]] = None, msg_on_fail: Optional[str] = None)None[source]

Validates the value against specified type and pattern.

Parameters
  • value – value to validate.

  • check_type – verify that parameter value is of specified type. Set to None to disable check.

  • pattern – regex pattern to validate the input with. If value evaluates to False, skip this kind of validation (default: ax.PARAM_REGEX).

  • param_name – path variable key.

  • http_error – derived exception to raise on check failure (default: HTTPUnprocessableEntity)

  • msg_on_fail – message details to return in HTTP exception if check failed (default: description message of UnprocessableEntityResponseSchema).

Returns

None.

Raises

HTTPError – if the key is not an applicable path variable for this request.

cowbird.api.requests.get_request_method_content(request)[source]
cowbird.api.requests.get_multiformat_body_raw(request: pyramid.request.Request, key: str, default: Optional[Any] = None)Any[source]

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

cowbird.api.requests.get_multiformat_body(request: pyramid.request.Request, key: str, default: Any = None, check_type: Any = str, pattern: Optional[Union[str, bool]] = ax.PARAM_REGEX, http_error: Optional[Type[pyramid.httpexceptions.HTTPError]] = None, msg_on_fail: Optional[str] = None)str[source]

Obtains and validates the matched value under key element from the request body.

Parsing of the body is accomplished according to Content-Type header.

Parameters
  • request – request from which to retrieve the key.

  • key – body key variable.

  • default – value to return instead if not found. If this default is None, it will raise.

  • check_type – verify that parameter value is of specified type. Set to None to disable check.

  • pattern – regex pattern to validate the input with. If value evaluates to False, skip this kind of validation (default: cowbird.api.exception.PARAM_REGEX).

  • http_error – derived exception to raise on check failure (default: HTTPUnprocessableEntity)

  • msg_on_fail – message details to return in HTTP exception if check failed (default: description message of UnprocessableEntityResponseSchema).

Returns

matched path variable value.

Raises
  • HTTPBadRequest – if the key could not be retrieved from the request body and has no provided default value.

  • HTTPUnprocessableEntity – if the retrieved value from the key is invalid for this request.

cowbird.api.requests.get_path_param(request: pyramid.request.Request, key: str, check_type: Any = str, pattern: Optional[Union[str, bool]] = ax.PARAM_REGEX, http_error: Optional[Type[pyramid.httpexceptions.HTTPError]] = None, msg_on_fail: Optional[str] = None)str[source]

Obtains the matched value located at the expected position of the specified path variable.

Parameters
  • request – request from which to retrieve the key.

  • key – path variable key.

  • check_type – verify that parameter value is of specified type. Set to None to disable check.

  • pattern – regex pattern to validate the input with. If value evaluates to False, skip this kind of validation (default: ax.PARAM_REGEX).

  • http_error – derived exception to raise on check failure (default: HTTPUnprocessableEntity)

  • msg_on_fail – message details to return in HTTP exception if check failed (default: description message of UnprocessableEntityResponseSchema).

Returns

matched path variable value.

Raises

HTTPError – if the key is not an applicable path variable for this request.

cowbird.api.requests.get_query_param(request: pyramid.request.Request, case_insensitive_key: Union[str, Iterable[str]], default: Optional[Any] = None)Any[source]

Retrieves a query string value by name (case insensitive), or returns the default if not present.