datalad_dataverse.utils

Miscellaneous utilities

datalad_dataverse.utils.format_doi(doi_in: str) str[source]

Converts unformatted DOI strings to the format expected by the dataverse API

Compatible with DOIs starting with "doi:", as URL or raw (e.g., 10.5072/FK2/WQCBX1).

Cannot be None or empty!

Parameters:

doi_in (str) -- Unformatted doi string provided by user which is checked for None of empty values

Returns:

DOI string as needed for dataverse API, None if string is empty.

Return type:

str

Raises:

ValueError -- If doi_in is None or empty

datalad_dataverse.utils.get_native_api(baseurl, token)[source]
Returns:

The pyDataverse API wrapper

Return type:

NativeApi

datalad_dataverse.utils.mangle_path(path: str | PurePosixPath) PurePosixPath[source]

Quote unsupported chars in all elements of a path

Dataverse currently auto-removes a leading dot from directory names. It also only allows the characters _, -, ., /, and \ in directory names. File names may not contain the following characters: /, :, *, ?, ", <, >, |, ;, and #. We therefore encode leading dots and all non-allowed characters in all elements of the path. We also replace leading dots in file names in order to simplify un-mangling. This allows us to handle un-mangling equally for directories and files.

Parameters:

path (str | PurePosixPath) -- the path that should be mangled, as a relative path in POSIX notation

Returns:

path object with the mangled name

Return type:

PurePosixPath

datalad_dataverse.utils.unmangle_path(dataverse_path: str | PurePosixPath) PurePosixPath[source]

Revert dataverse specific path name mangling

This method undoes the quoting performed by mangle_path().

Parameters:

dataverse_path (str | PurePosixPath) -- the path that should be un-mangled

Returns:

a path object with the un-mangled name

Return type:

PurePosixPath