Utils

hepdata.utils.file_extractor

hepdata.utils.miscellaneous

hepdata.utils.session

hepdata.utils.twitter

Twitter API.

hepdata.utils.url

hepdata.utils.users

HEPData user queries.

hepdata.utils.file_extractor

hepdata.utils.file_extractor.is_gz_file(filepath)[source]
hepdata.utils.file_extractor.extract(file_path, unzipped_path)[source]
hepdata.utils.file_extractor.get_file_in_directory(path, extension)[source]

hepdata.utils.miscellaneous

hepdata.utils.miscellaneous.splitter(data, predicate)[source]

Split a list according to a given predicate (lambda).

hepdata.utils.miscellaneous.sanitize_html(value, tags=None, attributes=None, strip=False)[source]

Sanitize HTML.

Parameters:
  • tags – Allowed HTML tags. Configuration set by Invenio-Config.

  • attributes – Allowed HTML attributes. Configuration set by Invenio-Config.

  • strip – Whether to strip tags that are not allowed. Defaults to False (escapes rather than strips disallowed tags).

Use this function when you need to include unescaped HTML that contains user provided data.

hepdata.utils.session

hepdata.utils.session.set_session_item(key, value)[source]

Stores a key and value in the session. By default we use REDIS.

Parameters:
  • key – e.g. my_key

  • value – anything, dict, array, string, int, etc.

Returns:

‘ok’

hepdata.utils.session.get_session_item(key)[source]

hepdata.utils.twitter

Twitter API.

hepdata.utils.twitter.tweet(title, collaborations, url, version=1)[source]

Announce addition or revision of a HEPData record on Twitter.

Parameters:
  • title

  • collaborations

  • url

  • version

Returns:

hepdata.utils.twitter.cleanup_latex(latex_string)[source]

Replace some spurious LaTeX encoding characters and expressions.

hepdata.utils.twitter.get_collaboration_string(collaborations)[source]

hepdata.utils.url

hepdata.utils.url.modify_query(path, **new_values)[source]

Fetch the query arguments, update them and generate a new URL.

Parameters:
  • path – [string] endpoint function name. Should contain the blueprint name or just a dot at the beginning for the same blueprint

  • **new_values – [string] dictionary containing parameters to update. When a parameter value is None, it is removed from the URL.

Returns:

[string] generated URL

hepdata.utils.users

HEPData user queries.

hepdata.utils.users.get_user_from_id(user_id)[source]

Returns a user object from their id.

Parameters:

user_id – <int>

Returns:

User object if found, else None

hepdata.utils.users.user_is_admin(user)[source]

Checks if user is an admin or coordinator.

Parameters:

user – <User> object

hepdata.utils.users.user_is_admin_or_coordinator(user)[source]

Checks if user is an admin or coordinator.

Parameters:

user – <User> object