cowbird.api.requests
Module Contents
Functions
|
Validates the value against specified type and pattern. |
|
|
|
Obtains the value of |
|
Obtains and validates the matched value under |
|
Obtains the matched value located at the expected position of the specified path variable. |
|
Retrieves a query string value by name (case insensitive), or returns the default if not present. |
Attributes
-
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_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.See also
-
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.
See also
-
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.