cowbird.api.requests

Attributes

LOGGER

Functions

check_value(→ None)

Validates the value against specified type and pattern.

get_request_method_content(→ Dict[str, Any])

get_multiformat_body_raw(→ Any)

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

get_multiformat_body(…)

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.

Module Contents

cowbird.api.requests.LOGGER[source]
cowbird.api.requests.check_value(value: Any, param_name: str, check_type: Type[Any] | Tuple[Type[Any], Ellipsis] = str, pattern: str | bool | None = ax.PARAM_REGEX, http_error: Type[pyramid.httpexceptions.HTTPError] | None = None, msg_on_fail: str | None = 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: pyramid.request.Request) Dict[str, Any][source]
cowbird.api.requests.get_multiformat_body_raw(request: pyramid.request.Request, key: str, default: Any | None = 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: Type[str] = str, pattern: str | bool | None = ax.PARAM_REGEX, http_error: Type[pyramid.httpexceptions.HTTPError] | None = None, msg_on_fail: str | None = None) str[source]
cowbird.api.requests.get_multiformat_body(request: pyramid.request.Request, key: str, default: Any = None, check_type: Type[str | None] = (str, type(None)), pattern: str | bool | None = ax.PARAM_REGEX, http_error: Type[pyramid.httpexceptions.HTTPError] | None = None, msg_on_fail: str | None = None) str | None
cowbird.api.requests.get_multiformat_body(request: pyramid.request.Request, key: str, default: Any = None, check_type: Type[int] = int, pattern: str | bool | None = ax.PARAM_REGEX, http_error: Type[pyramid.httpexceptions.HTTPError] | None = None, msg_on_fail: str | None = None) int
cowbird.api.requests.get_multiformat_body(request: pyramid.request.Request, key: str, default: Any = None, check_type: Type[float] = float, pattern: str | bool | None = ax.PARAM_REGEX, http_error: Type[pyramid.httpexceptions.HTTPError] | None = None, msg_on_fail: str | None = None) float
cowbird.api.requests.get_multiformat_body(request: pyramid.request.Request, key: str, default: Any = None, check_type: Type[bool] = bool, pattern: str | bool | None = ax.PARAM_REGEX, http_error: Type[pyramid.httpexceptions.HTTPError] | None = None, msg_on_fail: str | None = None) bool
cowbird.api.requests.get_multiformat_body(request: pyramid.request.Request, key: str, default: Any = None, check_type: Type[List[Any]] = list, pattern: str | bool | None = ax.PARAM_REGEX, http_error: Type[pyramid.httpexceptions.HTTPError] | None = None, msg_on_fail: str | None = None) cowbird.typedefs.JSON
cowbird.api.requests.get_multiformat_body(request: pyramid.request.Request, key: str, default: Any = None, check_type: Type[Dict[str, Any]] = dict, pattern: str | bool | None = ax.PARAM_REGEX, http_error: Type[pyramid.httpexceptions.HTTPError] | None = None, msg_on_fail: str | None = None) cowbird.typedefs.JSON

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: str | bool | None = ax.PARAM_REGEX, http_error: Type[pyramid.httpexceptions.HTTPError] | None = None, msg_on_fail: str | None = 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: str | Iterable[str], default: Any | None = None) Any[source]

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