
    O                     *   S SK Jr  S SKrS SKrS SKrS SKrS SKrS SKrS SKJrJ	r	J
r
JrJrJrJr  S SKrS SKJr  S SKJr  S SKJr  S SKJr  S SKJr  S S	KJr  S S
KJr  S SKJr  S SKJr  S SK J!r!  S SK"J#r$  S SK"Jr%  S SK&J'r(  \$RR                  r)\RT                  (       a  S SK+J,r,  S SKJ-r-  S SK.J/r/  S SK0J1r2  \Rf                  " \45      r5\%Rl                  Ro                  5       r8\\Rr                  \Rt                  4   r; " S S\(Rx                  5      r=g)    )absolute_importN)AnyDictOptionalSequenceTupleTypeUnion)gapic_v1)AnonymousCredentials)service_account)types)
exceptions)futures)thread)ordered_sequencer)unordered_sequencer)FlowController)gapic_version)client)	pubsub_v1)_batch)OptionalRetry)pubsubc                   N  ^  \ rS rSrSr  S)S\\R                  \4   S\\R                  \4   S\
4U 4S jjjr\ S*S\S\\R                  \4   S\
SS 4S	 jj5       r\r\S\4S
 j5       r\U 4S j5       rS\S\S\4S jrS\S\SS4S jrS+U 4S jjrS\R0                  R2                  \R0                  R2                  4S\S\S\SSSSS\\\4   SS4S jjrS,S jrS,S jrS,S jrS,S jrS,S jr S,S  jr! S-S\S!S"S\SS4S# jjr"S$\#SS4S% jr$ S-S\S&\S\SS4S' jjr%S(r&U =r'$ ).Client<   a)  A publisher client for Google Cloud Pub/Sub.

This creates an object that is capable of publishing messages.
Generally, you can instantiate this client with no arguments, and you
get sensible defaults.

Args:
    batch_settings:
        The settings for batch publishing.
    publisher_options:
        The options for the publisher client. Note that enabling message ordering
        will override the publish retry timeout to be infinite.
    kwargs:
        Any additional arguments provided are sent as keyword arguments to the
        underlying
        :class:`~google.cloud.pubsub_v1.gapic.publisher_client.PublisherClient`.
        Generally you should not need to set additional keyword
        arguments. Regional endpoints can be set via ``client_options`` that
        takes a single key-value pair that defines the endpoint.

Example:

.. code-block:: python

    from google.cloud import pubsub_v1

    publisher_client = pubsub_v1.PublisherClient(
        # Optional
        batch_settings = pubsub_v1.types.BatchSettings(
            max_bytes=1024,  # One kilobyte
            max_latency=1,   # One second
        ),

        # Optional
        publisher_options = pubsub_v1.types.PublisherOptions(
            enable_message_ordering=False,
            flow_control=pubsub_v1.types.PublishFlowControl(
                message_limit=2000,
                limit_exceeded_behavior=pubsub_v1.types.LimitExceededBehavior.BLOCK,
            ),
        ),

        # Optional
        client_options = {
            "api_endpoint": REGIONAL_ENDPOINT
        }
    )
