From 25ec2c0541ff53616fd64042783bc2b6d09c9ef8 Mon Sep 17 00:00:00 2001 From: Daniel Collins Date: Wed, 18 Nov 2020 13:59:59 -0500 Subject: [PATCH 1/3] chore: Add license headers to all files --- google/cloud/pubsublite/admin_client.py | 14 ++++++++++++++ google/cloud/pubsublite/admin_client_interface.py | 14 ++++++++++++++ google/cloud/pubsublite/cloudpubsub/__init__.py | 14 ++++++++++++++ .../cloudpubsub/internal/ack_set_tracker.py | 14 ++++++++++++++ .../cloudpubsub/internal/ack_set_tracker_impl.py | 14 ++++++++++++++ .../cloudpubsub/internal/assigning_subscriber.py | 14 ++++++++++++++ .../cloudpubsub/internal/async_publisher_impl.py | 14 ++++++++++++++ .../cloudpubsub/internal/client_multiplexer.py | 14 ++++++++++++++ .../cloudpubsub/internal/make_publisher.py | 14 ++++++++++++++ .../cloudpubsub/internal/make_subscriber.py | 14 ++++++++++++++ .../cloudpubsub/internal/managed_event_loop.py | 14 ++++++++++++++ .../multiplexed_async_publisher_client.py | 14 ++++++++++++++ .../multiplexed_async_subscriber_client.py | 14 ++++++++++++++ .../internal/multiplexed_publisher_client.py | 14 ++++++++++++++ .../internal/multiplexed_subscriber_client.py | 14 ++++++++++++++ .../cloudpubsub/internal/publisher_impl.py | 14 ++++++++++++++ .../internal/single_partition_subscriber.py | 14 ++++++++++++++ .../cloudpubsub/internal/single_publisher.py | 14 ++++++++++++++ .../cloudpubsub/internal/single_subscriber.py | 14 ++++++++++++++ .../internal/streaming_pull_manager.py | 14 ++++++++++++++ .../cloudpubsub/internal/subscriber_impl.py | 14 ++++++++++++++ .../pubsublite/cloudpubsub/message_transformer.py | 14 ++++++++++++++ .../pubsublite/cloudpubsub/message_transforms.py | 14 ++++++++++++++ .../cloud/pubsublite/cloudpubsub/nack_handler.py | 14 ++++++++++++++ .../pubsublite/cloudpubsub/publisher_client.py | 14 ++++++++++++++ .../cloudpubsub/publisher_client_interface.py | 14 ++++++++++++++ .../pubsublite/cloudpubsub/subscriber_client.py | 14 ++++++++++++++ .../cloudpubsub/subscriber_client_interface.py | 14 ++++++++++++++ .../constructable_from_service_account.py | 14 ++++++++++++++ google/cloud/pubsublite/internal/endpoints.py | 14 ++++++++++++++ .../cloud/pubsublite/internal/routing_metadata.py | 14 ++++++++++++++ google/cloud/pubsublite/internal/status_codes.py | 14 ++++++++++++++ .../pubsublite/internal/wait_ignore_cancelled.py | 14 ++++++++++++++ .../pubsublite/internal/wire/admin_client_impl.py | 14 ++++++++++++++ google/cloud/pubsublite/internal/wire/assigner.py | 14 ++++++++++++++ .../pubsublite/internal/wire/assigner_impl.py | 14 ++++++++++++++ .../cloud/pubsublite/internal/wire/committer.py | 14 ++++++++++++++ .../pubsublite/internal/wire/committer_impl.py | 14 ++++++++++++++ .../cloud/pubsublite/internal/wire/connection.py | 14 ++++++++++++++ .../internal/wire/connection_reinitializer.py | 14 ++++++++++++++ .../internal/wire/default_routing_policy.py | 14 ++++++++++++++ .../internal/wire/fixed_set_assigner.py | 14 ++++++++++++++ .../internal/wire/flow_control_batcher.py | 14 ++++++++++++++ .../pubsublite/internal/wire/gapic_connection.py | 14 ++++++++++++++ .../pubsublite/internal/wire/make_publisher.py | 14 ++++++++++++++ .../pubsublite/internal/wire/merge_metadata.py | 14 ++++++++++++++ .../internal/wire/permanent_failable.py | 14 ++++++++++++++ .../cloud/pubsublite/internal/wire/publisher.py | 14 ++++++++++++++ .../pubsublite/internal/wire/pubsub_context.py | 14 ++++++++++++++ .../internal/wire/retrying_connection.py | 14 ++++++++++++++ .../pubsublite/internal/wire/routing_policy.py | 14 ++++++++++++++ .../pubsublite/internal/wire/routing_publisher.py | 14 ++++++++++++++ .../pubsublite/internal/wire/serial_batcher.py | 14 ++++++++++++++ .../internal/wire/single_partition_publisher.py | 14 ++++++++++++++ .../cloud/pubsublite/internal/wire/subscriber.py | 14 ++++++++++++++ .../pubsublite/internal/wire/subscriber_impl.py | 14 ++++++++++++++ .../cloud/pubsublite/internal/wire/work_item.py | 14 ++++++++++++++ google/cloud/pubsublite/testing/test_utils.py | 14 ++++++++++++++ google/cloud/pubsublite/types/__init__.py | 15 +++++++++++++++ .../pubsublite/types/flow_control_settings.py | 14 ++++++++++++++ google/cloud/pubsublite/types/location.py | 14 ++++++++++++++ google/cloud/pubsublite/types/partition.py | 14 ++++++++++++++ google/cloud/pubsublite/types/paths.py | 14 ++++++++++++++ google/cloud/pubsublite/types/publish_metadata.py | 14 ++++++++++++++ .../internal/ack_set_tracker_impl_test.py | 14 ++++++++++++++ .../internal/assigning_subscriber_test.py | 14 ++++++++++++++ .../internal/async_client_multiplexer_test.py | 14 ++++++++++++++ .../internal/client_multiplexer_test.py | 14 ++++++++++++++ .../multiplexed_async_subscriber_client_test.py | 14 ++++++++++++++ .../cloudpubsub/internal/publisher_impl_test.py | 14 ++++++++++++++ .../internal/single_partition_subscriber_test.py | 14 ++++++++++++++ .../cloudpubsub/internal/subscriber_impl_test.py | 14 ++++++++++++++ .../cloudpubsub/message_transforms_test.py | 14 ++++++++++++++ .../internal/wire/assigner_impl_test.py | 14 ++++++++++++++ .../internal/wire/committer_impl_test.py | 14 ++++++++++++++ .../internal/wire/default_routing_policy_test.py | 14 ++++++++++++++ .../internal/wire/flow_control_batcher_test.py | 14 ++++++++++++++ .../internal/wire/gapic_connection_test.py | 14 ++++++++++++++ .../internal/wire/retrying_connection_test.py | 14 ++++++++++++++ .../pubsublite/internal/wire/routing_tests.json | 13 +++++++++++++ .../wire/single_partition_publisher_test.py | 14 ++++++++++++++ .../internal/wire/subscriber_impl_test.py | 14 ++++++++++++++ 82 files changed, 1148 insertions(+) diff --git a/google/cloud/pubsublite/admin_client.py b/google/cloud/pubsublite/admin_client.py index eac81675..d5e82197 100644 --- a/google/cloud/pubsublite/admin_client.py +++ b/google/cloud/pubsublite/admin_client.py @@ -1,3 +1,17 @@ +# Copyright 2020 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. + from typing import Optional, List from overrides import overrides diff --git a/google/cloud/pubsublite/admin_client_interface.py b/google/cloud/pubsublite/admin_client_interface.py index d8794768..2c59a102 100644 --- a/google/cloud/pubsublite/admin_client_interface.py +++ b/google/cloud/pubsublite/admin_client_interface.py @@ -1,3 +1,17 @@ +# Copyright 2020 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. + from abc import ABC, abstractmethod from typing import List diff --git a/google/cloud/pubsublite/cloudpubsub/__init__.py b/google/cloud/pubsublite/cloudpubsub/__init__.py index c030009e..cce27228 100644 --- a/google/cloud/pubsublite/cloudpubsub/__init__.py +++ b/google/cloud/pubsublite/cloudpubsub/__init__.py @@ -1,3 +1,17 @@ +# Copyright 2020 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. + # flake8: noqa from .message_transformer import MessageTransformer from .nack_handler import NackHandler diff --git a/google/cloud/pubsublite/cloudpubsub/internal/ack_set_tracker.py b/google/cloud/pubsublite/cloudpubsub/internal/ack_set_tracker.py index 3bb40df4..518120a1 100644 --- a/google/cloud/pubsublite/cloudpubsub/internal/ack_set_tracker.py +++ b/google/cloud/pubsublite/cloudpubsub/internal/ack_set_tracker.py @@ -1,3 +1,17 @@ +# Copyright 2020 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. + from abc import abstractmethod from typing import AsyncContextManager diff --git a/google/cloud/pubsublite/cloudpubsub/internal/ack_set_tracker_impl.py b/google/cloud/pubsublite/cloudpubsub/internal/ack_set_tracker_impl.py index 7ab0efb9..d271bed1 100644 --- a/google/cloud/pubsublite/cloudpubsub/internal/ack_set_tracker_impl.py +++ b/google/cloud/pubsublite/cloudpubsub/internal/ack_set_tracker_impl.py @@ -1,3 +1,17 @@ +# Copyright 2020 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 queue from collections import deque from typing import Optional diff --git a/google/cloud/pubsublite/cloudpubsub/internal/assigning_subscriber.py b/google/cloud/pubsublite/cloudpubsub/internal/assigning_subscriber.py index bfc33ff7..18bc3775 100644 --- a/google/cloud/pubsublite/cloudpubsub/internal/assigning_subscriber.py +++ b/google/cloud/pubsublite/cloudpubsub/internal/assigning_subscriber.py @@ -1,3 +1,17 @@ +# Copyright 2020 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. + from asyncio import Future, Queue, ensure_future from typing import Callable, NamedTuple, Dict, Set, Optional diff --git a/google/cloud/pubsublite/cloudpubsub/internal/async_publisher_impl.py b/google/cloud/pubsublite/cloudpubsub/internal/async_publisher_impl.py index 45e635dd..c34101de 100644 --- a/google/cloud/pubsublite/cloudpubsub/internal/async_publisher_impl.py +++ b/google/cloud/pubsublite/cloudpubsub/internal/async_publisher_impl.py @@ -1,3 +1,17 @@ +# Copyright 2020 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. + from typing import Mapping, Callable, Optional from google.pubsub_v1 import PubsubMessage diff --git a/google/cloud/pubsublite/cloudpubsub/internal/client_multiplexer.py b/google/cloud/pubsublite/cloudpubsub/internal/client_multiplexer.py index 7f097f4c..549d065e 100644 --- a/google/cloud/pubsublite/cloudpubsub/internal/client_multiplexer.py +++ b/google/cloud/pubsublite/cloudpubsub/internal/client_multiplexer.py @@ -1,3 +1,17 @@ +# Copyright 2020 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 asyncio import threading from typing import Generic, TypeVar, Callable, Dict, Awaitable diff --git a/google/cloud/pubsublite/cloudpubsub/internal/make_publisher.py b/google/cloud/pubsublite/cloudpubsub/internal/make_publisher.py index c3b1ac4d..c54d086e 100644 --- a/google/cloud/pubsublite/cloudpubsub/internal/make_publisher.py +++ b/google/cloud/pubsublite/cloudpubsub/internal/make_publisher.py @@ -1,3 +1,17 @@ +# Copyright 2020 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. + from typing import Optional, Mapping from google.api_core.client_options import ClientOptions diff --git a/google/cloud/pubsublite/cloudpubsub/internal/make_subscriber.py b/google/cloud/pubsublite/cloudpubsub/internal/make_subscriber.py index 4c520019..6970d1f2 100644 --- a/google/cloud/pubsublite/cloudpubsub/internal/make_subscriber.py +++ b/google/cloud/pubsublite/cloudpubsub/internal/make_subscriber.py @@ -1,3 +1,17 @@ +# Copyright 2020 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. + from typing import Optional, Mapping, Set, AsyncIterator, Callable from uuid import uuid4 diff --git a/google/cloud/pubsublite/cloudpubsub/internal/managed_event_loop.py b/google/cloud/pubsublite/cloudpubsub/internal/managed_event_loop.py index 54c1f532..cbc8f971 100644 --- a/google/cloud/pubsublite/cloudpubsub/internal/managed_event_loop.py +++ b/google/cloud/pubsublite/cloudpubsub/internal/managed_event_loop.py @@ -1,3 +1,17 @@ +# Copyright 2020 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. + from asyncio import AbstractEventLoop, new_event_loop, run_coroutine_threadsafe from concurrent.futures import Future from threading import Thread diff --git a/google/cloud/pubsublite/cloudpubsub/internal/multiplexed_async_publisher_client.py b/google/cloud/pubsublite/cloudpubsub/internal/multiplexed_async_publisher_client.py index 2755d6d9..8e1b766e 100644 --- a/google/cloud/pubsublite/cloudpubsub/internal/multiplexed_async_publisher_client.py +++ b/google/cloud/pubsublite/cloudpubsub/internal/multiplexed_async_publisher_client.py @@ -1,3 +1,17 @@ +# Copyright 2020 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. + from typing import Callable, Union, Mapping from google.api_core.exceptions import GoogleAPICallError diff --git a/google/cloud/pubsublite/cloudpubsub/internal/multiplexed_async_subscriber_client.py b/google/cloud/pubsublite/cloudpubsub/internal/multiplexed_async_subscriber_client.py index ce00b8d0..17115d59 100644 --- a/google/cloud/pubsublite/cloudpubsub/internal/multiplexed_async_subscriber_client.py +++ b/google/cloud/pubsublite/cloudpubsub/internal/multiplexed_async_subscriber_client.py @@ -1,3 +1,17 @@ +# Copyright 2020 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. + from typing import ( Union, AsyncIterator, diff --git a/google/cloud/pubsublite/cloudpubsub/internal/multiplexed_publisher_client.py b/google/cloud/pubsublite/cloudpubsub/internal/multiplexed_publisher_client.py index d94650f1..4bfe9cf5 100644 --- a/google/cloud/pubsublite/cloudpubsub/internal/multiplexed_publisher_client.py +++ b/google/cloud/pubsublite/cloudpubsub/internal/multiplexed_publisher_client.py @@ -1,3 +1,17 @@ +# Copyright 2020 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. + from concurrent.futures import Future from typing import Callable, Union, Mapping diff --git a/google/cloud/pubsublite/cloudpubsub/internal/multiplexed_subscriber_client.py b/google/cloud/pubsublite/cloudpubsub/internal/multiplexed_subscriber_client.py index 2965ecbd..928984ae 100644 --- a/google/cloud/pubsublite/cloudpubsub/internal/multiplexed_subscriber_client.py +++ b/google/cloud/pubsublite/cloudpubsub/internal/multiplexed_subscriber_client.py @@ -1,3 +1,17 @@ +# Copyright 2020 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. + from concurrent.futures.thread import ThreadPoolExecutor from typing import Union, Optional, Set diff --git a/google/cloud/pubsublite/cloudpubsub/internal/publisher_impl.py b/google/cloud/pubsublite/cloudpubsub/internal/publisher_impl.py index 428141b9..7f25e77d 100644 --- a/google/cloud/pubsublite/cloudpubsub/internal/publisher_impl.py +++ b/google/cloud/pubsublite/cloudpubsub/internal/publisher_impl.py @@ -1,3 +1,17 @@ +# Copyright 2020 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. + from concurrent.futures import Future from typing import Mapping diff --git a/google/cloud/pubsublite/cloudpubsub/internal/single_partition_subscriber.py b/google/cloud/pubsublite/cloudpubsub/internal/single_partition_subscriber.py index 6150e818..5cdcfcd5 100644 --- a/google/cloud/pubsublite/cloudpubsub/internal/single_partition_subscriber.py +++ b/google/cloud/pubsublite/cloudpubsub/internal/single_partition_subscriber.py @@ -1,3 +1,17 @@ +# Copyright 2020 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 asyncio from typing import Union, Dict, NamedTuple import queue diff --git a/google/cloud/pubsublite/cloudpubsub/internal/single_publisher.py b/google/cloud/pubsublite/cloudpubsub/internal/single_publisher.py index d4568cf1..96c03b0e 100644 --- a/google/cloud/pubsublite/cloudpubsub/internal/single_publisher.py +++ b/google/cloud/pubsublite/cloudpubsub/internal/single_publisher.py @@ -1,3 +1,17 @@ +# Copyright 2020 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. + from abc import abstractmethod from typing import AsyncContextManager, Mapping, ContextManager from concurrent import futures diff --git a/google/cloud/pubsublite/cloudpubsub/internal/single_subscriber.py b/google/cloud/pubsublite/cloudpubsub/internal/single_subscriber.py index 4ec31b2a..13f0cda2 100644 --- a/google/cloud/pubsublite/cloudpubsub/internal/single_subscriber.py +++ b/google/cloud/pubsublite/cloudpubsub/internal/single_subscriber.py @@ -1,3 +1,17 @@ +# Copyright 2020 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. + from abc import abstractmethod from typing import AsyncContextManager, Callable, Set, Optional diff --git a/google/cloud/pubsublite/cloudpubsub/internal/streaming_pull_manager.py b/google/cloud/pubsublite/cloudpubsub/internal/streaming_pull_manager.py index 490e78fc..dcdb10ac 100644 --- a/google/cloud/pubsublite/cloudpubsub/internal/streaming_pull_manager.py +++ b/google/cloud/pubsublite/cloudpubsub/internal/streaming_pull_manager.py @@ -1,3 +1,17 @@ +# Copyright 2020 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. + from abc import ABC, abstractmethod from typing import Optional, Callable diff --git a/google/cloud/pubsublite/cloudpubsub/internal/subscriber_impl.py b/google/cloud/pubsublite/cloudpubsub/internal/subscriber_impl.py index 891797df..98473fe0 100644 --- a/google/cloud/pubsublite/cloudpubsub/internal/subscriber_impl.py +++ b/google/cloud/pubsublite/cloudpubsub/internal/subscriber_impl.py @@ -1,3 +1,17 @@ +# Copyright 2020 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 concurrent.futures import threading from concurrent.futures.thread import ThreadPoolExecutor diff --git a/google/cloud/pubsublite/cloudpubsub/message_transformer.py b/google/cloud/pubsublite/cloudpubsub/message_transformer.py index 73585fdb..3dfb6c86 100644 --- a/google/cloud/pubsublite/cloudpubsub/message_transformer.py +++ b/google/cloud/pubsublite/cloudpubsub/message_transformer.py @@ -1,3 +1,17 @@ +# Copyright 2020 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. + from abc import ABC, abstractmethod from google.pubsub_v1 import PubsubMessage diff --git a/google/cloud/pubsublite/cloudpubsub/message_transforms.py b/google/cloud/pubsublite/cloudpubsub/message_transforms.py index ba1dce04..ba6308e0 100644 --- a/google/cloud/pubsublite/cloudpubsub/message_transforms.py +++ b/google/cloud/pubsublite/cloudpubsub/message_transforms.py @@ -1,3 +1,17 @@ +# Copyright 2020 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 datetime from google.api_core.exceptions import InvalidArgument diff --git a/google/cloud/pubsublite/cloudpubsub/nack_handler.py b/google/cloud/pubsublite/cloudpubsub/nack_handler.py index d2d054d9..978d6092 100644 --- a/google/cloud/pubsublite/cloudpubsub/nack_handler.py +++ b/google/cloud/pubsublite/cloudpubsub/nack_handler.py @@ -1,3 +1,17 @@ +# Copyright 2020 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. + from abc import ABC, abstractmethod from typing import Callable diff --git a/google/cloud/pubsublite/cloudpubsub/publisher_client.py b/google/cloud/pubsublite/cloudpubsub/publisher_client.py index 23c72f32..2463d302 100644 --- a/google/cloud/pubsublite/cloudpubsub/publisher_client.py +++ b/google/cloud/pubsublite/cloudpubsub/publisher_client.py @@ -1,3 +1,17 @@ +# Copyright 2020 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. + from concurrent.futures import Future from typing import Optional, Mapping, Union diff --git a/google/cloud/pubsublite/cloudpubsub/publisher_client_interface.py b/google/cloud/pubsublite/cloudpubsub/publisher_client_interface.py index c024585f..3b19a351 100644 --- a/google/cloud/pubsublite/cloudpubsub/publisher_client_interface.py +++ b/google/cloud/pubsublite/cloudpubsub/publisher_client_interface.py @@ -1,3 +1,17 @@ +# Copyright 2020 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. + from abc import abstractmethod from concurrent.futures import Future from typing import ContextManager, Mapping, Union, AsyncContextManager diff --git a/google/cloud/pubsublite/cloudpubsub/subscriber_client.py b/google/cloud/pubsublite/cloudpubsub/subscriber_client.py index 713ad7fb..717369ef 100644 --- a/google/cloud/pubsublite/cloudpubsub/subscriber_client.py +++ b/google/cloud/pubsublite/cloudpubsub/subscriber_client.py @@ -1,3 +1,17 @@ +# Copyright 2020 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. + from concurrent.futures.thread import ThreadPoolExecutor from typing import Optional, Union, Set, AsyncIterator diff --git a/google/cloud/pubsublite/cloudpubsub/subscriber_client_interface.py b/google/cloud/pubsublite/cloudpubsub/subscriber_client_interface.py index 90160488..8dd23506 100644 --- a/google/cloud/pubsublite/cloudpubsub/subscriber_client_interface.py +++ b/google/cloud/pubsublite/cloudpubsub/subscriber_client_interface.py @@ -1,3 +1,17 @@ +# Copyright 2020 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. + from abc import abstractmethod from typing import ( ContextManager, diff --git a/google/cloud/pubsublite/internal/constructable_from_service_account.py b/google/cloud/pubsublite/internal/constructable_from_service_account.py index 1261c5fc..80fcc42a 100644 --- a/google/cloud/pubsublite/internal/constructable_from_service_account.py +++ b/google/cloud/pubsublite/internal/constructable_from_service_account.py @@ -1,3 +1,17 @@ +# Copyright 2020 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. + from google.oauth2 import service_account diff --git a/google/cloud/pubsublite/internal/endpoints.py b/google/cloud/pubsublite/internal/endpoints.py index 0422e1c7..282897e2 100644 --- a/google/cloud/pubsublite/internal/endpoints.py +++ b/google/cloud/pubsublite/internal/endpoints.py @@ -1,3 +1,17 @@ +# Copyright 2020 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. + from google.cloud.pubsublite.types import CloudRegion diff --git a/google/cloud/pubsublite/internal/routing_metadata.py b/google/cloud/pubsublite/internal/routing_metadata.py index d29aa882..d16eed15 100644 --- a/google/cloud/pubsublite/internal/routing_metadata.py +++ b/google/cloud/pubsublite/internal/routing_metadata.py @@ -1,3 +1,17 @@ +# Copyright 2020 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. + from typing import Mapping from urllib.parse import urlencode diff --git a/google/cloud/pubsublite/internal/status_codes.py b/google/cloud/pubsublite/internal/status_codes.py index bd9aabc5..1671b811 100644 --- a/google/cloud/pubsublite/internal/status_codes.py +++ b/google/cloud/pubsublite/internal/status_codes.py @@ -1,3 +1,17 @@ +# Copyright 2020 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. + from grpc import StatusCode from google.api_core.exceptions import GoogleAPICallError diff --git a/google/cloud/pubsublite/internal/wait_ignore_cancelled.py b/google/cloud/pubsublite/internal/wait_ignore_cancelled.py index 2f3d2946..d4221ef1 100644 --- a/google/cloud/pubsublite/internal/wait_ignore_cancelled.py +++ b/google/cloud/pubsublite/internal/wait_ignore_cancelled.py @@ -1,3 +1,17 @@ +# Copyright 2020 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. + from asyncio import CancelledError from typing import Awaitable diff --git a/google/cloud/pubsublite/internal/wire/admin_client_impl.py b/google/cloud/pubsublite/internal/wire/admin_client_impl.py index 030a76a0..234916b9 100644 --- a/google/cloud/pubsublite/internal/wire/admin_client_impl.py +++ b/google/cloud/pubsublite/internal/wire/admin_client_impl.py @@ -1,3 +1,17 @@ +# Copyright 2020 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. + from typing import List from google.protobuf.field_mask_pb2 import FieldMask diff --git a/google/cloud/pubsublite/internal/wire/assigner.py b/google/cloud/pubsublite/internal/wire/assigner.py index 9ab06991..c8b25498 100644 --- a/google/cloud/pubsublite/internal/wire/assigner.py +++ b/google/cloud/pubsublite/internal/wire/assigner.py @@ -1,3 +1,17 @@ +# Copyright 2020 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. + from abc import abstractmethod from typing import AsyncContextManager, Set diff --git a/google/cloud/pubsublite/internal/wire/assigner_impl.py b/google/cloud/pubsublite/internal/wire/assigner_impl.py index acff74b4..13db5b89 100644 --- a/google/cloud/pubsublite/internal/wire/assigner_impl.py +++ b/google/cloud/pubsublite/internal/wire/assigner_impl.py @@ -1,3 +1,17 @@ +# Copyright 2020 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 asyncio from typing import Optional, Set diff --git a/google/cloud/pubsublite/internal/wire/committer.py b/google/cloud/pubsublite/internal/wire/committer.py index f225becf..23e8e96a 100644 --- a/google/cloud/pubsublite/internal/wire/committer.py +++ b/google/cloud/pubsublite/internal/wire/committer.py @@ -1,3 +1,17 @@ +# Copyright 2020 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. + from abc import abstractmethod from typing import AsyncContextManager diff --git a/google/cloud/pubsublite/internal/wire/committer_impl.py b/google/cloud/pubsublite/internal/wire/committer_impl.py index 6647c752..115845fe 100644 --- a/google/cloud/pubsublite/internal/wire/committer_impl.py +++ b/google/cloud/pubsublite/internal/wire/committer_impl.py @@ -1,3 +1,17 @@ +# Copyright 2020 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 asyncio from typing import Optional, List, Iterable diff --git a/google/cloud/pubsublite/internal/wire/connection.py b/google/cloud/pubsublite/internal/wire/connection.py index 6d96a1b7..2816fa5f 100644 --- a/google/cloud/pubsublite/internal/wire/connection.py +++ b/google/cloud/pubsublite/internal/wire/connection.py @@ -1,3 +1,17 @@ +# Copyright 2020 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. + from typing import Generic, TypeVar, AsyncContextManager from abc import abstractmethod diff --git a/google/cloud/pubsublite/internal/wire/connection_reinitializer.py b/google/cloud/pubsublite/internal/wire/connection_reinitializer.py index db6c375d..d789708d 100644 --- a/google/cloud/pubsublite/internal/wire/connection_reinitializer.py +++ b/google/cloud/pubsublite/internal/wire/connection_reinitializer.py @@ -1,3 +1,17 @@ +# Copyright 2020 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. + from typing import Generic from abc import ABCMeta, abstractmethod from google.cloud.pubsublite.internal.wire.connection import ( diff --git a/google/cloud/pubsublite/internal/wire/default_routing_policy.py b/google/cloud/pubsublite/internal/wire/default_routing_policy.py index 75021c31..5e020182 100644 --- a/google/cloud/pubsublite/internal/wire/default_routing_policy.py +++ b/google/cloud/pubsublite/internal/wire/default_routing_policy.py @@ -1,3 +1,17 @@ +# Copyright 2020 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 hashlib import random diff --git a/google/cloud/pubsublite/internal/wire/fixed_set_assigner.py b/google/cloud/pubsublite/internal/wire/fixed_set_assigner.py index dbe94e8f..86565dea 100644 --- a/google/cloud/pubsublite/internal/wire/fixed_set_assigner.py +++ b/google/cloud/pubsublite/internal/wire/fixed_set_assigner.py @@ -1,3 +1,17 @@ +# Copyright 2020 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 asyncio from typing import Set diff --git a/google/cloud/pubsublite/internal/wire/flow_control_batcher.py b/google/cloud/pubsublite/internal/wire/flow_control_batcher.py index 68340362..7e99fb58 100644 --- a/google/cloud/pubsublite/internal/wire/flow_control_batcher.py +++ b/google/cloud/pubsublite/internal/wire/flow_control_batcher.py @@ -1,3 +1,17 @@ +# Copyright 2020 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. + from typing import List, Optional from google.cloud.pubsublite_v1 import FlowControlRequest, SequencedMessage diff --git a/google/cloud/pubsublite/internal/wire/gapic_connection.py b/google/cloud/pubsublite/internal/wire/gapic_connection.py index 41d720dd..27657799 100644 --- a/google/cloud/pubsublite/internal/wire/gapic_connection.py +++ b/google/cloud/pubsublite/internal/wire/gapic_connection.py @@ -1,3 +1,17 @@ +# Copyright 2020 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. + from typing import AsyncIterator, TypeVar, Optional, Callable, AsyncIterable, Awaitable import asyncio diff --git a/google/cloud/pubsublite/internal/wire/make_publisher.py b/google/cloud/pubsublite/internal/wire/make_publisher.py index 93abaad3..27d2d4cc 100644 --- a/google/cloud/pubsublite/internal/wire/make_publisher.py +++ b/google/cloud/pubsublite/internal/wire/make_publisher.py @@ -1,3 +1,17 @@ +# Copyright 2020 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. + from typing import AsyncIterator, Mapping, Optional, MutableMapping from google.cloud.pubsub_v1.types import BatchSettings diff --git a/google/cloud/pubsublite/internal/wire/merge_metadata.py b/google/cloud/pubsublite/internal/wire/merge_metadata.py index 4c3e30db..6ea31c3a 100644 --- a/google/cloud/pubsublite/internal/wire/merge_metadata.py +++ b/google/cloud/pubsublite/internal/wire/merge_metadata.py @@ -1,3 +1,17 @@ +# Copyright 2020 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. + from typing import Mapping, Optional diff --git a/google/cloud/pubsublite/internal/wire/permanent_failable.py b/google/cloud/pubsublite/internal/wire/permanent_failable.py index 6bcb1125..2fcf54a7 100644 --- a/google/cloud/pubsublite/internal/wire/permanent_failable.py +++ b/google/cloud/pubsublite/internal/wire/permanent_failable.py @@ -1,3 +1,17 @@ +# Copyright 2020 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 asyncio from typing import Awaitable, TypeVar, Optional, Callable diff --git a/google/cloud/pubsublite/internal/wire/publisher.py b/google/cloud/pubsublite/internal/wire/publisher.py index 9ca07d7b..d9a14a94 100644 --- a/google/cloud/pubsublite/internal/wire/publisher.py +++ b/google/cloud/pubsublite/internal/wire/publisher.py @@ -1,3 +1,17 @@ +# Copyright 2020 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. + from abc import abstractmethod from typing import AsyncContextManager from google.cloud.pubsublite_v1.types import PubSubMessage diff --git a/google/cloud/pubsublite/internal/wire/pubsub_context.py b/google/cloud/pubsublite/internal/wire/pubsub_context.py index f64968f1..032f5fc7 100644 --- a/google/cloud/pubsublite/internal/wire/pubsub_context.py +++ b/google/cloud/pubsublite/internal/wire/pubsub_context.py @@ -1,3 +1,17 @@ +# Copyright 2020 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. + from base64 import b64encode from typing import Mapping, Optional, NamedTuple diff --git a/google/cloud/pubsublite/internal/wire/retrying_connection.py b/google/cloud/pubsublite/internal/wire/retrying_connection.py index c766ea8f..af8fdc74 100644 --- a/google/cloud/pubsublite/internal/wire/retrying_connection.py +++ b/google/cloud/pubsublite/internal/wire/retrying_connection.py @@ -1,3 +1,17 @@ +# Copyright 2020 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 asyncio from asyncio import Future diff --git a/google/cloud/pubsublite/internal/wire/routing_policy.py b/google/cloud/pubsublite/internal/wire/routing_policy.py index 8191fd8d..362e04eb 100644 --- a/google/cloud/pubsublite/internal/wire/routing_policy.py +++ b/google/cloud/pubsublite/internal/wire/routing_policy.py @@ -1,3 +1,17 @@ +# Copyright 2020 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. + from abc import ABC, abstractmethod from google.cloud.pubsublite.types import Partition diff --git a/google/cloud/pubsublite/internal/wire/routing_publisher.py b/google/cloud/pubsublite/internal/wire/routing_publisher.py index 2558df9c..e6db82e1 100644 --- a/google/cloud/pubsublite/internal/wire/routing_publisher.py +++ b/google/cloud/pubsublite/internal/wire/routing_publisher.py @@ -1,3 +1,17 @@ +# Copyright 2020 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 asyncio from typing import Mapping diff --git a/google/cloud/pubsublite/internal/wire/serial_batcher.py b/google/cloud/pubsublite/internal/wire/serial_batcher.py index 55943e85..218e5869 100644 --- a/google/cloud/pubsublite/internal/wire/serial_batcher.py +++ b/google/cloud/pubsublite/internal/wire/serial_batcher.py @@ -1,3 +1,17 @@ +# Copyright 2020 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. + from abc import abstractmethod from typing import Generic, List, Iterable import asyncio diff --git a/google/cloud/pubsublite/internal/wire/single_partition_publisher.py b/google/cloud/pubsublite/internal/wire/single_partition_publisher.py index bc48fd6a..90f6f46a 100644 --- a/google/cloud/pubsublite/internal/wire/single_partition_publisher.py +++ b/google/cloud/pubsublite/internal/wire/single_partition_publisher.py @@ -1,3 +1,17 @@ +# Copyright 2020 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 asyncio from typing import Optional, List, Iterable diff --git a/google/cloud/pubsublite/internal/wire/subscriber.py b/google/cloud/pubsublite/internal/wire/subscriber.py index 4b8535f2..45dfc1c4 100644 --- a/google/cloud/pubsublite/internal/wire/subscriber.py +++ b/google/cloud/pubsublite/internal/wire/subscriber.py @@ -1,3 +1,17 @@ +# Copyright 2020 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. + from abc import abstractmethod from typing import AsyncContextManager from google.cloud.pubsublite_v1.types import SequencedMessage, FlowControlRequest diff --git a/google/cloud/pubsublite/internal/wire/subscriber_impl.py b/google/cloud/pubsublite/internal/wire/subscriber_impl.py index 8c2df143..a19ce0d5 100644 --- a/google/cloud/pubsublite/internal/wire/subscriber_impl.py +++ b/google/cloud/pubsublite/internal/wire/subscriber_impl.py @@ -1,3 +1,17 @@ +# Copyright 2020 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 asyncio from typing import Optional diff --git a/google/cloud/pubsublite/internal/wire/work_item.py b/google/cloud/pubsublite/internal/wire/work_item.py index 9ec3775f..618958f5 100644 --- a/google/cloud/pubsublite/internal/wire/work_item.py +++ b/google/cloud/pubsublite/internal/wire/work_item.py @@ -1,3 +1,17 @@ +# Copyright 2020 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 asyncio from typing import Generic diff --git a/google/cloud/pubsublite/testing/test_utils.py b/google/cloud/pubsublite/testing/test_utils.py index 335da709..f5077203 100644 --- a/google/cloud/pubsublite/testing/test_utils.py +++ b/google/cloud/pubsublite/testing/test_utils.py @@ -1,3 +1,17 @@ +# Copyright 2020 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 asyncio from typing import List, Union, Any, TypeVar, Generic, Optional diff --git a/google/cloud/pubsublite/types/__init__.py b/google/cloud/pubsublite/types/__init__.py index 5103ec25..146755d0 100644 --- a/google/cloud/pubsublite/types/__init__.py +++ b/google/cloud/pubsublite/types/__init__.py @@ -1,3 +1,18 @@ +# Copyright 2020 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. +# + from .location import CloudRegion, CloudZone from .partition import Partition from .paths import LocationPath, TopicPath, SubscriptionPath diff --git a/google/cloud/pubsublite/types/flow_control_settings.py b/google/cloud/pubsublite/types/flow_control_settings.py index 7ac72432..f21c56f5 100644 --- a/google/cloud/pubsublite/types/flow_control_settings.py +++ b/google/cloud/pubsublite/types/flow_control_settings.py @@ -1,3 +1,17 @@ +# Copyright 2020 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. + from typing import NamedTuple diff --git a/google/cloud/pubsublite/types/location.py b/google/cloud/pubsublite/types/location.py index 6bacd83a..e24667f3 100644 --- a/google/cloud/pubsublite/types/location.py +++ b/google/cloud/pubsublite/types/location.py @@ -1,3 +1,17 @@ +# Copyright 2020 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. + from typing import NamedTuple from google.api_core.exceptions import InvalidArgument diff --git a/google/cloud/pubsublite/types/partition.py b/google/cloud/pubsublite/types/partition.py index e8f4ccbd..2a95d4cf 100644 --- a/google/cloud/pubsublite/types/partition.py +++ b/google/cloud/pubsublite/types/partition.py @@ -1,3 +1,17 @@ +# Copyright 2020 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. + from typing import NamedTuple diff --git a/google/cloud/pubsublite/types/paths.py b/google/cloud/pubsublite/types/paths.py index 66a09ba4..9038180a 100644 --- a/google/cloud/pubsublite/types/paths.py +++ b/google/cloud/pubsublite/types/paths.py @@ -1,3 +1,17 @@ +# Copyright 2020 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. + from typing import NamedTuple from google.api_core.exceptions import InvalidArgument diff --git a/google/cloud/pubsublite/types/publish_metadata.py b/google/cloud/pubsublite/types/publish_metadata.py index 869741e3..c746eda1 100644 --- a/google/cloud/pubsublite/types/publish_metadata.py +++ b/google/cloud/pubsublite/types/publish_metadata.py @@ -1,3 +1,17 @@ +# Copyright 2020 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. + from typing import NamedTuple import json diff --git a/tests/unit/pubsublite/cloudpubsub/internal/ack_set_tracker_impl_test.py b/tests/unit/pubsublite/cloudpubsub/internal/ack_set_tracker_impl_test.py index 24ebd588..5eb3d053 100644 --- a/tests/unit/pubsublite/cloudpubsub/internal/ack_set_tracker_impl_test.py +++ b/tests/unit/pubsublite/cloudpubsub/internal/ack_set_tracker_impl_test.py @@ -1,3 +1,17 @@ +# Copyright 2020 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. + from asynctest.mock import MagicMock, call import pytest diff --git a/tests/unit/pubsublite/cloudpubsub/internal/assigning_subscriber_test.py b/tests/unit/pubsublite/cloudpubsub/internal/assigning_subscriber_test.py index 85c7db14..50a39ae0 100644 --- a/tests/unit/pubsublite/cloudpubsub/internal/assigning_subscriber_test.py +++ b/tests/unit/pubsublite/cloudpubsub/internal/assigning_subscriber_test.py @@ -1,3 +1,17 @@ +# Copyright 2020 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. + from typing import Set from asynctest.mock import MagicMock, call diff --git a/tests/unit/pubsublite/cloudpubsub/internal/async_client_multiplexer_test.py b/tests/unit/pubsublite/cloudpubsub/internal/async_client_multiplexer_test.py index feefea1e..926fdb0d 100644 --- a/tests/unit/pubsublite/cloudpubsub/internal/async_client_multiplexer_test.py +++ b/tests/unit/pubsublite/cloudpubsub/internal/async_client_multiplexer_test.py @@ -1,3 +1,17 @@ +# Copyright 2020 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 pytest from asynctest.mock import call, CoroutineMock diff --git a/tests/unit/pubsublite/cloudpubsub/internal/client_multiplexer_test.py b/tests/unit/pubsublite/cloudpubsub/internal/client_multiplexer_test.py index 21e26aa1..a3bc9305 100644 --- a/tests/unit/pubsublite/cloudpubsub/internal/client_multiplexer_test.py +++ b/tests/unit/pubsublite/cloudpubsub/internal/client_multiplexer_test.py @@ -1,3 +1,17 @@ +# Copyright 2020 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 pytest from mock import MagicMock, call diff --git a/tests/unit/pubsublite/cloudpubsub/internal/multiplexed_async_subscriber_client_test.py b/tests/unit/pubsublite/cloudpubsub/internal/multiplexed_async_subscriber_client_test.py index 4a0ca557..7283f057 100644 --- a/tests/unit/pubsublite/cloudpubsub/internal/multiplexed_async_subscriber_client_test.py +++ b/tests/unit/pubsublite/cloudpubsub/internal/multiplexed_async_subscriber_client_test.py @@ -1,3 +1,17 @@ +# Copyright 2020 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 asyncio import pytest diff --git a/tests/unit/pubsublite/cloudpubsub/internal/publisher_impl_test.py b/tests/unit/pubsublite/cloudpubsub/internal/publisher_impl_test.py index 67b3e8e8..765abba7 100644 --- a/tests/unit/pubsublite/cloudpubsub/internal/publisher_impl_test.py +++ b/tests/unit/pubsublite/cloudpubsub/internal/publisher_impl_test.py @@ -1,3 +1,17 @@ +# Copyright 2020 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. + from asynctest.mock import MagicMock import pytest diff --git a/tests/unit/pubsublite/cloudpubsub/internal/single_partition_subscriber_test.py b/tests/unit/pubsublite/cloudpubsub/internal/single_partition_subscriber_test.py index 0a136e8d..55f6fe30 100644 --- a/tests/unit/pubsublite/cloudpubsub/internal/single_partition_subscriber_test.py +++ b/tests/unit/pubsublite/cloudpubsub/internal/single_partition_subscriber_test.py @@ -1,3 +1,17 @@ +# Copyright 2020 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 asyncio from typing import Callable diff --git a/tests/unit/pubsublite/cloudpubsub/internal/subscriber_impl_test.py b/tests/unit/pubsublite/cloudpubsub/internal/subscriber_impl_test.py index aaf35664..f3899719 100644 --- a/tests/unit/pubsublite/cloudpubsub/internal/subscriber_impl_test.py +++ b/tests/unit/pubsublite/cloudpubsub/internal/subscriber_impl_test.py @@ -1,3 +1,17 @@ +# Copyright 2020 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 asyncio import concurrent from concurrent.futures.thread import ThreadPoolExecutor diff --git a/tests/unit/pubsublite/cloudpubsub/message_transforms_test.py b/tests/unit/pubsublite/cloudpubsub/message_transforms_test.py index b9182057..79478a4f 100644 --- a/tests/unit/pubsublite/cloudpubsub/message_transforms_test.py +++ b/tests/unit/pubsublite/cloudpubsub/message_transforms_test.py @@ -1,3 +1,17 @@ +# Copyright 2020 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 datetime import pytest diff --git a/tests/unit/pubsublite/internal/wire/assigner_impl_test.py b/tests/unit/pubsublite/internal/wire/assigner_impl_test.py index e35d4432..b4efc4f3 100644 --- a/tests/unit/pubsublite/internal/wire/assigner_impl_test.py +++ b/tests/unit/pubsublite/internal/wire/assigner_impl_test.py @@ -1,3 +1,17 @@ +# Copyright 2020 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 asyncio from unittest.mock import call from collections import defaultdict diff --git a/tests/unit/pubsublite/internal/wire/committer_impl_test.py b/tests/unit/pubsublite/internal/wire/committer_impl_test.py index 55bb2971..c1105d46 100644 --- a/tests/unit/pubsublite/internal/wire/committer_impl_test.py +++ b/tests/unit/pubsublite/internal/wire/committer_impl_test.py @@ -1,3 +1,17 @@ +# Copyright 2020 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 asyncio from unittest.mock import call from collections import defaultdict diff --git a/tests/unit/pubsublite/internal/wire/default_routing_policy_test.py b/tests/unit/pubsublite/internal/wire/default_routing_policy_test.py index 9e7f0eff..a242fcd6 100644 --- a/tests/unit/pubsublite/internal/wire/default_routing_policy_test.py +++ b/tests/unit/pubsublite/internal/wire/default_routing_policy_test.py @@ -1,3 +1,17 @@ +# Copyright 2020 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 json import os diff --git a/tests/unit/pubsublite/internal/wire/flow_control_batcher_test.py b/tests/unit/pubsublite/internal/wire/flow_control_batcher_test.py index 4e8ecf0d..000a32f7 100644 --- a/tests/unit/pubsublite/internal/wire/flow_control_batcher_test.py +++ b/tests/unit/pubsublite/internal/wire/flow_control_batcher_test.py @@ -1,3 +1,17 @@ +# Copyright 2020 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. + from google.cloud.pubsublite.internal.wire.flow_control_batcher import ( FlowControlBatcher, ) diff --git a/tests/unit/pubsublite/internal/wire/gapic_connection_test.py b/tests/unit/pubsublite/internal/wire/gapic_connection_test.py index 69126b0d..90a43559 100644 --- a/tests/unit/pubsublite/internal/wire/gapic_connection_test.py +++ b/tests/unit/pubsublite/internal/wire/gapic_connection_test.py @@ -1,3 +1,17 @@ +# Copyright 2020 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 asyncio import pytest diff --git a/tests/unit/pubsublite/internal/wire/retrying_connection_test.py b/tests/unit/pubsublite/internal/wire/retrying_connection_test.py index 60b1f9f0..027c5dd4 100644 --- a/tests/unit/pubsublite/internal/wire/retrying_connection_test.py +++ b/tests/unit/pubsublite/internal/wire/retrying_connection_test.py @@ -1,3 +1,17 @@ +# Copyright 2020 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 asyncio from asynctest.mock import MagicMock, CoroutineMock diff --git a/tests/unit/pubsublite/internal/wire/routing_tests.json b/tests/unit/pubsublite/internal/wire/routing_tests.json index 353f36bf..9ca2a2d2 100644 --- a/tests/unit/pubsublite/internal/wire/routing_tests.json +++ b/tests/unit/pubsublite/internal/wire/routing_tests.json @@ -1,3 +1,16 @@ +// Copyright 2020 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. // File defining a map from routing keys to the expected partition in a 29 // partition topic for test purposes. This file should be copied into all client // library test suites. diff --git a/tests/unit/pubsublite/internal/wire/single_partition_publisher_test.py b/tests/unit/pubsublite/internal/wire/single_partition_publisher_test.py index cfd998ac..a2771e87 100644 --- a/tests/unit/pubsublite/internal/wire/single_partition_publisher_test.py +++ b/tests/unit/pubsublite/internal/wire/single_partition_publisher_test.py @@ -1,3 +1,17 @@ +# Copyright 2020 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 asyncio from unittest.mock import call from collections import defaultdict diff --git a/tests/unit/pubsublite/internal/wire/subscriber_impl_test.py b/tests/unit/pubsublite/internal/wire/subscriber_impl_test.py index 1031012d..ed773695 100644 --- a/tests/unit/pubsublite/internal/wire/subscriber_impl_test.py +++ b/tests/unit/pubsublite/internal/wire/subscriber_impl_test.py @@ -1,3 +1,17 @@ +# Copyright 2020 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 asyncio from unittest.mock import call from collections import defaultdict From 97db7a5957fa3986b841af7cfddb0feae46c86e2 Mon Sep 17 00:00:00 2001 From: Daniel Collins Date: Wed, 18 Nov 2020 15:12:19 -0500 Subject: [PATCH 2/3] fix: Enforce that __enter__ is called on all user interfaces before use --- .../cloudpubsub/publisher_client.py | 11 ++++++ .../cloudpubsub/subscriber_client.py | 11 ++++++ .../pubsublite/internal/require_started.py | 35 +++++++++++++++++++ samples/snippets/subscriber_example.py | 29 ++++++++------- 4 files changed, 71 insertions(+), 15 deletions(-) create mode 100644 google/cloud/pubsublite/internal/require_started.py diff --git a/google/cloud/pubsublite/cloudpubsub/publisher_client.py b/google/cloud/pubsublite/cloudpubsub/publisher_client.py index 2463d302..9ddd4da5 100644 --- a/google/cloud/pubsublite/cloudpubsub/publisher_client.py +++ b/google/cloud/pubsublite/cloudpubsub/publisher_client.py @@ -36,6 +36,7 @@ from google.cloud.pubsublite.internal.constructable_from_service_account import ( ConstructableFromServiceAccount, ) +from google.cloud.pubsublite.internal.require_started import RequireStarted from google.cloud.pubsublite.internal.wire.make_publisher import ( DEFAULT_BATCHING_SETTINGS as WIRE_DEFAULT_BATCHING, ) @@ -52,6 +53,7 @@ class PublisherClient(PublisherClientInterface, ConstructableFromServiceAccount) """ _impl: PublisherClientInterface + _require_stared: RequireStarted DEFAULT_BATCHING_SETTINGS = WIRE_DEFAULT_BATCHING """ @@ -83,6 +85,7 @@ def __init__( transport=transport, ) ) + self._require_stared = RequireStarted() @overrides def publish( @@ -92,18 +95,21 @@ def publish( ordering_key: str = "", **attrs: Mapping[str, str] ) -> "Future[str]": + self._require_stared.require_started() return self._impl.publish( topic=topic, data=data, ordering_key=ordering_key, **attrs ) @overrides def __enter__(self): + self._require_stared.__enter__() self._impl.__enter__() return self @overrides def __exit__(self, exc_type, exc_value, traceback): self._impl.__exit__(exc_type, exc_value, traceback) + self._require_stared.__exit__(exc_type, exc_value, traceback) class AsyncPublisherClient( @@ -117,6 +123,7 @@ class AsyncPublisherClient( """ _impl: AsyncPublisherClientInterface + _require_stared: RequireStarted DEFAULT_BATCHING_SETTINGS = WIRE_DEFAULT_BATCHING """ @@ -148,6 +155,7 @@ def __init__( transport=transport, ) ) + self._require_stared = RequireStarted() @overrides async def publish( @@ -157,15 +165,18 @@ async def publish( ordering_key: str = "", **attrs: Mapping[str, str] ) -> str: + self._require_stared.require_started() return await self._impl.publish( topic=topic, data=data, ordering_key=ordering_key, **attrs ) @overrides async def __aenter__(self): + self._require_stared.__enter__() await self._impl.__aenter__() return self @overrides async def __aexit__(self, exc_type, exc_value, traceback): await self._impl.__aexit__(exc_type, exc_value, traceback) + self._require_stared.__exit__(exc_type, exc_value, traceback) diff --git a/google/cloud/pubsublite/cloudpubsub/subscriber_client.py b/google/cloud/pubsublite/cloudpubsub/subscriber_client.py index 717369ef..96134938 100644 --- a/google/cloud/pubsublite/cloudpubsub/subscriber_client.py +++ b/google/cloud/pubsublite/cloudpubsub/subscriber_client.py @@ -39,6 +39,7 @@ from google.cloud.pubsublite.internal.constructable_from_service_account import ( ConstructableFromServiceAccount, ) +from google.cloud.pubsublite.internal.require_started import RequireStarted from google.cloud.pubsublite.types import ( FlowControlSettings, Partition, @@ -56,6 +57,7 @@ class SubscriberClient(SubscriberClientInterface, ConstructableFromServiceAccoun """ _impl: SubscriberClientInterface + _require_started: RequireStarted def __init__( self, @@ -92,6 +94,7 @@ def __init__( client_options=client_options, ), ) + self._require_started = RequireStarted() @overrides def subscribe( @@ -101,6 +104,7 @@ def subscribe( per_partition_flow_control_settings: FlowControlSettings, fixed_partitions: Optional[Set[Partition]] = None, ) -> StreamingPullFuture: + self._require_started.require_started() return self._impl.subscribe( subscription, callback, @@ -110,12 +114,14 @@ def subscribe( @overrides def __enter__(self): + self._require_started.__enter__() self._impl.__enter__() return self @overrides def __exit__(self, exc_type, exc_value, traceback): self._impl.__exit__(exc_type, exc_value, traceback) + self._require_started.__exit__(exc_type, exc_value, traceback) class AsyncSubscriberClient( @@ -130,6 +136,7 @@ class AsyncSubscriberClient( """ _impl: AsyncSubscriberClientInterface + _require_started: RequireStarted def __init__( self, @@ -161,6 +168,7 @@ def __init__( client_options=client_options, ) ) + self._require_started = RequireStarted() @overrides async def subscribe( @@ -169,15 +177,18 @@ async def subscribe( per_partition_flow_control_settings: FlowControlSettings, fixed_partitions: Optional[Set[Partition]] = None, ) -> AsyncIterator[Message]: + self._require_started.require_started() return await self._impl.subscribe( subscription, per_partition_flow_control_settings, fixed_partitions ) @overrides async def __aenter__(self): + self._require_started.__enter__() await self._impl.__aenter__() return self @overrides async def __aexit__(self, exc_type, exc_value, traceback): await self._impl.__aexit__(exc_type, exc_value, traceback) + self._require_started.__exit__(exc_type, exc_value, traceback) diff --git a/google/cloud/pubsublite/internal/require_started.py b/google/cloud/pubsublite/internal/require_started.py new file mode 100644 index 00000000..b7d4337b --- /dev/null +++ b/google/cloud/pubsublite/internal/require_started.py @@ -0,0 +1,35 @@ +# Copyright 2020 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. + +from typing import ContextManager + +from google.api_core.exceptions import FailedPrecondition + + +class RequireStarted(ContextManager): + def __init__(self): + self._started = False + + def __enter__(self): + if self._started: + raise FailedPrecondition("__enter__ called twice.") + self._started = True + return self + + def require_started(self): + if not self._started: + raise FailedPrecondition("__enter__ has never been called.") + + def __exit__(self, exc_type, exc_value, traceback): + self.require_started() diff --git a/samples/snippets/subscriber_example.py b/samples/snippets/subscriber_example.py index ed2fba41..a50c0f72 100644 --- a/samples/snippets/subscriber_example.py +++ b/samples/snippets/subscriber_example.py @@ -59,21 +59,20 @@ def callback(message): print(f"Received {message_data} of ordering key {message.ordering_key}.") message.ack() - subscriber_client = SubscriberClient() - - streaming_pull_future = subscriber_client.subscribe( - subscription_path, - callback=callback, - per_partition_flow_control_settings=per_partition_flow_control_settings, - ) - - print(f"Listening for messages on {str(subscription_path)}...") - - try: - streaming_pull_future.result(timeout=timeout) - except TimeoutError or KeyboardInterrupt: - streaming_pull_future.cancel() - assert streaming_pull_future.done() + with SubscriberClient() as subscriber_client: + streaming_pull_future = subscriber_client.subscribe( + subscription_path, + callback=callback, + per_partition_flow_control_settings=per_partition_flow_control_settings, + ) + + print(f"Listening for messages on {str(subscription_path)}...") + + try: + streaming_pull_future.result(timeout=timeout) + except TimeoutError or KeyboardInterrupt: + streaming_pull_future.cancel() + assert streaming_pull_future.done() # [END pubsublite_quickstart_subscriber] From c33b25eba0f1b8d1beacdb275c258ba27a420bd7 Mon Sep 17 00:00:00 2001 From: Daniel Collins Date: Wed, 18 Nov 2020 15:12:19 -0500 Subject: [PATCH 3/3] fix: Enforce that __enter__ is called on all user interfaces before use --- .../cloudpubsub/publisher_client.py | 11 ++++++ .../cloudpubsub/subscriber_client.py | 11 ++++++ .../pubsublite/internal/require_started.py | 35 +++++++++++++++++++ samples/snippets/subscriber_example.py | 29 ++++++++------- 4 files changed, 71 insertions(+), 15 deletions(-) create mode 100644 google/cloud/pubsublite/internal/require_started.py diff --git a/google/cloud/pubsublite/cloudpubsub/publisher_client.py b/google/cloud/pubsublite/cloudpubsub/publisher_client.py index 2463d302..9ddd4da5 100644 --- a/google/cloud/pubsublite/cloudpubsub/publisher_client.py +++ b/google/cloud/pubsublite/cloudpubsub/publisher_client.py @@ -36,6 +36,7 @@ from google.cloud.pubsublite.internal.constructable_from_service_account import ( ConstructableFromServiceAccount, ) +from google.cloud.pubsublite.internal.require_started import RequireStarted from google.cloud.pubsublite.internal.wire.make_publisher import ( DEFAULT_BATCHING_SETTINGS as WIRE_DEFAULT_BATCHING, ) @@ -52,6 +53,7 @@ class PublisherClient(PublisherClientInterface, ConstructableFromServiceAccount) """ _impl: PublisherClientInterface + _require_stared: RequireStarted DEFAULT_BATCHING_SETTINGS = WIRE_DEFAULT_BATCHING """ @@ -83,6 +85,7 @@ def __init__( transport=transport, ) ) + self._require_stared = RequireStarted() @overrides def publish( @@ -92,18 +95,21 @@ def publish( ordering_key: str = "", **attrs: Mapping[str, str] ) -> "Future[str]": + self._require_stared.require_started() return self._impl.publish( topic=topic, data=data, ordering_key=ordering_key, **attrs ) @overrides def __enter__(self): + self._require_stared.__enter__() self._impl.__enter__() return self @overrides def __exit__(self, exc_type, exc_value, traceback): self._impl.__exit__(exc_type, exc_value, traceback) + self._require_stared.__exit__(exc_type, exc_value, traceback) class AsyncPublisherClient( @@ -117,6 +123,7 @@ class AsyncPublisherClient( """ _impl: AsyncPublisherClientInterface + _require_stared: RequireStarted DEFAULT_BATCHING_SETTINGS = WIRE_DEFAULT_BATCHING """ @@ -148,6 +155,7 @@ def __init__( transport=transport, ) ) + self._require_stared = RequireStarted() @overrides async def publish( @@ -157,15 +165,18 @@ async def publish( ordering_key: str = "", **attrs: Mapping[str, str] ) -> str: + self._require_stared.require_started() return await self._impl.publish( topic=topic, data=data, ordering_key=ordering_key, **attrs ) @overrides async def __aenter__(self): + self._require_stared.__enter__() await self._impl.__aenter__() return self @overrides async def __aexit__(self, exc_type, exc_value, traceback): await self._impl.__aexit__(exc_type, exc_value, traceback) + self._require_stared.__exit__(exc_type, exc_value, traceback) diff --git a/google/cloud/pubsublite/cloudpubsub/subscriber_client.py b/google/cloud/pubsublite/cloudpubsub/subscriber_client.py index 717369ef..96134938 100644 --- a/google/cloud/pubsublite/cloudpubsub/subscriber_client.py +++ b/google/cloud/pubsublite/cloudpubsub/subscriber_client.py @@ -39,6 +39,7 @@ from google.cloud.pubsublite.internal.constructable_from_service_account import ( ConstructableFromServiceAccount, ) +from google.cloud.pubsublite.internal.require_started import RequireStarted from google.cloud.pubsublite.types import ( FlowControlSettings, Partition, @@ -56,6 +57,7 @@ class SubscriberClient(SubscriberClientInterface, ConstructableFromServiceAccoun """ _impl: SubscriberClientInterface + _require_started: RequireStarted def __init__( self, @@ -92,6 +94,7 @@ def __init__( client_options=client_options, ), ) + self._require_started = RequireStarted() @overrides def subscribe( @@ -101,6 +104,7 @@ def subscribe( per_partition_flow_control_settings: FlowControlSettings, fixed_partitions: Optional[Set[Partition]] = None, ) -> StreamingPullFuture: + self._require_started.require_started() return self._impl.subscribe( subscription, callback, @@ -110,12 +114,14 @@ def subscribe( @overrides def __enter__(self): + self._require_started.__enter__() self._impl.__enter__() return self @overrides def __exit__(self, exc_type, exc_value, traceback): self._impl.__exit__(exc_type, exc_value, traceback) + self._require_started.__exit__(exc_type, exc_value, traceback) class AsyncSubscriberClient( @@ -130,6 +136,7 @@ class AsyncSubscriberClient( """ _impl: AsyncSubscriberClientInterface + _require_started: RequireStarted def __init__( self, @@ -161,6 +168,7 @@ def __init__( client_options=client_options, ) ) + self._require_started = RequireStarted() @overrides async def subscribe( @@ -169,15 +177,18 @@ async def subscribe( per_partition_flow_control_settings: FlowControlSettings, fixed_partitions: Optional[Set[Partition]] = None, ) -> AsyncIterator[Message]: + self._require_started.require_started() return await self._impl.subscribe( subscription, per_partition_flow_control_settings, fixed_partitions ) @overrides async def __aenter__(self): + self._require_started.__enter__() await self._impl.__aenter__() return self @overrides async def __aexit__(self, exc_type, exc_value, traceback): await self._impl.__aexit__(exc_type, exc_value, traceback) + self._require_started.__exit__(exc_type, exc_value, traceback) diff --git a/google/cloud/pubsublite/internal/require_started.py b/google/cloud/pubsublite/internal/require_started.py new file mode 100644 index 00000000..b7d4337b --- /dev/null +++ b/google/cloud/pubsublite/internal/require_started.py @@ -0,0 +1,35 @@ +# Copyright 2020 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. + +from typing import ContextManager + +from google.api_core.exceptions import FailedPrecondition + + +class RequireStarted(ContextManager): + def __init__(self): + self._started = False + + def __enter__(self): + if self._started: + raise FailedPrecondition("__enter__ called twice.") + self._started = True + return self + + def require_started(self): + if not self._started: + raise FailedPrecondition("__enter__ has never been called.") + + def __exit__(self, exc_type, exc_value, traceback): + self.require_started() diff --git a/samples/snippets/subscriber_example.py b/samples/snippets/subscriber_example.py index ed2fba41..a50c0f72 100644 --- a/samples/snippets/subscriber_example.py +++ b/samples/snippets/subscriber_example.py @@ -59,21 +59,20 @@ def callback(message): print(f"Received {message_data} of ordering key {message.ordering_key}.") message.ack() - subscriber_client = SubscriberClient() - - streaming_pull_future = subscriber_client.subscribe( - subscription_path, - callback=callback, - per_partition_flow_control_settings=per_partition_flow_control_settings, - ) - - print(f"Listening for messages on {str(subscription_path)}...") - - try: - streaming_pull_future.result(timeout=timeout) - except TimeoutError or KeyboardInterrupt: - streaming_pull_future.cancel() - assert streaming_pull_future.done() + with SubscriberClient() as subscriber_client: + streaming_pull_future = subscriber_client.subscribe( + subscription_path, + callback=callback, + per_partition_flow_control_settings=per_partition_flow_control_settings, + ) + + print(f"Listening for messages on {str(subscription_path)}...") + + try: + streaming_pull_future.result(timeout=timeout) + except TimeoutError or KeyboardInterrupt: + streaming_pull_future.cancel() + assert streaming_pull_future.done() # [END pubsublite_quickstart_subscriber]