tensorbay.utility.file#

Basic concepts of local file and remote file.

class tensorbay.utility.file.URL(url, updater)[source]#

Bases: object

URL is a class used to get and update the url.

Parameters
  • url (str) – The url.

  • updater (Callable[[], Optional[str]]) – A function used to update the url.

Return type

None

classmethod from_getter(getter, updater)[source]#

Create a URL instance from the given getter and updater.

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

  • updater (Callable[[], Optional[str]]) – The updater of the url.

Returns

The URL instance which stores the url and the updater.

Return type

tensorbay.utility.file.URL

update()[source]#

Update the url.

Return type

None

get()[source]#

Get the url of the file.

Returns

The url.

Return type

str

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=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 (Optional[tensorbay.utility.file.URL]) – The URL instance used to get and update url.

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

  • remote_path (str) –

Return type

None

path#

The file local path.

get_url()[source]#

Return the url of the data hosted by tensorbay.

Returns

The url of the data.

Raises

ValueError – When the url 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[tensorbay.utility.requests.UserResponse, _io.BufferedReader]

get_callback_body()[source]#

Not support get_callback_body function.

Raises

AttributeError – when calling the get_callback_body().

Return type

Dict[str, Any]