PR Title Check / check-title (pull_request) Successful in 8s
Test Python Package / unit-tests (pull_request) Successful in 12s
Code Quality Pipeline / code-quality (pull_request) Successful in 20s
Test Python Package / integration-tests (pull_request) Successful in 24s
Test Python Package / coverage-report (pull_request) Successful in 11s
Relax write validation so {} and zero-byte BytesIO round-trip correctly,
document None-vs-empty semantics on interfaces and adapters, and add
integration tests for placeholders and existence distinction.
Co-authored-by: Cursor <cursoragent@cursor.com>
45 lines
1.3 KiB
Python
45 lines
1.3 KiB
Python
"""Definition of ObjectRepositoryInterface abstract base class."""
|
|
|
|
from abc import ABC, abstractmethod
|
|
from io import BytesIO
|
|
|
|
|
|
class ObjectRepositoryInterface(ABC):
|
|
"""Interface that defines binary object CRUD methods."""
|
|
|
|
@abstractmethod
|
|
def get(self, object_name: str) -> BytesIO | None:
|
|
"""Get an object by name.
|
|
|
|
Returns ``None`` when the object does not exist. Returns an empty
|
|
``BytesIO`` for a zero-byte object. Use ``value is not None`` to test
|
|
existence. Raises ConnectionError when not connected. Other backend
|
|
errors propagate to the caller.
|
|
"""
|
|
...
|
|
|
|
@abstractmethod
|
|
def put(
|
|
self,
|
|
object_name: str,
|
|
data: BytesIO,
|
|
content_type: str = "application/octet-stream",
|
|
) -> None:
|
|
"""Put an object by name.
|
|
|
|
Accepts zero-byte ``BytesIO``. A zero-byte object is returned by
|
|
``get()`` as an empty buffer, not ``None``. Use ``delete()`` to remove
|
|
an object entirely.
|
|
"""
|
|
...
|
|
|
|
@abstractmethod
|
|
def delete(self, object_name: str) -> None:
|
|
"""Delete an object by name, removing it entirely."""
|
|
...
|
|
|
|
@abstractmethod
|
|
def list_objects(self, prefix: str = "") -> list[str]:
|
|
"""List object names with an optional prefix."""
|
|
...
|