
                         x    S 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	 r " S
 S\5      rg)z"Utilities for Pub/Sub Lite topics.    )cloudpubsub)types)message_transforms)topics)	lite_util)
gapic_util)http_encodingc                  P    [         R                  " [        R                  " 5       S9$ )N)credentials)r   PublisherClientr   GetGapicCredentials     0lib/googlecloudsdk/api_lib/pubsub/lite_topics.pyGetDefaultPublisherClientr      s!    		$	$002
4 4r   c                   F    \ rS rSrSrS
S jrS rS rS r    SS jr	S	r
g)r   !   z,Wrapper client for a Pub/Sub Lite publisher.Nc                 4    U=(       d
    [        5       U l        g N)r   _client)selfclients     r   __init__PublisherClient.__init__$   s    868DLr   c                 :    U R                   R                  5         U $ r   )r   	__enter__)r   s    r   r   PublisherClient.__enter__'   s    LLKr   c                 <    U R                   R                  XU5        g r   )r   __exit__)r   exc_type	exc_value	tracebacks       r   r   PublisherClient.__exit__+   s    LL(y9r   c                     [         R                  " [        R                  " UR                  5      [        R
                  " UR                  5      UR                  S9$ )N)projectlocationname)r   	TopicPathr   ProjectIdToProjectNumber
projectsIdLocationToZoneOrRegionlocationsIdtopicsId)r   resources     r   _TopicResourceToPath$PublisherClient._TopicResourceToPath.   sD    ??2283F3FG11(2F2FG   r   c                    U(       d  U(       d  [         R                  " S5      eU R                  U5      nU=(       d    0 nU(       a'  [        R                  " U5      U[        R
                  '    [        R                  R                  U R                  R                  " U[        R                  " U5      U40 UD6R                  5       5      $ ! [         a(  n[         R                  " SR!                  US95      eSnAff = f)a4  Publishes a message to the specified Pub/Sub Lite topic.

Args:
  topic_resource: The pubsub.lite_topic resource to publish to.
  message: The string message to publish.
  ordering_key: The key for ordering delivery to subscribers.
  attributes: A dict of attributes to attach to the message.
  event_time: A user-specified event timestamp.

Raises:
  EmptyMessageException: if the message is empty.
  PublishOperationException: if the publish operation is not successful.

Returns:
  The messageId of the published message, containing the Partition and
  Offset.
zdYou cannot send an empty message. You must specify either a MESSAGE, one or more ATTRIBUTE, or both.z,Publish operation failed with error: {error})errorN)r   EmptyMessageExceptionr/   r   encode_attribute_event_timePUBSUB_LITE_EVENT_TIMEr   MessageMetadatadecoder   publishr	   Encoderesult	ExceptionPublishOperationExceptionformat)r   topic_resourcemessageordering_key
attributes
event_time
topic_pathes           r   PublishPublisherClient.Publish4   s    . :((56 6 **>:J!rJ

8
8
D #::;J""))
,,

z=+?+?+H+;/9;;A68E E  J,,
8
?
?a
?
HJ JJs   0AC 
D #C;;D )r   r   )NNNN)__name__
__module____qualname____firstlineno____doc__r   r   r   r/   rE   __static_attributes__r   r   r   r   r   !   s-    49:  &Jr   r   N)rK   google.cloud.pubsubliter   r   #google.cloud.pubsublite.cloudpubsubr   googlecloudsdk.api_lib.pubsubr   !googlecloudsdk.command_lib.pubsubr   googlecloudsdk.corer   googlecloudsdk.core.utilr	   r   objectr   r   r   r   <module>rT      s4     ) 0 ) B 0 7 * 24
9Jf 9Jr   