Utils¶
-
cliquet.utils.
strip_whitespace
(v)¶ Remove whitespace, newlines, and tabs from the beginning/end of a string.
Parameters: v (str) – the string to strip. Return type: str
-
cliquet.utils.
msec_time
()¶ Return current epoch time in milliseconds.
Return type: int
-
cliquet.utils.
classname
(obj)¶ Get a classname from an object.
Return type: str
-
cliquet.utils.
merge_dicts
(a, b)¶ Merge b into a recursively, without overwriting values.
Parameters: a (dict) – the dict that will be altered with values of b. Return type: None
-
cliquet.utils.
random_bytes_hex
(bytes_length)¶ Return a hexstring of bytes_length cryptographic-friendly random bytes.
Parameters: bytes_length (integer) – number of random bytes. Return type: str
-
cliquet.utils.
native_value
(value)¶ Convert string value to native python values.
Parameters: value (str) – value to interprete. Returns: the value coerced to python type
-
cliquet.utils.
read_env
(key, value)¶ Read the setting key from environment variables.
Parameters: - key – the setting name
- value – default value if undefined in environment
Returns: the value from environment, coerced to python type
-
cliquet.utils.
encode64
(content, encoding='utf-8')¶ Encode some content in base64.
Return type: str
-
cliquet.utils.
decode64
(encoded_content, encoding='utf-8')¶ Decode some base64 encoded content.
Return type: str
-
cliquet.utils.
hmac_digest
(secret, message, encoding='utf-8')¶ Return hex digest of a message HMAC using secret
-
cliquet.utils.
reapply_cors
(request, response)¶ Reapply cors headers to the new response with regards to the request.
We need to re-apply the CORS checks done by Cornice, in case we’re recreating the response from scratch.
-
cliquet.utils.
current_service
(request)¶ Return the Cornice service matching the specified request.
Returns: the service or None if unmatched. Return type: cornice.Service
-
cliquet.utils.
build_request
(original, dict_obj)¶ Transform a dict object into a
pyramid.request.Request
object.Parameters: - original – the original request.
- dict_obj – a dict object with the sub-request specifications.
-
cliquet.utils.
build_response
(response, request)¶ Transform a
pyramid.response.Response
object into a serializable dict.Parameters: - response – a response object, returned by Pyramid.
- request – the request that was used to get the response.
-
cliquet.utils.
follow_subrequest
(request, subrequest, **kwargs)¶ Run a subrequest (e.g. batch), and follow the redirection if any.
Return type: tuple Returns: the reponse and the redirection request (or subrequest if no redirection happened.)
-
cliquet.utils.
encode_header
(value, encoding='utf-8')¶ Make sure the value is of type
str
in both PY2 and PY3.
-
cliquet.utils.
decode_header
(value, encoding='utf-8')¶ Make sure the header is an unicode string.
-
cliquet.utils.
strip_uri_prefix
(path)¶ Remove potential version prefix in URI.
-
class
cliquet.utils.
DeprecatedMeta
¶ A metaclass to be set on deprecated classes.
Warning will happen when class is inherited.