
    M                     B   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JrJ	r	  S SK
Jr  S SKJr  S SKJr  \R                   (       a  S SKrS SKrS SKJr  S SKJr  S	r\R.                  " 5       r\R3                  \R4                  5        SS
\S\S\4S jjr " S S\5      rg)    )absolute_importN)OptionalCallable)requests)futures)AcknowledgeStatus)types)
containersz@Message {{
  data: {!r}
  ordering_key: {!r}
  attributes: {}
}}linesprefixreturnc                 ~    / nU R                  S5       H  nUR                  X-   5        M     SR                  U5      $ )a  Indent some text.

Note that this is present as ``textwrap.indent``, but not in Python 2.

Args:
    lines:
        The newline delimited string to be indented.
    prefix:
        The prefix to indent each line with. Defaults to two spaces.

Returns:
    The newly indented content.

)splitappendjoin)r   r   indentedlines       <lib/third_party/google/cloud/pubsub_v1/subscriber/message.py_indentr   /   s9     HD!& "99X    c                   J   \ rS rSrSrS 4SSS\S\SS	S
\/ \4   4
S jjr	S r
\S S j5       r\S\4S j5       r\S!S j5       r\S\4S j5       r\S\4S j5       r\S\4S j5       r\S\\   4S j5       rS"S jrS#S jrS"S jrS\SS4S jrS\SS4S jrS"S jrS#S jrSrg)$MessageC   ax  A representation of a single Pub/Sub message.

The common way to interact with
:class:`~.pubsub_v1.subscriber.message.Message` objects is to receive
them in callbacks on subscriptions; most users should never have a need
to instantiate them by hand. (The exception to this is if you are
implementing a custom subclass to
:class:`~.pubsub_v1.subscriber._consumer.Consumer`.)

Attributes:
    message_id (str):
        The message ID. In general, you should not need to use this directly.
    data (bytes):
        The data in the message. Note that this will be a :class:`bytes`,
        not a text string.
    attributes (MutableMapping[str, str]):
        The attributes sent along with the message. See :attr:`attributes` for more
        information on this type.
    publish_time (google.protobuf.timestamp_pb2.Timestamp):
        The time that this message was originally published.
