2222import time
2323import typing
2424from typing import Any , Dict , Optional , Sequence , Tuple , Type , Union
25+ import warnings
2526
2627from google .api_core import gapic_v1
2728from google .auth .credentials import AnonymousCredentials # type: ignore
2829from google .oauth2 import service_account # type: ignore
2930
30- from google .cloud .pubsub_v1 import _gapic
3131from google .cloud .pubsub_v1 import types
3232from google .cloud .pubsub_v1 .publisher import exceptions
3333from google .cloud .pubsub_v1 .publisher import futures
4949 from google .cloud import pubsub_v1
5050 from google .cloud .pubsub_v1 .publisher import _batch
5151 from google .pubsub_v1 .services .publisher .client import OptionalRetry
52+ from google .pubsub_v1 .types import pubsub as pubsub_types
5253
5354
5455_LOGGER = logging .getLogger (__name__ )
5556
56- _DENYLISTED_METHODS = (
57- "publish" ,
58- "from_service_account_file" ,
59- "from_service_account_json" ,
60- )
6157
6258_raw_proto_pubbsub_message = gapic_types .PubsubMessage .pb ()
6359
6662]
6763
6864
69- @_gapic .add_methods (publisher_client .PublisherClient , denylist = _DENYLISTED_METHODS )
70- class Client (object ):
65+ class Client (publisher_client .PublisherClient ):
7166 """A publisher client for Google Cloud Pub/Sub.
7267
7368 This creates an object that is capable of publishing messages.
@@ -146,8 +141,8 @@ def __init__(
146141
147142 # Add the metrics headers, and instantiate the underlying GAPIC
148143 # client.
149- self . api = publisher_client . PublisherClient (** kwargs )
150- self ._target = self .api . _transport ._host
144+ super (). __init__ (** kwargs )
145+ self ._target = self ._transport ._host
151146 self ._batch_class = thread .Batch
152147 self .batch_settings = types .BatchSettings (* batch_settings )
153148
@@ -164,7 +159,7 @@ def __init__(
164159 self ._flow_controller = FlowController (self .publisher_options .flow_control )
165160
166161 @classmethod
167- def from_service_account_file (
162+ def from_service_account_file ( # type: ignore[override]
168163 cls ,
169164 filename : str ,
170165 batch_settings : Union [types .BatchSettings , Sequence ] = (),
@@ -188,7 +183,7 @@ def from_service_account_file(
188183 kwargs ["credentials" ] = credentials
189184 return cls (batch_settings , ** kwargs )
190185
191- from_service_account_json = from_service_account_file
186+ from_service_account_json = from_service_account_file # type: ignore[assignment]
192187
193188 @property
194189 def target (self ) -> str :
@@ -199,6 +194,26 @@ def target(self) -> str:
199194 """
200195 return self ._target
201196
197+ @property
198+ def api (self ):
199+ """The underlying gapic API client.
200+
201+ .. versionchanged:: 2.10.0
202+ Instead of a GAPIC ``PublisherClient`` client instance, this property is a
203+ proxy object to it with the same interface.
204+
205+ .. deprecated:: 2.10.0
206+ Use the GAPIC methods and properties on the client instance directly
207+ instead of through the :attr:`api` attribute.
208+ """
209+ msg = (
210+ 'The "api" property only exists for backward compatibility, access its '
211+ 'attributes directly thorugh the client instance (e.g. "client.foo" '
212+ 'instead of "client.api.foo").'
213+ )
214+ warnings .warn (msg , category = DeprecationWarning )
215+ return super ()
216+
202217 def _get_or_create_sequencer (self , topic : str , ordering_key : str ) -> SequencerType :
203218 """ Get an existing sequencer or create a new one given the (topic,
204219 ordering_key) pair.
@@ -252,7 +267,11 @@ def resume_publish(self, topic: str, ordering_key: str) -> None:
252267 else :
253268 sequencer .unpause ()
254269
255- def publish (
270+ def _gapic_publish (self , * args , ** kwargs ) -> "pubsub_types.PublishResponse" :
271+ """Call the GAPIC public API directly."""
272+ return super ().publish (* args , ** kwargs )
273+
274+ def publish ( # type: ignore[override]
256275 self ,
257276 topic : str ,
258277 data : bytes ,
@@ -382,7 +401,7 @@ def on_publish_done(future):
382401 if self ._enable_message_ordering :
383402 if retry is gapic_v1 .method .DEFAULT :
384403 # use the default retry for the publish GRPC method as a base
385- transport = self .api . _transport
404+ transport = self ._transport
386405 base_retry = transport ._wrapped_methods [transport .publish ]._retry
387406 retry = base_retry .with_deadline (2.0 ** 32 )
388407 else :
0 commit comments