Cat Feeder  1.0.0
The Cat feeder project
Loading...
Searching...
No Matches
bucket_class_aliases.py
Go to the documentation of this file.
1r"""
2# +==== BEGIN CatFeeder =================+
3# LOGO:
4# ..............(..../\
5# ...............)..(.')
6# ..............(../..)
7# ...............\‍(__)|
8# Inspired by Joan Stark
9# source https://www.asciiart.eu/
10# animals/cats
11# /STOP
12# PROJECT: CatFeeder
13# FILE: bucket_class_aliases.py
14# CREATION DATE: 19-11-2025
15# LAST Modified: 14:41:58 19-12-2025
16# DESCRIPTION:
17# This is the backend server in charge of making the actual website work.
18# Protocol aliases for the S3 bucket wrapper.
19#
20# These lightweight ``typing.Protocol`` classes describe only the subset of the boto3 S3 interface that the bucket wrapper relies on.
21# They allow static type checking without introducing optional stub packages or a hard dependency on external type distributions.
22# /STOP
23# COPYRIGHT: (c) Cat Feeder
24# PURPOSE: Class aliases used to help with typing for the bucket wrapper.
25# // AR
26# +==== END CatFeeder =================+
27"""
28
29from typing import Protocol, Any, Iterable
30
31
32class S3ObjectLike(Protocol):
33 """Minimal shape of an object stored in a bucket.
34
35 Only the attributes and methods actually accessed by the
36 wrapper are declared here.
37 """
38 @property
39 def content_length(self) -> int:
40 """Return the byte size of the object's content."""
41 raise NotImplementedError
42
43 def delete(self) -> Any:
44 """Delete the object from its parent bucket."""
45 raise NotImplementedError
46
47 @property
48 def key(self) -> str:
49 """Return the object key (its unique path within the bucket)."""
50 raise NotImplementedError
51
52 def get(self) -> Any:
53 """Retrieve the object and return a response containing the object's body and metadata."""
54 raise NotImplementedError
55
56
58 """Iterable collection façade exposing ``all()`` to enumerate objects."""
59
60 def all(self) -> Iterable[S3ObjectLike]:
61 """Return an iterable over all objects in the collection."""
62 raise NotImplementedError
63
64
65class S3BucketLike(Protocol):
66 """Minimal bucket interface used for file/object operations."""
67
68 def upload_file(self, Filename: str, Key: str) -> Any:
69 """Upload a local file specified by ``Filename`` to this bucket under ``Key``."""
70 raise NotImplementedError
71
72 def download_file(self, Key: str, Filename: str) -> Any:
73 """Download the object at ``Key`` into the local file path ``Filename``."""
74 raise NotImplementedError
75
76 def put_object(self, Key: str, Body: bytes) -> Any:
77 """Upload a byte stream to this bucket under ``Key``."""
78 raise NotImplementedError
79
80 def delete(self) -> Any:
81 """Delete the bucket itself (must be empty)."""
82 raise NotImplementedError
83
84 def Object(self, key: str) -> S3ObjectLike:
85 """Return an object handle for the given key inside this bucket."""
86 raise NotImplementedError
87
88 @property
89 def objects(self) -> S3ObjectsCollectionLike:
90 """Return a collection façade exposing enumeration of bucket objects."""
91 raise NotImplementedError
92
93
95 """Collection façade for listing bucket resources."""
96
97 def all(self) -> Iterable[Any]:
98 """Return an iterable over all available bucket resources (each with ``.name``)."""
99 raise NotImplementedError # Buckets with `.name`
100
101
102class S3ServiceResourceLike(Protocol):
103 """Top-level S3 service resource surface used by the wrapper.
104
105 Provides bucket lookup, bucket creation and metadata client
106 access for connectivity checks.
107 """
108 buckets: S3BucketsCollectionLike
109 meta: Any # has `.client.list_buckets()`
110
111 def Bucket(self, name: str) -> S3BucketLike:
112 """Return a bucket handle for the given name."""
113 raise NotImplementedError
114
115 def create_bucket(self, *, Bucket: str, **kwargs: Any) -> Any:
116 """Create a new bucket named ``Bucket`` with optional configuration ``kwargs``."""
117 raise NotImplementedError