Skip to content

Class swarmauri_base.git_filters.GitFilterBase.GitFilterBase

swarmauri_base.git_filters.GitFilterBase.GitFilterBase

Bases: IGitFilter

Base class providing clean and smudge helpers.

upload abstractmethod

upload(key, data)

Store data under key and return a URI or identifier.

Source code in swarmauri_base/git_filters/GitFilterBase.py
14
15
16
@abstractmethod
def upload(self, key: str, data: BinaryIO) -> str:  # pragma: no cover - interface
    """Store *data* under *key* and return a URI or identifier."""

download abstractmethod

download(key)

Return a binary file-like object for key.

Source code in swarmauri_base/git_filters/GitFilterBase.py
18
19
20
@abstractmethod
def download(self, key: str) -> BinaryIO:  # pragma: no cover - interface
    """Return a binary file-like object for *key*."""

from_uri abstractmethod classmethod

from_uri(uri)

Create a filter instance from uri.

Source code in swarmauri_base/git_filters/GitFilterBase.py
22
23
24
25
@classmethod
@abstractmethod
def from_uri(cls, uri: str) -> "GitFilterBase":  # pragma: no cover - interface
    """Create a filter instance from *uri*."""

clean

clean(data)
Source code in swarmauri_base/git_filters/GitFilterBase.py
27
28
29
30
31
32
33
34
35
def clean(self, data: bytes) -> str:
    oid = "sha256:" + hashlib.sha256(data).hexdigest()
    try:
        self.download(oid)
    except (FileNotFoundError, KeyError):
        # Some storage backends may raise ``KeyError`` instead of ``FileNotFoundError``
        # when an object is missing. Treat both cases as a cache miss and upload.
        self.upload(oid, io.BytesIO(data))
    return oid

smudge

smudge(oid)
Source code in swarmauri_base/git_filters/GitFilterBase.py
37
38
39
def smudge(self, oid: str) -> bytes:
    with self.download(oid) as fh:
        return fh.read()