Skip to content
This repository was archived by the owner on Mar 31, 2026. It is now read-only.

Commit 71e0904

Browse files
authored
feat(experimental): add AsyncAbstractObjectStream (#1546)
* add AsyncAbstractObjectStream this will be the parent class for AsyncReadObjectStream and AsyncWriteObjectStream * keep _AsyncAbstractObjectStream private * include handle in tests * remove unit tests for abstract class * bucket_name and object_name cannot be NONE * minor edit - add bidi-stream in doc string
1 parent 8b988ad commit 71e0904

1 file changed

Lines changed: 67 additions & 0 deletions

File tree

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# Copyright 2025 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import abc
16+
from typing import Any, Optional
17+
18+
19+
class _AsyncAbstractObjectStream(abc.ABC):
20+
"""Abstract base class to represent gRPC bidi-stream for GCS ``Object``.
21+
22+
Concrete implementation of this class could be ``_AsyncReadObjectStream``
23+
or ``_AsyncWriteObjectStream``.
24+
25+
:type bucket_name: str
26+
:param bucket_name: (Optional) The name of the bucket containing the object.
27+
28+
:type object_name: str
29+
:param object_name: (Optional) The name of the object.
30+
31+
:type generation_number: int
32+
:param generation_number: (Optional) If present, selects a specific revision of
33+
this object.
34+
35+
:type handle: bytes
36+
:param handle: (Optional) The handle for the object, could be read_handle or
37+
write_handle, based on how the stream is used.
38+
"""
39+
40+
def __init__(
41+
self,
42+
bucket_name: str,
43+
object_name: str,
44+
generation_number: Optional[int] = None,
45+
handle: Optional[bytes] = None,
46+
) -> None:
47+
super().__init__()
48+
self.bucket_name: str = bucket_name
49+
self.object_name: str = object_name
50+
self.generation_number: Optional[int] = generation_number
51+
self.handle: Optional[bytes] = handle
52+
53+
@abc.abstractmethod
54+
async def open(self) -> None:
55+
pass
56+
57+
@abc.abstractmethod
58+
async def close(self) -> None:
59+
pass
60+
61+
@abc.abstractmethod
62+
async def send(self, protobuf: Any) -> None:
63+
pass
64+
65+
@abc.abstractmethod
66+
async def recv(self) -> Any:
67+
pass

0 commit comments

Comments
 (0)