tlcurl.url_adapter¶
Provides a unified interface for URL-based file operations across different schemes and storage backends.
Module Contents¶
Classes¶
Class |
Description |
|---|---|
An Enum indicating what to do if content already exists at the target URL |
|
The base class for all URL adapters |
|
A UrlAdapter where the Async methods are implemented as Futures that call the equivalent Sync methods on the thread pool |
|
The base class for all directory entries. |
|
A UrlAdapter where the Sync methods are implemented by calling the equivalent Async methods and then waiting on the Futures returned. |
Data¶
Data |
Description |
|---|---|
API¶
- class IfExistsOption¶
-
An Enum indicating what to do if content already exists at the target URL
from tlc.core.url_adapter import IfExistsOption, UrlAdapter from tlc.core.url import Url url = Url("s3://my-bucket/my-file.txt") adapter = UrlAdapter.get_adapter(url) adapter.write_string_content_to_url(url, "Hello World!", IfExistsOption.OVERWRITE)
Initialize self. See help(type(self)) for accurate signature.
- OVERWRITE = overwrite¶
If content already exists at the target URL, overwrite the content (default).
- RAISE = raise¶
If content already exists at the target URL, raise an exception.
- RENAME = rename¶
If content already exists at the target URL, leave that content, and write the new content to a new URL that is similar to the original target URL.
- REUSE = reuse¶
If content already exists at the target URL, reuse the existing content.
- class UrlAdapter¶
Bases:
abc.ABCThe base class for all URL adapters
- copy_url(
- source: Url,
- destination: Url,
- options: IfExistsOption = IfExistsOption.OVERWRITE,
Copy URL synchronously
- abstract copy_url_async(
- source: Url,
- destination: Url,
- options: IfExistsOption = IfExistsOption.OVERWRITE,
Copy URL asynchronously
- abstract exists(
- url: Url,
Return True if the given URL refers to an existing path synchronously
- abstract exists_async(
- url: Url,
Return True if the given URL refers to an existing path asynchronously
- abstract get_file_size_async(
- url: Url,
Get the size of the file at the given URL asynchronously
- abstract is_dir_async(
- url: Url,
Return True if the given URL refers to a directory asynchronously
- is_file_hierarchy_flat() bool¶
Determine if the file hierarchy is flat for this adapter
Cloud storage normally has a flat hierarchy, meaning that
make_dirsis a no-op.
- abstract is_writable_async(
- url: Url,
Return True if the given URL is writable asynchronously
- abstract list_dir(
- url: Url,
List the entries belonging to the directory at the given URL synchronously
- abstract list_dir_async(
- url: Url,
List the entries belonging to the directory at the given URL asynchronously
- abstract make_dirs( ) None¶
Create a leaf directory and all intermediate ones synchronously
For flat file hierarchies, this may be a no-op, see
is_file_hierarchy_flat.
- abstract make_dirs_async( ) Future¶
Create a leaf directory and all intermediate ones asynchronously
For flat file hierarchies, this may be a no-op, see
is_file_hierarchy_flat.
- abstract read_binary_content_from_url(
- url: Url,
Read binary content from URL synchronously, dispatch
- abstract read_binary_content_from_url_async(
- url: Url,
Read binary content from URL asynchronously
- abstract stat(
- url: Url,
- Get metadata about a file or directory at the given URL synchronously
param url: The URL to get metadata for
return: A UrlAdapterDirEntry containing metadata about the file or directory
raises FileNotFoundError: If the URL does not exist
- abstract stat_async(
- url: Url,
- Get metadata about a file or directory at the given URL asynchronously
param url: The URL to get metadata for
return: A Future that resolves to a UrlAdapterDirEntry containing metadata
raises FileNotFoundError: If the URL does not exist
- abstract touch(
- url: Url,
Update the last modified timestamp of a file to the current time. Creates the file if it doesn’t exist.
- Parameters:
url – The URL of the file to touch
- write_binary_content_to_url(
- url: Url,
- content: bytes,
- options: IfExistsOption = IfExistsOption.OVERWRITE,
Write binary content to URL synchronously
Handles write options and dispatches to
_write_binary_content_to_url
- abstract write_binary_content_to_url_async(
- url: Url,
- content: bytes,
- options: IfExistsOption = IfExistsOption.OVERWRITE,
Write binary content to URL asynchronously
- class UrlAdapterAsyncFromSync¶
Bases:
tlcurl.url_adapter.UrlAdapterA UrlAdapter where the Async methods are implemented as Futures that call the equivalent Sync methods on the thread pool
Derived classes must implement the Sync methods.
- copy_url_async(
- source: Url,
- destination: Url,
- options: IfExistsOption = IfExistsOption.OVERWRITE,
- write_binary_content_to_url_async(
- url: Url,
- content: bytes,
- options: IfExistsOption = IfExistsOption.OVERWRITE,
- class UrlAdapterDirEntry¶
The base class for all directory entries.
- abstract mtime() Any¶
Return the modification time object for this entry
The mtime object is not specified to be of any particular type, but must be comparable to other mtime objects of the same type
May raise exceptions when accessing the resources
- class UrlAdapterSyncFromAsync¶
Bases:
tlcurl.url_adapter.UrlAdapterA UrlAdapter where the Sync methods are implemented by calling the equivalent Async methods and then waiting on the Futures returned.
Derived classes must implement the Async methods.
- list_dir(
- url: Url,
- stat(
- url: Url,
- write_binary_content_to_url(
- url: Url,
- content: bytes,
- options: IfExistsOption = IfExistsOption.OVERWRITE,
- logger = getLogger(...)¶