Remove whitespace, newlines, and tabs from the beginning/end of a string.

Parameters:v (str) – the string to strip.
Return type:str

Return current epoch time in milliseconds.

Return type:int

Get a classname from an object.

Return type:str
kinto.core.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.
kinto.core.utils.recursive_update_dict(root, changes, ignores=())

Update recursively all the entries from a dict and it’s children dicts.

  • root (dict) – root dictionary
  • changes (dict) – dictonary where changes should be made (default=root)
Returns dict newd:

dictionary with removed entries of val.


Return a hexstring of bytes_length cryptographic-friendly random bytes.

Parameters:bytes_length (int) – number of random bytes.
Return type:str

Convert string value to native python values.

Parameters:value (str) – value to interprete.
Returns:the value coerced to python type
kinto.core.utils.read_env(key, value)

Read the setting key from environment variables.

  • key – the setting name
  • value – default value if undefined in environment

the value from environment, coerced to python type, or the (uncoerced) default value

kinto.core.utils.encode64(content, encoding='utf-8')

Encode some content in base64.

Return type:str
kinto.core.utils.decode64(encoded_content, encoding='utf-8')

Decode some base64 encoded content.

Return type:str
kinto.core.utils.hmac_digest(secret, message, encoding='utf-8')

Return hex digest of a message HMAC using secret

kinto.core.utils.dict_subset(d, keys)

Return a dict with the specified keys

kinto.core.utils.dict_merge(a, b)

Merge the two specified dicts

kinto.core.utils.find_nested_value(d, path, default=None)

Finds a nested value in a dict from a dotted path key string.

  • d (dict) – the dict to retrieve nested value from
  • path (str) – the path to the nested value, in dot notation

the nested value if any was found, or None

class kinto.core.utils.COMPARISON

An enumeration.

kinto.core.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.

kinto.core.utils.log_context(request, **kwargs)

Bind information to the current request summary log.


Return the Cornice service matching the specified request.

Returns:the service or None if unmatched.
Return type:cornice.Service

Return the name used when the kinto.core resource was registered along its viewset.

Returns:the resource identifier.
Return type:str

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.

Returns:the list principals with prefixed user id.
kinto.core.utils.build_request(original, dict_obj)

Transform a dict object into a pyramid.request.Request object.

It sets a parent attribute on the resulting request assigned with the original request specified.

  • original – the original request.
  • dict_obj – a dict object with the sub-request specifications.
kinto.core.utils.build_response(response, request)

Transform a pyramid.response.Response object into a serializable dict.

  • 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)

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.)

Remove potential version prefix in URI.

kinto.core.utils.view_lookup(request, uri)

A convenience method for view_lookup_registry when you have a request.

  • request – the current request (used to obtain registry).
  • uri – a plural or object endpoint URI.
Return type:



the resource name and the associated matchdict.

kinto.core.utils.view_lookup_registry(registry, uri)

Look-up the specified uri and return the associated resource name along the match dict.

  • registry – the application’s registry.
  • uri – a plural or object endpoint URI.
Return type:



the resource name and the associated matchdict.

kinto.core.utils.instance_uri(request, resource_name, **params)

Return the URI for the given resource.

kinto.core.utils.instance_uri_registry(registry, resource_name, **params)

Return the URI for the given resource, even if you don’t have a request.

This gins up a request using Request.blank and so does not support any routes with pregenerators.


Extract the bucket_id and collection_id of the given resource (URI)

Parameters:resource (str) – a uri formatted /buckets/<bid>/collections/<cid> or <bid>/<cid>.
Returns:a dictionary with the bucket_id and collection_id of the resource
kinto.core.utils.apply_json_patch(record, ops)

Apply JSON Patch operations using jsonpatch.

  • record – base record where changes should be applied (not in-place).
  • changes (list) – list of JSON patch operations.
  • only_data (bool) – param to limit the scope of the patch only to ‘data’.
Returns dict data:

patched record data. dict permissions: patched record permissions