Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 9 additions & 39 deletions google/cloud/storage/_experimental/asyncio/_utils.py
Original file line number Diff line number Diff line change
@@ -1,41 +1,11 @@
# Copyright 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import warnings

import google_crc32c
# Import everything from the new stable module
from google.cloud.storage.asyncio._utils import * # noqa

from google.api_core import exceptions


def raise_if_no_fast_crc32c():
"""Check if the C-accelerated version of google-crc32c is available.

If not, raise an error to prevent silent performance degradation.

raises google.api_core.exceptions.FailedPrecondition: If the C extension is not available.
returns: True if the C extension is available.
rtype: bool

"""
if google_crc32c.implementation != "c":
raise exceptions.FailedPrecondition(
"The google-crc32c package is not installed with C support. "
"C extension is required for faster data integrity checks."
"For more information, see https://github.com/googleapis/python-crc32c."
)


def update_write_handle_if_exists(obj, response):
"""Update the write_handle attribute of an object if it exists in the response."""
if hasattr(response, "write_handle") and response.write_handle is not None:
obj.write_handle = response.write_handle
warnings.warn(
"google.cloud.storage._experimental.asyncio._utils has been moved to google.cloud.storage.asyncio._utils. "
"Please update your imports.",
DeprecationWarning,
stacklevel=2,
)
Original file line number Diff line number Diff line change
@@ -1,67 +1,11 @@
# Copyright 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import warnings

import abc
from typing import Any, Optional
# Import everything from the new stable module
from google.cloud.storage.asyncio.async_abstract_object_stream import * # noqa


class _AsyncAbstractObjectStream(abc.ABC):
"""Abstract base class to represent gRPC bidi-stream for GCS ``Object``.

Concrete implementation of this class could be ``_AsyncReadObjectStream``
or ``_AsyncWriteObjectStream``.

:type bucket_name: str
:param bucket_name: (Optional) The name of the bucket containing the object.

:type object_name: str
:param object_name: (Optional) The name of the object.

:type generation_number: int
:param generation_number: (Optional) If present, selects a specific revision of
this object.

:type handle: Any
:param handle: (Optional) The handle for the object, could be read_handle or
write_handle, based on how the stream is used.
"""

def __init__(
self,
bucket_name: str,
object_name: str,
generation_number: Optional[int] = None,
handle: Optional[Any] = None,
) -> None:
super().__init__()
self.bucket_name: str = bucket_name
self.object_name: str = object_name
self.generation_number: Optional[int] = generation_number
self.handle: Optional[Any] = handle

@abc.abstractmethod
async def open(self) -> None:
pass

@abc.abstractmethod
async def close(self) -> None:
pass

@abc.abstractmethod
async def send(self, protobuf: Any) -> None:
pass

@abc.abstractmethod
async def recv(self) -> Any:
pass
warnings.warn(
"google.cloud.storage._experimental.asyncio.async_abstract_object_stream has been moved to google.cloud.storage.asyncio.async_abstract_object_stream. "
"Please update your imports.",
DeprecationWarning,
stacklevel=2,
)
Loading