Using cove as a library (cove.lib)

Currently the main user of cove.lib is cove.views which is responsible for rendering the Cove web application.

common

class cove.lib.common.CustomJsonrefLoader(**kwargs)[source]

This ref loader is only for use with the jsonref library and NOT jsonschema.

get_remote_json(uri, **kwargs)[source]
class cove.lib.common.CustomRefResolver(*args, **kw)[source]

This RefResolver is only for use with the jsonschema library

resolve_remote(uri)[source]
class cove.lib.common.SchemaJsonMixin[source]
deref_schema(schema_str)[source]
get_release_pkg_schema_fields()[source]
get_release_pkg_schema_obj(deref=False)[source]
get_release_schema_obj(deref=False)[source]
release_pkg_schema_str
release_schema_str
cove.lib.common.add_is_codelist(obj)[source]

This is needed so that we can detect enums that are arrays as the jsonschema library does not give you any parent information and the codelist property is on the parent in this case. Only applies to release.tag in core schema at the moment.

cove.lib.common.common_checks_context(upload_dir, json_data, schema_obj, schema_name, context, extra_checkers=None, fields_regex=False, api=False, cache=True)[source]
cove.lib.common.fields_present_generator(json_data, prefix='')[source]
cove.lib.common.get_additional_codelist_values(schema_obj, codelist_url, json_data)[source]
cove.lib.common.get_counts_additional_fields(json_data, schema_obj, schema_name, context, fields_regex=False)[source]
cove.lib.common.get_fields_present(*args, **kwargs)[source]
cove.lib.common.get_json_data_deprecated_fields(json_data_paths, schema_obj)[source]
cove.lib.common.get_json_data_generic_paths(json_data, path=(), generic_paths=None)[source]

Transform json data into a dictionary with keys made of json paths.

Key are json paths (as tuples). Values are dictionaries with keys including specific indexes (which are not including in the top level keys), eg:

{‘a’: ‘I am’, ‘b’: [‘a’, ‘list’], ‘c’: [{‘ca’: ‘ca1’}, {‘ca’: ‘ca2’}, {‘cb’: ‘cb’}]}

will return:

generic_paths = {

(‘a’,): {(‘a’,): ‘I am’}, (‘b’,): {

(‘b’,): [‘a’, ‘list’], (‘b’, 0): ‘a’, (‘b’, 1): ‘list’

}, (‘c’,): {

(‘c’,): [
{‘ca’: ‘ca1’}, {‘ca’: ‘ca2’}, {‘cb’: ‘cb’}

], (‘c’, 0): {‘ca’: ‘ca1’}, (‘c’, 1): {‘ca’: ‘ca2’}, (‘c’, 2): {‘cb’: ‘cb’}

}, (‘c’, ‘ca’): {

(‘c’, 0, ‘ca’): ‘ca1’, (‘c’, 1, ‘ca’): ‘ca2’

}, (‘c’, ‘cb’): {(‘c’, 2, ‘cb’): ‘cb’}

}

cove.lib.common.get_json_data_missing_ids(json_data_paths, schema_obj)[source]
cove.lib.common.get_orgids_prefixes(orgids_url=None)[source]

Get org-ids.json file from file system (or fetch upstream if it doesn’t exist)

A lock file is needed to avoid different processes trying to access the file trampling each other. If a process has the exclusive lock, a different process will wait until it is released.

cove.lib.common.get_schema_validation_errors(json_data, schema_obj, schema_name, cell_src_map, heading_src_map, extra_checkers=None)[source]
cove.lib.common.get_spreadsheet_meta_data(upload_dir, file_name, schema, file_type='xlsx', name='Meta')[source]
cove.lib.common.oneOf_draft4(validator, oneOf, instance, schema)[source]

oneOf_draft4 validator from https://github.com/Julian/jsonschema/blob/d16713a4296663f3d62c50b9f9a2893cb380b7af/jsonschema/_validators.py#L337 patched to sort the instance.

cove.lib.common.required_draft4(validator, required, instance, schema)[source]
cove.lib.common.schema_dict_fields_generator(schema_dict)[source]
cove.lib.common.unique_ids(validator, ui, instance, schema)[source]

converters

exceptions

exception cove.lib.exceptions.CoveInputDataError(context=None)[source]

An error that we think is due to the data input by the user, rather than a bug in the application.

exception cove.lib.exceptions.UnrecognisedFileType(context=None)[source]
context
exception cove.lib.exceptions.UnrecognisedFileTypeXML(context=None)[source]
context
cove.lib.exceptions.cove_spreadsheet_conversion_error(func)[source]
cove.lib.exceptions.cove_web_input_error(func)[source]

ocds

threesixtygiving

tools

class cove.lib.tools.NumberStr(o)[source]
cove.lib.tools.cached_get_request[source]
cove.lib.tools.datetime_or_date(instance)[source]
cove.lib.tools.decimal_default(o)[source]
cove.lib.tools.get_file_type(file)[source]
cove.lib.tools.get_no_exception(item, key, fallback)[source]
cove.lib.tools.ignore_errors(f)[source]
cove.lib.tools.to_list(item)[source]
cove.lib.tools.update_docs(document_parent, counter)[source]