batch_settingspublisher_optionskwargsc                 0  > [        U5      [        R                  L d  [        U5      S:X  d   S5       e[        U5      [        R                  L d  [        U5      S:X  d   S5       e[
        R                  R                  S5      (       a1  S[
        R                  R                  S5      0US'   [        5       US'   [        R                  " U6 U l	        U R                  S   U l
        [        TU ]0  " S	0 UD6  U R                  R                  U l        [         R"                  U l        [        R                  " U6 U l        U R$                  R)                  5       U l        0 U l        SU l        S U l        [3        U R                  R4                  5      U l        g )
Nr   zBbatch_settings must be of type BatchSettings or an empty sequence.zHpublisher_options must be of type PublisherOptions or an empty sequence.PUBSUB_EMULATOR_HOSTapi_endpointclient_optionscredentialsF )typer   BatchSettingslenPublisherOptionsosenvirongetr   r   _enable_message_orderingsuper__init__
_transport_host_targetr   Batch_batch_classr   	make_lock_batch_lock_sequencers_is_stopped_commit_threadr   flow_control_flow_controller)selfr   r   r    	__class__s       :lib/third_party/google/cloud/pubsub_v1/publisher/client.pyr0   Client.__init__n   sn     E$7$773~;NRS;S	PO	PS "#u'='==$%*	V V	V+ ::>>011

/E F(F#$ %9$:F=! "'!7!79J!K(,(>(>q(A% 	"6",,"LL#11>B  ,,668AC :> !/t/E/E/R/R S    filenamereturnc                 Z    [         R                  R                  U5      nXCS'   U " U40 UD6$ )ac  Creates an instance of this client using the provided credentials
file.

Args:
    filename:
        The path to the service account private key JSON file.
    batch_settings:
        The settings for batch publishing.
    kwargs:
        Additional arguments to pass to the constructor.

Returns:
    A Publisher instance that is the constructed client.
r%   )r   Credentialsfrom_service_account_file)clsrB   r   r    r%   s        r?   rF    Client.from_service_account_file   s2    * &11KKHU +}>,V,,rA   c                     U R                   $ )zMReturn the target (where the API is).

Returns:
    The location of the API.
)r3   r=   s    r?   targetClient.target   s     ||rA   c                 N   > Sn[         R                  " U[        S9  [        5       $ )aO  The underlying gapic API client.

.. versionchanged:: 2.10.0
    Instead of a GAPIC ``PublisherClient`` client instance, this property is a
    proxy object to it with the same interface.

.. deprecated:: 2.10.0
    Use the GAPIC methods and properties on the client instance directly
    instead of through the :attr:`api` attribute.
zThe "api" property only exists for backward compatibility, access its attributes directly thorugh the client instance (e.g. "client.foo" instead of "client.api.foo").)category)warningswarnDeprecationWarningr/   )r=   msgr>   s     r?   api
Client.api   s%    , 	
 	c$67wrA   topicordering_keyc                     X4nU R                   R                  U5      nUcB  US:X  a  [        R                  " X5      nO[        R
                  " XU5      nX@R                   U'   U$ )zTGet an existing sequencer or create a new one given the (topic,
ordering_key) pair.
 )r8   r-   r   UnorderedSequencerr   OrderedSequencerr=   rU   rV   sequencer_key	sequencers        r?   _get_or_create_sequencerClient._get_or_create_sequencer   sk     -$$((7	r!/BB4O	->>	 /8]+rA   Nc                 N   U R                      U R                  (       a  [        S5      eU R                  (       d  [	        S5      eX4nU R
                  R                  U5      nUc  [        R                  S5        OUR                  5         SSS5        g! , (       d  f       g= f)a  Resume publish on an ordering key that has had unrecoverable errors.

Args:
    topic: The topic to publish messages to.
    ordering_key: A string that identifies related messages for which
        publish order should be respected.

Raises:
    RuntimeError:
        If called after publisher has been stopped by a `stop()` method
        call.
    ValueError:
        If the topic/ordering key combination has not been seen before
        by this client.
z-Cannot resume publish on a stopped publisher.zICannot resume publish on a topic/ordering key if ordering is not enabled.NzCError: The topic/ordering key combination has not been seen before.)
r7   r9   RuntimeErrorr.   
ValueErrorr8   r-   _LOGGERdebugunpauser[   s        r?   resume_publishClient.resume_publish   s      "#RSS00 & 
 #1M((,,];I (
 !!#% s   B B
B$c                 $   > [         TU ]  " U0 UD6$ )z#Call the GAPIC public API directly.)r/   publish)r=   argsr    r>   s      r?   _gapic_publishClient._gapic_publish	  s    w///rA   rX   dataretryr   timeoutztypes.OptionalTimeoutattrsz"pubsub_v1.publisher.futures.Futurec                 |  ^ ^ [        U[        5      (       d  [        S5      eT R                  (       d  US:w  a  [	        S5      e[
        R
                  " U5      R                  5        HO  u  px[        U[        5      (       a  M  [        U[        5      (       a  UR                  S5      Xg'   MF  [        S5      e   [        X#US9n	[        R                  R                  U	5      m T R                  R                  T5        UU 4S jnU[(        R*                  R,                  L a  T R.                  R0                  nU[(        R*                  R,                  L a  T R.                  R2                  nT R4                     T R6                  (       a  [9        S	5      eT R                  (       ao  U[(        R*                  R,                  L aA  T R:                  nUR<                  UR>                     R@                  nURC                  S
5      nOURC                  S
5      nT RE                  X5      nUR?                  TXES9nURG                  U5        T RI                  5         UsSSS5        $ ! [        R                    a2  n
["        R$                  " 5       nUR'                  U
5        Us Sn
A
$ Sn
A
ff = f! , (       d  f       g= f)a	  Publish a single message.

.. note::
    Messages in Pub/Sub are blobs of bytes. They are *binary* data,
    not text. You must send data as a bytestring
    (``bytes`` in Python 3; ``str`` in Python 2), and this library
    will raise an exception if you send a text string.

    The reason that this is so important (and why we do not try to
    coerce for you) is because Pub/Sub is also platform independent
    and there is no way to know how to decode messages properly on
    the other side; therefore, encoding and decoding is a required
    exercise for the developer.

Add the given message to this object; this will cause it to be
published once the batch either has enough messages or a sufficient
period of time has elapsed.
This method may block if LimitExceededBehavior.BLOCK is used in the
flow control settings.

Example:
    >>> from google.cloud import pubsub_v1
    >>> client = pubsub_v1.PublisherClient()
    >>> topic = client.topic_path('[PROJECT]', '[TOPIC]')
    >>> data = b'The rain in Wales falls mainly on the snails.'
    >>> response = client.publish(topic, data, username='guido')

Args:
    topic: The topic to publish messages to.
    data: A bytestring representing the message body. This
        must be a bytestring.
    ordering_key: A string that identifies related messages for which
        publish order should be respected. Message ordering must be
        enabled for this client to use this feature.
    retry:
        Designation of what errors, if any, should be retried. If `ordering_key`
        is specified, the total retry deadline will be changed to "infinity".
        If given, it overides any retry passed into the client through
        the ``publisher_options`` argument.
    timeout:
        The timeout for the RPC request. Can be used to override any timeout
        passed in through ``publisher_options`` when instantiating the client.

    attrs: A dictionary of attributes to be
        sent as metadata. (These may be text strings or byte strings.)

Returns:
    A :class:`~google.cloud.pubsub_v1.publisher.futures.Future`
    instance that conforms to Python Standard library's
    :class:`~concurrent.futures.Future` interface (but not an
    instance of that class).

Raises:
    RuntimeError:
        If called after publisher has been stopped by a `stop()` method
        call.

    pubsub_v1.publisher.exceptions.MessageTooLargeError: If publishing
        the ``message`` would exceed the max size limit on the backend.
z=Data being published to Pub/Sub must be sent as a bytestring.rX   zSCannot publish a message with an ordering key when message ordering is not enabled.zutf-8zGAll attributes being published to Pub/Sub must be sent as text strings.)rm   rV   
attributesNc                 <   > TR                   R                  T5        g N)r<   release)futuremessager=   s    r?   on_publish_done'Client.publish.<locals>.on_publish_done|  s    !!))'2rA   z&Cannot publish on a stopped publisher.g      A)rn   ro   )%
isinstancebytes	TypeErrorr.   rb   copyitemsstrdecode_raw_proto_pubbsub_messagegapic_typesPubsubMessagewrapr<   addr   FlowControlLimitErrorr   Futureset_exceptionr   methodDEFAULTr   rn   ro   r7   r9   ra   r1   _wrapped_methodsri   _retrywith_deadliner^   add_done_callback!_ensure_commit_timer_runs_no_lock)r=   rU   rm   rV   rn   ro   rp   kv
vanilla_pbexcrv   rx   	transport
base_retryr]   rw   s   `               @r?   ri   Client.publish  sF   N $&&O  ,,1C+  IIe$**,DA!S!!!U##88G,+  - 0U

 ++00<	!!%%g.	3 HOO+++**00Ehoo---,,44G"#KLL
 ,,HOO333 $I!*!;!;I<M<M!N!U!UJ&44W=E!//8E 55eJI&&we&MF$$_5 2243  // 	^^%F  %M	 s+   &I$ :C J-$J*8'J%J*%J*-
J;c                 p    U R                      U R                  5         SSS5        g! , (       d  f       g= f)zzEnsure a cleanup/commit timer thread is running.

If a cleanup/commit timer thread is already running, this does nothing.
N)r7   r   rJ   s    r?   $ensure_cleanup_and_commit_timer_runs+Client.ensure_cleanup_and_commit_timer_runs  s%    
 224 s   '
5c                     U R                   (       d5  U R                  R                  [        S5      :  a  U R	                  5         ggg)z{Ensure a commit timer thread is running, without taking
_batch_lock.

_batch_lock must be held before calling this method.
infN)r:   r   max_latencyfloat_start_commit_threadrJ   s    r?   r   (Client._ensure_commit_timer_runs_no_lock  s9     ""t':':'F'Fu'U%%' (V"rA   c                     [         R                  " SU R                  SS9U l        U R                  R	                  5         g)z>Start a new thread to actually wait and commit the sequencers.zThread-PubSubBatchCommitterT)namerK   daemonN)	threadingThread_wait_and_commit_sequencersr:   startrJ   s    r?   r   Client._start_commit_thread  s:    
 (...33

 	!!#rA   c                 2   [         R                  " U R                  R                  5        [        R                  S5        U R                     U R                  (       a
   SSS5        gU R                  5         SU l	        SSS5        g! , (       d  f       g= f)z;Wait up to the batching timeout, and commit all sequencers.zCommit thread is waking upN)
timesleepr   r   rc   rd   r7   r9   _commit_sequencersr:   rJ   s    r?   r   "Client._wait_and_commit_sequencers  sh     	

4&&22323  ##%"&D	 s   B(B
Bc                 (   U R                   R                  5        VVs/ s H  u  pUR                  5       (       d  M  UPM      nnnU H  nU R                   U	 M     U R                   R                  5        H  nUR	                  5         M     gs  snnf )z1Clean up finished sequencers and commit the rest.N)r8   r~   is_finishedvaluescommit)r=   keyr]   finished_sequencer_keysr\   s        r?   r   Client._commit_sequencers  s     #'"2"2"8"8":#
":$$& ": 	  #

 5M  / 5 ))002I 3#
s
   BBc                     U R                      U R                  (       a  [        S5      eSU l        U R                  R	                  5        H  nUR                  5         M     SSS5        g! , (       d  f       g= f)a  Immediately publish all outstanding messages.

Asynchronously sends all outstanding messages and
prevents future calls to `publish()`. Method should
be invoked prior to deleting this `Client()` object
in order to ensure that no pending messages are lost.

.. note::

    This method is non-blocking. Use `Future()` objects
    returned by `publish()` to make sure all publish
    requests completed, either in success or error.

Raises:
    RuntimeError:
        If called after publisher has been stopped by a `stop()` method
        call.
z(Cannot stop a publisher already stopped.TN)r7   r9   ra   r8   r   stop)r=   r]   s     r?   r   Client.stop  sY    & "#MNN#D!--446	  7 s   AA++
A9batchz_batch.thread.Batchc                 H    U R                  X5      nUR                  U5        g rt   )r^   
_set_batch)r=   rU   r   rV   r]   s        r?   r   Client._set_batch  s"     11%F	U#rA   batch_classc                     Xl         g rt   )r5   )r=   r   s     r?   _set_batch_classClient._set_batch_class  s    'rA   r]   c                 &    X4nX R                   U'   g rt   )r8   )r=   rU   r]   rV   r\   s        r?   _set_sequencerClient._set_sequencer  s     -*3'rA   )
r5   r7   r:   r.   r<   r9   r8   r3   r   r   )r&   r&   )r&   )rC   zpubsub_types.PublishResponse)rC   N)rX   )(__name__
__module____qualname____firstlineno____doc__r
   r   r(   r   r*   r   r0   classmethodr   rF   from_service_account_jsonpropertyrK   rS   SequencerTyper^   rf   rk   r   r   r   r{   ri   r   r   r   r   r   r   r   r	   r   r   __static_attributes____classcell__)r>   s   @r?   r   r   <   s'   /f @BEG,Te118;<,T !!7!7!AB,T 	,T ,T\  @B-- e118;<- 	-
 
- -0 !:    &c   ""$C "$s "$t "$H0 !)!8!8+3??+B+BQQ Q 	Q
 Q )Q ucz"Q 
.Qf5(
$
'!< MO$$!6$FI$	$(D (T (
 IK44%24BE4	4 4rA   r   )>
__future__r   r}   loggingr+   r   r   typingr   r   r   r   r   r	   r
   rO   google.api_corer   google.auth.credentialsr   google.oauth2r   google.cloud.pubsub_v1r    google.cloud.pubsub_v1.publisherr   r   'google.cloud.pubsub_v1.publisher._batchr   +google.cloud.pubsub_v1.publisher._sequencerr   r   0google.cloud.pubsub_v1.publisher.flow_controllerr   google.pubsub_v1r   package_versionr   #google.pubsub_v1.services.publisherr   publisher_client__version__TYPE_CHECKINGgoogle.cloudr   r   *google.pubsub_v1.services.publisher.clientr   google.pubsub_v1.typesr   pubsub_types	getLoggerr   rc   r   pbr   rZ   rY   r   PublisherClientr   r&   rA   r?   <module>r      s    '   	    D D D  $ 8 ) ( 7 4 : I K K = 1 J))	&7H= 

H
% )6699; &&(;(N(NN
F4-- F4rA   