schema_util

Utilities for writing content to files and for other file manipulation.

Functions

format_error(row_number, row[, ...])

get_api_key()

Tries to get the GitHub access token from the environment. Defaults to above value if not found.

make_url_request(resource_url[, ...])

Make a request and adds the above GitHub access credentials.

schema_version_greater_equal(hed_schema, ...)

Check if the given schema standard version is above target version

url_to_file(resource_url)

Write data from a URL resource into a file.

url_to_string(resource_url)

Get the data from the specified url as a string.

xml_element_2_str(elem)

Convert an XML element to an XML string.

format_error(row_number, row, warning_message='Schema term is empty or the line is malformed', error_code='GENERIC_ERROR')[source]
get_api_key()[source]

Tries to get the GitHub access token from the environment. Defaults to above value if not found.

Returns:

A GitHub access key or an empty string.

make_url_request(resource_url, try_authenticate=True)[source]

Make a request and adds the above GitHub access credentials.

Parameters:
  • resource_url (str) – The url to retrieve.

  • try_authenticate (bool) – If True add the above credentials.

Returns:

url_request

schema_version_greater_equal(hed_schema, target_version)[source]

Check if the given schema standard version is above target version

Parameters:
  • hed_schema (HedSchema or HedSchemaGroup) – If a schema group, checks if any version is above.

  • target_version (str) – The semantic version to check against

Returns:

True if the version is above target_version

False if it is not, or it is ambiguous.

Return type:

bool

url_to_file(resource_url)[source]

Write data from a URL resource into a file. Data is decoded as unicode.

Parameters:

resource_url (str) – The URL to the resource.

Returns:

The local temporary filename for the downloaded file,

Return type:

str

url_to_string(resource_url)[source]

Get the data from the specified url as a string.

Parameters:

resource_url (str) – The URL to the resource.

Returns:

The data at the target url.

Return type:

str

xml_element_2_str(elem)[source]

Convert an XML element to an XML string.

Parameters:

elem (Element) – An XML element.

Returns:

An XML string representing the XML element.

Return type:

str