gigl.common#
Common utilities, services, and tools used throughout GiGL.
Submodules#
Classes#
Represents a Google Cloud Storage (GCS) URI. |
|
Represents an HTTP URI. |
|
Represents a local URI (Uniform Resource Identifier) that extends the Uri class and implements the os.PathLike interface. |
|
A URI; currently supports GCS ('gs://foo/bar'), HTTP ('http://abc.com/xyz') or local ('/foo/bar'). |
|
Factory class to create the proper concrete Uri instance given an input. |
Package Contents#
- class gigl.common.GcsUri(uri)[source]#
Bases:
gigl.common.types.uri.uri.Uri
Represents a Google Cloud Storage (GCS) URI.
- Parameters:
uri (Union[str, Path, GcsUri]) – The URI string or path to initialize the GcsUri object.
- classmethod is_valid(uri, raise_exception=False)[source]#
Check if the given URI is valid.
- Parameters:
uri (Union[str, Path, Uri]) – The URI to be validated.
raise_exception (Optiona[bool]) – Whether to raise an exception if the URI is invalid. Defaults to False.
- Returns:
True if the URI is valid, False otherwise.
- Return type:
bool
- classmethod join(token, *tokens)[source]#
Joins multiple URI tokens together and returns a new GcsUri object.
- property bucket: str#
- Return type:
str
- property path: str#
- Return type:
str
- class gigl.common.HttpUri(uri)[source]#
Bases:
gigl.common.types.uri.uri.Uri
Represents an HTTP URI.
- Parameters:
uri (Union[str, pathlib.Path, HttpUri])
- classmethod is_valid(uri, raise_exception=False)[source]#
Check if the URI is valid.
- Parameters:
uri (Union[str, pathlib.Path, gigl.common.types.uri.uri.Uri]) – The URI to check.
raise_exception (bool) – Whether to raise an exception if the URI is invalid.
- Returns:
True if the URI is valid, False otherwise.
- Return type:
bool
- classmethod join(token, *tokens)[source]#
Join multiple URI tokens into a single URI.
- Parameters:
token (Union[str, pathlib.Path, gigl.common.types.uri.uri.Uri]) – The first URI token.
*tokens (Union[str, pathlib.Path, gigl.common.types.uri.uri.Uri]) – Additional URI tokens to join.
- Returns:
The joined URI.
- Return type:
- class gigl.common.LocalUri(uri)[source]#
Bases:
gigl.common.types.uri.uri.Uri
,os.PathLike
Represents a local URI (Uniform Resource Identifier) that extends the Uri class and implements the os.PathLike interface.
- Parameters:
uri (Union[str, pathlib.Path, Uri])
- absolute()[source]#
Returns an absolute LocalUri object.
- Returns:
An absolute LocalUri object.
- Return type:
- classmethod is_valid(uri, raise_exception=False)[source]#
Checks if the given URI is valid.
- Parameters:
uri (Union[str, Path, Uri]) – The URI to check.
raise_exception (Optional[bool]) – Whether to raise an exception if the URI is invalid. Defaults to False.
- Returns:
True if the URI is valid, False otherwise.
- Return type:
bool
- class gigl.common.Uri(uri)[source]#
Bases:
object
A URI; currently supports GCS (‘gs://foo/bar’), HTTP (‘http://abc.com/xyz’) or local (‘/foo/bar’).
- Parameters:
uri (Union[str, pathlib.Path, Uri])
- get_basename()[source]#
The base name is the final component of the path, effectively extracting the file or directory name from a full path string. i.e. get_basename(“/foo/bar.txt”) -> bar.txt get_basename(“gs://bucket/foo”) -> foo
- Return type:
str
- classmethod is_valid(uri, raise_exception=False)[source]#
- Abstractmethod:
- Parameters:
uri (Union[str, pathlib.Path, Uri])
raise_exception (bool)
- Return type:
bool
Check if the given URI is valid.
- Parameters:
uri (Union[str, pathlib.Path, Uri]) – The URI to check.
raise_exception (bool) – Whether to raise an exception if the URI is invalid.
- Returns:
True if the URI is valid, False otherwise.
- Return type:
bool
- property uri#