Common / Utilities

Common operations.

Because cloud operations are OS agnostic, we don’t use any of os or os.path.

cloud_browser.common.PARENT = '..'

Parent path phrase.

cloud_browser.common.SEP = '/'

Browser file path separator.

cloud_browser.common.basename(path)

Rightmost part of path after separator.

cloud_browser.common.check_version(mod, required)

Require minimum version of module using __version__ member.

cloud_browser.common.dt_from_header(date_str)

Try various RFC conversions to datetime or return None.

Parameters

date_str (string) – Date string.

Returns

Date time.

Return type

datetime.datetime or None

cloud_browser.common.dt_from_rfc1123(date_str)

Convert 1123 (HTTP header) date string to datetime object.

Parameters

date_str (string) – Date string.

Returns

Date time.

Return type

datetime.datetime

cloud_browser.common.dt_from_rfc8601(date_str)

Convert 8601 (ISO) date string to datetime object.

Handles “Z” and milliseconds transparently.

Parameters

date_str (string) – Date string.

Returns

Date time.

Return type

datetime.datetime

cloud_browser.common.get_int(value, default, test_fn=None)

Convert value to integer.

Parameters
  • value – Integer value.

  • default – Default value on failed conversion.

  • test_fn – Constraint function. Use default if returns False.

Returns

Integer value.

Return type

int

cloud_browser.common.path_join(*args)

Join path parts to single path.

cloud_browser.common.path_list(path)

Return list of path parts.

cloud_browser.common.path_parts(path)

Split path into container, object.

Parameters

path (string) – Path to resource (including container).

Returns

Container, storage object tuple.

Return type

tuple of string, string

cloud_browser.common.path_yield(path)

Yield on all path parts.

cloud_browser.common.relpath(path, start)

Get relative path to start.

Note: Modeled after python2.6 os.path.relpath().

cloud_browser.common.requires(module, name='')

Enforces module presence.

The general use here is to allow conditional imports that may fail (e.g., a required python package is not installed) but still allow the rest of the python package to compile and run fine. If the wrapped method with this decorated is invoked, then a runtime error is generated.

Parameters
  • module (module or None) – required module (set as variable to None on import fail)

  • name (string) – module name