c                      g)NF r   r   r   <lambda>Message.<lambda>`   s    r   messageztypes.PubsubMessage._meta._pback_iddelivery_attemptrequest_queuezqueue.Queue"exactly_once_delivery_enabled_funcc                 
   Xl         X l        US:  a  UOSU l        X@l        XPl        UR
                  U l        [        R                  " 5       U l        UR                  U l	        UR                  U l        [        R                  R                  UR                  R                   UR                  R"                  S-  -   [        R$                  R&                  S9U l        UR*                  U l        UR/                  5       U l        g)a\  Construct the Message.

.. note::

    This class should not be constructed directly; it is the
    responsibility of :class:`BasePolicy` subclasses to do so.

Args:
    message (types.PubsubMessage._meta._pb):
        The message received from Pub/Sub. For performance reasons it should be
        the raw protobuf message normally wrapped by
        :class:`~pubsub_v1.types.PubsubMessage`. A raw message can be obtained
        from a  :class:`~pubsub_v1.types.PubsubMessage` instance through the
        latter's ``._pb`` attribute.
    ack_id (str):
        The ack_id received from Pub/Sub.
    delivery_attempt (int):
        The delivery attempt counter received from Pub/Sub if a DeadLetterPolicy
        is set on the subscription, and zero otherwise.
    request_queue (queue.Queue):
        A queue provided by the policy that can accept requests; the policy is
        responsible for handling those requests.
    exactly_once_delivery_enabled_func (Callable[[], bool]):
        A Callable that returns whether exactly-once delivery is currently-enabled. Defaults to a lambda that always returns False.
r   Ng    eA)tz)_message_ack_id_delivery_attempt_request_queue#_exactly_once_delivery_enabled_func
message_idtime_received_timestamp
attributes_attributesdata_datadtdatetimefromtimestamppublish_timesecondsnanostimezoneutc_publish_timeordering_key_ordering_keyByteSize_size)selfr   r    r!   r"   r#   s         r   __init__Message.__init__Z   s    B  5E5I!1t+3U0!,,
 $(99; 
 #--\\
[[66  ((7+?+?+E+E+KK{{ 7 
 %11%%'
r   c                 :   U R                   R                  n[        U5      S:  a  US S S-   n[        R                  " [        U R                  5      SSSS9n[        U5      nUR                  5       n[        R                  U[        U R                  5      U5      $ )N2   s   ...   ),z: T)indent
separators	sort_keys)r&   r0   lenjsondumpsdictr.   r   lstrip_MESSAGE_REPRformatstrr;   )r?   	abbv_datapretty_attrss      r   __repr__Message.__repr__   s    MM&&	y>B!#2/Izz!!t
 |,#**,##Is43D3D/E|TTr   r   c                     U R                   $ )aX  Return the attributes of the underlying Pub/Sub Message.

.. warning::

    A ``ScalarMap`` behaves slightly differently than a
    ``dict``. For a Pub / Sub message this is a ``string->string`` map.
    When trying to access a value via ``map['key']``, if the key is
    not in the map, then the default value for the string type will
    be returned, which is an empty string. It may be more intuitive
    to just cast the map to a ``dict`` or to one use ``map.get``.

Returns:
    containers.ScalarMap: The message's attributes. This is a
    ``dict``-like object provided by ``google.protobuf``.
)r/   r?   s    r   r.   Message.attributes   s    " r   c                     U R                   $ )zReturn the data for the underlying Pub/Sub Message.

Returns:
    bytes: The message data. This is always a bytestring; if you want
    a text string, call :meth:`bytes.decode`.
)r1   rV   s    r   r0   Message.data   s     zzr   c                     U R                   $ )zReturn the time that the message was originally published.

Returns:
    datetime.datetime: The date and time that the message was
    published.
)r:   rV   s    r   r5   Message.publish_time   s     !!!r   c                     U R                   $ )z-The ordering key used to publish the message.)r<   rV   s    r   r;   Message.ordering_key   s     !!!r   c                     U R                   $ )z4Return the size of the underlying message, in bytes.)r>   rV   s    r   sizeMessage.size   s     zzr   c                     U R                   $ )zthe ID used to ack the message.)r'   rV   s    r   r    Message.ack_id   s     ||r   c                     U R                   $ )a  The delivery attempt counter is 1 + (the sum of number of NACKs
and number of ack_deadline exceeds) for this message. It is set to None
if a DeadLetterPolicy is not set on the subscription.

A NACK is any call to ModifyAckDeadline with a 0 deadline. An ack_deadline
exceeds event is whenever a message is not acknowledged within
ack_deadline. Note that ack_deadline is initially
Subscription.ackDeadlineSeconds, but may get extended automatically by
the client library.

The first delivery of a given message will have this value as 1. The value
is calculated at best effort and is approximate.

Returns:
    Optional[int]: The delivery attempt counter or ``None``.
)r(   rV   s    r   r!   Message.delivery_attempt   s    $ %%%r   Nc           
         [         R                  " [        R                  " 5       U R                  -
  5      nU R                  R                  [        R                  " U R                  U R                  UU R                  SS95        g)a  Acknowledge the given message.

Acknowledging a message in Pub/Sub means that you are done
with it, and it will not be delivered to this subscription again.
You should avoid acknowledging messages until you have
*finished* processing them, so that in the event of a failure,
you receive the message again.

.. warning::
    Acks in Pub/Sub are best effort. You should always
    ensure that your processing code is idempotent, as you may
    receive any given message more than once. If you need strong
    guarantees about acks and re-deliveres, enable exactly-once
    delivery on your subscription and use the `ack_with_response`
    method instead. Exactly once delivery is a preview feature.
    For more details, see:
    https://cloud.google.com/pubsub/docs/exactly-once-delivery."

Nr    	byte_sizetime_to_ackr;   future)mathceilr,   r-   r)   putr   
AckRequestr'   r_   r;   )r?   rh   s     r   ackMessage.ack   sb    ( ii		d.F.F FG||))'!..	
r   futures.Futurec           
      z   U R                  5       (       a  [        R                  " 5       nUnO[        nSn[        R
                  " [        R                  " 5       U R                  -
  5      nU R                  R                  [        R                  " U R                  U R                  UU R                  US95        U$ )a  Acknowledge the given message.

Acknowledging a message in Pub/Sub means that you are done
with it, and it will not be delivered to this subscription again.
You should avoid acknowledging messages until you have
*finished* processing them, so that in the event of a failure,
you receive the message again.

If exactly-once delivery is NOT enabled on the subscription, the
future returns immediately with an AcknowledgeStatus.SUCCESS.
Since acks in Cloud Pub/Sub are best effort when exactly-once
delivery is disabled, the message may be re-delivered. Because
re-deliveries are possible, you should ensure that your processing
code is idempotent, as you may receive any given message more than
once.

If exactly-once delivery is enabled on the subscription, the
future returned by this method tracks the state of acknowledgement
operation. If the future completes successfully, the message is
guaranteed NOT to be re-delivered. Otherwise, the future will
contain an exception with more details about the failure and the
message may be re-delivered.

Exactly once delivery is a preview feature. For more details,
see https://cloud.google.com/pubsub/docs/exactly-once-delivery."

Returns:
    futures.Future: A
    :class:`~google.cloud.pubsub_v1.subscriber.futures.Future`
    instance that conforms to Python Standard library's
    :class:`~concurrent.futures.Future` interface (but not an
    instance of that class). Call `result()` to get the result
    of the operation; upon success, a
    pubsub_v1.subscriber.exceptions.AcknowledgeStatus.SUCCESS
    will be returned and upon an error, an
    pubsub_v1.subscriber.exceptions.AcknowledgeError exception
    will be thrown.
Nrf   )r*   r   Future_SUCCESS_FUTURErj   rk   r,   r-   r)   rl   r   rm   r'   r_   r;   )r?   ri   
req_futurerh   s       r   ack_with_responseMessage.ack_with_response
  s    P 3355^^%FJ$FJii		d.F.F FG||))'!..!	
 r   c                     U R                   R                  [        R                  " U R                  U R
                  U R                  S95        g)a  Release the message from lease management.

This informs the policy to no longer hold on to the lease for this
message. Pub/Sub will re-deliver the message if it is not acknowledged
before the existing lease expires.

.. warning::
    For most use cases, the only reason to drop a message from
    lease management is on `ack` or `nack`; this library
    automatically drop()s the message on `ack` or `nack`. You probably
    do not want to call this method directly.
)r    rg   r;   N)r)   rl   r   DropRequestr'   r_   r;   rV   s    r   dropMessage.dropD  s;     	  ||tyytGXGX	
r   r6   c                 v    U R                   R                  [        R                  " U R                  USS95        g)a>  Resets the deadline for acknowledgement.

New deadline will be the given value of seconds from now.

The default implementation handles automatically modacking received messages for you;
you should not need to manually deal with setting ack deadlines. The exception case is
if you are implementing your own custom subclass of
:class:`~.pubsub_v1.subcriber._consumer.Consumer`.

Args:
    seconds (int):
        The number of seconds to set the lease deadline to. This should be
        between 0 and 600. Due to network latency, values below 10 are advised
        against.
Nr    r6   ri   )r)   rl   r   ModAckRequestr'   )r?   r6   s     r   modify_ack_deadlineMessage.modify_ack_deadlineW  s/      	""$,,PTU	
r   c                     U R                  5       (       a  [        R                  " 5       nUnO[        nSnU R                  R                  [        R                  " U R                  XS95        U$ )a  Resets the deadline for acknowledgement and returns the response
status via a future.

New deadline will be the given value of seconds from now.

The default implementation handles automatically modacking received messages for you;
you should not need to manually deal with setting ack deadlines. The exception case is
if you are implementing your own custom subclass of
:class:`~.pubsub_v1.subcriber._consumer.Consumer`.

If exactly-once delivery is NOT enabled on the subscription, the
future returns immediately with an AcknowledgeStatus.SUCCESS.
Since modify-ack-deadline operations in Cloud Pub/Sub are best effort
when exactly-once delivery is disabled, the message may be re-delivered
within the set deadline.

If exactly-once delivery is enabled on the subscription, the
future returned by this method tracks the state of the
modify-ack-deadline operation. If the future completes successfully,
the message is guaranteed NOT to be re-delivered within the new deadline.
Otherwise, the future will contain an exception with more details about
the failure and the message will be redelivered according to its
currently-set ack deadline.

Exactly once delivery is a preview feature. For more details,
see https://cloud.google.com/pubsub/docs/exactly-once-delivery."

Args:
    seconds (int):
        The number of seconds to set the lease deadline to. This should be
        between 0 and 600. Due to network latency, values below 10 are advised
        against.
Returns:
    futures.Future: A
    :class:`~google.cloud.pubsub_v1.subscriber.futures.Future`
    instance that conforms to Python Standard library's
    :class:`~concurrent.futures.Future` interface (but not an
    instance of that class). Call `result()` to get the result
    of the operation; upon success, a
    pubsub_v1.subscriber.exceptions.AcknowledgeStatus.SUCCESS
    will be returned and upon an error, an
    pubsub_v1.subscriber.exceptions.AcknowledgeError exception
    will be thrown.

Nr|   )	r*   r   rr   rs   r)   rl   r   r}   r'   )r?   r6   ri   rt   s       r   !modify_ack_deadline_with_response)Message.modify_ack_deadline_with_responsek  sa    ^ 3355^^%FJ$FJ""||W	
 r   c           	          U R                   R                  [        R                  " U R                  U R
                  U R                  SS95        g)zDecline to acknowledge the given message.

This will cause the message to be re-delivered to subscribers. Re-deliveries
may take place immediately or after a delay, and may arrive at this subscriber
or another.
Nr    rg   r;   ri   )r)   rl   r   NackRequestr'   r_   r;   rV   s    r   nackMessage.nack  s@     	  ||))!..		
r   c           	         U R                  5       (       a  [        R                  " 5       nUnO[        nSnU R                  R                  [        R                  " U R                  U R                  U R                  US95        U$ )a0  Decline to acknowledge the given message, returning the response status via
a future.

This will cause the message to be re-delivered to subscribers. Re-deliveries
may take place immediately or after a delay, and may arrive at this subscriber
or another.

If exactly-once delivery is NOT enabled on the subscription, the
future returns immediately with an AcknowledgeStatus.SUCCESS.

If exactly-once delivery is enabled on the subscription, the
future returned by this method tracks the state of the
nack operation. If the future completes successfully,
the future's result will be an AcknowledgeStatus.SUCCESS.
Otherwise, the future will contain an exception with more details about
the failure.

Exactly once delivery is a preview feature. For more details,
see https://cloud.google.com/pubsub/docs/exactly-once-delivery."

Returns:
    futures.Future: A
    :class:`~google.cloud.pubsub_v1.subscriber.futures.Future`
    instance that conforms to Python Standard library's
    :class:`~concurrent.futures.Future` interface (but not an
    instance of that class). Call `result()` to get the result
    of the operation; upon success, a
    pubsub_v1.subscriber.exceptions.AcknowledgeStatus.SUCCESS
    will be returned and upon an error, an
    pubsub_v1.subscriber.exceptions.AcknowledgeError exception
    will be thrown.

Nr   )r*   r   rr   rs   r)   rl   r   r   r'   r_   r;   )r?   ri   rt   s      r   nack_with_responseMessage.nack_with_response  sr    F 3355^^%FJ$FJ  ||))!..!		
 r   )r'   r/   r1   r(   r*   r&   r<   r:   r-   r)   r>   r+   )r   zcontainers.ScalarMap)r   zdatetime.datetime)r   N)r   rp   )__name__
__module____qualname____firstlineno____doc__rP   intr   boolr@   rS   propertyr.   bytesr0   r5   r;   r_   r    r   r!   rn   ru   ry   r~   r   r   r   __static_attributes__r   r   r   r   r   C   sH   8 BO7(07( 7( 	7(
 %7( -5RX,>7(rU    $ e   " " "c " " c      &(3- & &&
>8t
&
3 
4 
(< <AQ <|
 3r   r   )z  )
__future__r   r3   r2   rJ   rj   r,   typingr   r   +google.cloud.pubsub_v1.subscriber._protocolr   !google.cloud.pubsub_v1.subscriberr   ,google.cloud.pubsub_v1.subscriber.exceptionsr   TYPE_CHECKINGqueuegoogle.cloud.pubsub_v1r	   !cloudsdk.google.protobuf.internalr
   rN   rr   rs   
set_resultSUCCESSrP   r   objectr   r   r   r   <module>r      s    '      % @ 5 J 
,< .."   ,44 53  s (if ir   