birdy.utils module

birdy.utils._encode(content, mimetype, encoding)[source]

Encode in base64 if mimetype is a binary type.

birdy.utils.delist(data)[source]

If data is a sequence with a single element, returns this element, otherwise return the sequence.

birdy.utils.embed(value, mimetype=None, encoding=None)[source]

Return the content of the file, either as a string or base64 bytes.

Returns:

encoded content string and actual encoding

Return type:

str

birdy.utils.fix_url(url)[source]

If url is a local path, add a file:// scheme.

birdy.utils.guess_type(url, supported)[source]

Guess the mime type of the file link.

If the mimetype is not recognized, default to the first supported value.

Parameters:
  • url (str, Path) – Path or URL to file.

  • supported (list, tuple) – Supported mimetypes.

Return type:

mimetype, encoding

birdy.utils.is_file(path)[source]

Return True if path is a valid file.

birdy.utils.is_opendap_url(url)[source]

Check if a provided url is an OpenDAP url.

The DAP Standard specifies that a specific tag must be included in the Content-Description header of every request. This tag is one of: “dods-dds” | “dods-das” | “dods-data” | “dods-error”

So we can check if the header starts with dods.

Note that this might not work with every DAP server implementation.

birdy.utils.is_url(url)[source]

Return whether value is a valid URL.

birdy.utils.sanitize(name)[source]

Lower-case name and replace all non-ascii chars by _.

If name is a Python keyword (like return) then add a trailing _.