Utils¶
- kinto.core.utils.strip_whitespace(v: Any) Any¶
Remove whitespace, newlines, and tabs from the beginning/end of a string.
- kinto.core.utils.merge_dicts(a: dict, b: dict) None¶
Merge b into a recursively, without overwriting values.
- Parameters:
a (dict) – the dict that will be altered with values of b.
- kinto.core.utils.recursive_update_dict(root: dict, changes: Any, ignores: tuple = ()) None¶
Update recursively all the entries from a dict and it’s children dicts.
- kinto.core.utils.random_bytes_hex(bytes_length: int) str¶
Return a hexstring of bytes_length cryptographic-friendly random bytes.
- kinto.core.utils.native_value(value: Any) Any¶
Convert string value to native python values.
- Parameters:
value (str) – value to interpret.
- Returns:
the value coerced to python type
- kinto.core.utils.read_env(key: str, value: Any) Any¶
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, or the (uncoerced) default value
- kinto.core.utils.encode64(content: str, encoding: str = 'utf-8') str¶
Encode some content in base64.
- Return type:
- kinto.core.utils.decode64(encoded_content: str, encoding: str = 'utf-8') str¶
Decode some base64 encoded content.
- Return type:
- kinto.core.utils.hmac_digest(secret: str | bytes, message: str, encoding: str = 'utf-8') str¶
Return hex digest of a message HMAC using secret
- kinto.core.utils.find_nested_value(d: dict, path: str, default: Any = None) Any¶
Finds a nested value in a dict from a dotted path key string.
- class kinto.core.utils.COMPARISON(*values)¶
- kinto.core.utils.reapply_cors(request, response) Any¶
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.
- kinto.core.utils.log_context(request, **kwargs) dict¶
Bind information to the current request summary log.
- kinto.core.utils.current_service(request) Any¶
Return the Cornice service matching the specified request.
- Returns:
the service or None if unmatched.
- Return type:
kinto.core.cornice.Service
- kinto.core.utils.current_resource_name(request) str¶
Return the name used when the kinto.core resource was registered along its viewset.
- Returns:
the resource identifier.
- Return type:
- kinto.core.utils.prefixed_userid(request) str | None¶
In Kinto users ids are prefixed with the policy name that is contained in Pyramid Multiauth. If a custom authn policy is used, without authn_type, this method returns the user id without prefix.
- kinto.core.utils.prefixed_principals(request) list¶
- Returns:
the list principals with prefixed user id.
- kinto.core.utils.deprecated_effective_principals(request) list¶
Deprecated alias for
prefixed_principals().Deprecated since version Use:
request.prefixed_principalsinstead.- Returns:
the list of principals with prefixed user id.
- kinto.core.utils.build_request(original, dict_obj: dict) Any¶
Transform a dict object into a
pyramid.request.Requestobject.It sets a
parentattribute on the resulting request assigned with the original request specified.- Parameters:
original – the original request.
dict_obj – a dict object with the sub-request specifications.
- kinto.core.utils.build_response(response, request) dict¶
Transform a
pyramid.response.Responseobject into a serializable dict.- Parameters:
response – a response object, returned by Pyramid.
request – the request that was used to get the response.
- kinto.core.utils.follow_subrequest(request, subrequest, **kwargs) tuple¶
Run a subrequest (e.g. batch), and follow the redirection if any.
- Return type:
- Returns:
the response and the redirection request (or subrequest if no redirection happened.)
- kinto.core.utils.view_lookup(request, uri: str) tuple¶
A convenience method for view_lookup_registry when you have a request.
- Parameters:
request – the current request (used to obtain registry).
uri – a plural or object endpoint URI.
- Return type:
- Returns:
the resource name and the associated matchdict.
- kinto.core.utils.view_lookup_registry(registry, uri: str) tuple¶
Look-up the specified uri and return the associated resource name along the match dict.
- Parameters:
registry – the application’s registry.
uri – a plural or object endpoint URI.
- Return type:
- Returns:
the resource name and the associated matchdict.
- kinto.core.utils.instance_uri(request, resource_name, **params) str¶
Return the URI for the given resource.