
                         z   d dl mZmZmZ d dlmZ d dlmZ d dlm	Z	 d dl
mZ d dlmZ d dlmZ d dlmZ d d	lmZ d d
lmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZm Z  d dl!m"Z" d dl#m$Z$m%Z% d dl&m'Z' d dl(m)Z) d dl*m+Z+  eddd      Z,dZ-	 	 	 	 	 d$de de.dee   dee+   dee)   d eee.e.f      d!ee   d"efd#Z/y)%    )AsyncIteratorMappingOptional)BatchSettings)AdminClient)regional_endpoint)PublisherClientId)PublishSequenceNumber)ClientCacheDefaultRoutingPolicy)GapicConnectionFactory)merge_metadata)PartitionCountWatcherImpl)PartitionCountWatchingPublisher)	Publisher)SinglePartitionPublisher)	Partition	TopicPath)topic_routing_metadata)InitialPublishRequestPublishRequest)async_client)ClientOptions)Credentialsi  0 i  g?)	max_bytesmax_messagesmax_latencyiX  Ntopic	transportper_partition_batching_settingscredentialsclient_optionsmetadata	client_idreturnc                 H   
 t         t         j                  j                        })t	        t         j                  j                              t        fd      
dt        f
 fd}dt        fd}	t        t        | t              ||	      S )a  
    Make a new publisher for the given topic.

    Args:
      topic: The topic to publish to.
      transport: The transport type to use.
      per_partition_batching_settings: Settings for batching messages on each partition. The default is reasonable for most cases.
      credentials: The credentials to use to connect. GOOGLE_DEFAULT_CREDENTIALS is used if None.
      client_options: Other options to pass to the client. Note that if you pass any you must set api_endpoint.
      metadata: Additional metadata to send with the RPC.
      client_id: 128-bit unique client id. If set, enables publish idempotency for the session.

    Returns:
      A new Publisher.

    Throws:
      GoogleApiCallException on any error determining topic structure.
    )regionr"   r#   )api_endpointc                  4    t        j                         S )N)r"   r    r#   )r   PublisherServiceAsyncClient)r#   r"   r    s   Glib/third_party/google/cloud/pubsublite/internal/wire/make_publisher.py<lambda>z make_publisher.<locals>.<lambda>c   s    88#y
    	partitionc                      dt         t           f fd}t        t               j                        }rj                  |_        t        |t        |      t        d            S )Nrequestsc                     t        t                    }j                         j                  | t	        |j                                     S )N)r$   )r   r   getpublishlistitems)r1   final_metadataclient_cacher$   r/   r   s     r,   connection_factoryzEmake_publisher.<locals>.publisher_factory.<locals>.connection_factoryi   sP    +0	BN  ##%--4(<(<(>#? .  r.   )r   r/   r   )	r   r   r   strvaluer%   r   r   r
   )r/   r9   initial_requestr8   r%   r$   r!   r   s   `  r,   publisher_factoryz)make_publisher.<locals>.publisher_factoryh   sg    	~)F 	 	 0e*	
 (1O%'+"#56!!$	
 	
r.   partition_countc                     t        |       S )Nr   )r>   s    r,   policy_factoryz&make_publisher.<locals>.policy_factory}   s    #O44r.   )DEFAULT_BATCHING_SETTINGSr   locationr(   r   r   r   r   intr   r   DEFAULT_PARTITION_POLL_PERIOD)r   r    r!   r"   r#   r$   r%   admin_clientr=   r@   r8   s   ```````   @r,   make_publisherrF   <   s    6 '.*C'~~$$%L
 &*5>>+@+@A
 	
L
Y 
 
*5 5 +!,7TU r.   )NNNNN)0typingr   r   r   google.cloud.pubsub_v1.typesr   $google.cloud.pubsublite.admin_clientr   *google.cloud.pubsublite.internal.endpointsr   4google.cloud.pubsublite.internal.publisher_client_idr	   8google.cloud.pubsublite.internal.publish_sequence_numberr
   2google.cloud.pubsublite.internal.wire.client_cacher   <google.cloud.pubsublite.internal.wire.default_routing_policyr   6google.cloud.pubsublite.internal.wire.gapic_connectionr   4google.cloud.pubsublite.internal.wire.merge_metadatar   Bgoogle.cloud.pubsublite.internal.wire.partition_count_watcher_implr   Hgoogle.cloud.pubsublite.internal.wire.partition_count_watching_publisherr   /google.cloud.pubsublite.internal.wire.publisherr   @google.cloud.pubsublite.internal.wire.single_partition_publisherr   google.cloud.pubsublite.typesr   r   1google.cloud.pubsublite.internal.routing_metadatar   google.cloud.pubsublite_v1r   r   5google.cloud.pubsublite_v1.services.publisher_servicer   google.api_core.client_optionsr   google.auth.credentialsr   rA   rD   r:   rF    r.   r,   <module>r\      s	   4 3 6 < H R K P F ? T L N 8 /)  !$  @D)-.2,0-1HHH &.m%<H +&	H
 ]+H wsCx()H )*H Hr.   