tensorbay.utility.file

mixin classes for local file and remote file.

class tensorbay.utility.file.FileMixin(local_path)[source]

Bases: tensorbay.utility.repr.ReprMixin

FileMixin is a mixin class to mixin file related methods for local file.

Parameters

local_path (str) – The file local path.

Return type

None

path

The file local path.

get_checksum()[source]

Get and cache the sha1 checksum of the local data.

Returns

The sha1 checksum of the local data.

Return type

str

get_url()[source]

Return the url of the local data file.

Returns

The url of the local data.

Return type

str

open()[source]

Return the binary file pointer of this file.

The local file pointer will be obtained by build-in open().

Returns

The local file pointer for this data.

Return type

_io.BufferedReader

class tensorbay.utility.file.RemoteFileMixin(remote_path, *, _url_getter=None, _url_updater=None, cache_path='')[source]

Bases: tensorbay.utility.repr.ReprMixin

RemoteFileMixin is a mixin class to mixin file related methods for remote file.

Parameters
  • local_path – The file local path.

  • _url_getter (Optional[Callable[[str], str]]) – The url getter of the remote file.

  • cache_path (str) – The path to store the cache.

  • remote_path (str) –

  • _url_updater (Optional[Callable[[], None]]) –

Return type

None

path

The file local path.

update_url()[source]

Update the url when the url is timed out.

Raises

ValueError – When the _url_updater is missing.

Return type

None

get_url()[source]

Return the url of the data hosted by tensorbay.

Returns

The url of the data.

Raises

ValueError – When the _url_getter is missing.

Return type

str

open()[source]

Return the binary file pointer of this file.

The remote file pointer will be obtained by urllib.request.urlopen().

Returns

The remote file pointer for this data.

Return type

Union[http.client.HTTPResponse, _io.BufferedReader]