a
    !f                     @   s   d Z ddl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 z4dd
lmZ ddlmZ ddlmZ ddlmZ W n& ey   dZd ZZd ZZY n0 dZeoejdduZG dd deZdS )z9Client for interacting with the Google Cloud Pub/Sub API.    N)
JSONClient)
Connection)_PublisherAPI)_SubscriberAPI)_IAMPolicyAPI)SubscriptionTopic)PublisherApi)SubscriberApiFTZGCLOUD_ENABLE_GAXc                   @   sb   e Zd ZdZeZd Z ZZe	dd Z
e	dd Ze	dd Zdd	d
ZdddZdddZdS )Clienta  Client to bundle configuration needed for API requests.

    :type project: string
    :param project: the project which the client acts on behalf of. Will be
                    passed when creating a topic.  If not passed,
                    falls back to the default inferred from the environment.

    :type credentials: :class:`oauth2client.client.OAuth2Credentials` or
                       :class:`NoneType`
    :param credentials: The OAuth2 Credentials to use for the connection
                        owned by this client. If not passed (and if no ``http``
                        object is passed), falls back to the default inferred
                        from the environment.

    :type http: :class:`httplib2.Http` or class that defines ``request()``.
    :param http: An optional HTTP object to make requests. If not passed, an
                 ``http`` object is created that is bound to the
                 ``credentials`` for the current object.
    Nc                 C   s2   | j du r,tr t }t|| _ nt| j| _ | j S )z'Helper for publisher-related API calls.N)_publisher_api_USE_GAXGeneratedPublisherAPIGAXPublisherAPIJSONPublisherAPI
connectionself	generated r   U/var/www/html/python-backend/venv/lib/python3.9/site-packages/gcloud/pubsub/client.pypublisher_apiG   s    
zClient.publisher_apic                 C   s2   | j du r,tr t }t|| _ nt| j| _ | j S )z(Helper for subscriber-related API calls.N)_subscriber_apir   GeneratedSubscriberAPIGAXSubscriberAPIJSONSubscriberAPIr   r   r   r   r   subscriber_apiR   s    
zClient.subscriber_apic                 C   s   | j du rt| j| _ | j S )z(Helper for IAM policy-related API calls.N)_iam_policy_apir   r   r   r   r   r   iam_policy_api]   s    
zClient.iam_policy_apic                    s4    j }| j||\}} fdd|D }||fS )a  List topics for the project associated with this client.

        See:
        https://cloud.google.com/pubsub/reference/rest/v1/projects.topics/list

        Example:

        .. literalinclude:: pubsub_snippets.py
           :start-after: [START client_list_topics]
           :end-before: [END client_list_topics]

        :type page_size: int
        :param page_size: maximum number of topics to return, If not passed,
                          defaults to a value set by the API.

        :type page_token: string
        :param page_token: opaque marker for the next "page" of topics. If not
                           passed, the API will return the first page of
                           topics.

        :rtype: tuple, (list, str)
        :returns: list of :class:`gcloud.pubsub.topic.Topic`, plus a
                  "next page token" string:  if not None, indicates that
                  more topics can be retrieved with another call (pass that
                  value as ``page_token``).
        c                    s   g | ]}t | qS r   )r	   from_api_repr.0resourcer   r   r   
<listcomp>   s   z&Client.list_topics.<locals>.<listcomp>)r   list_topicsproject)r   	page_size
page_tokenapi	resources
next_tokentopicsr   r   r   r&   d   s    
zClient.list_topicsc                    s:    j }| j||\}}i  fdd|D }||fS )a  List subscriptions for the project associated with this client.

        See:
        https://cloud.google.com/pubsub/reference/rest/v1/projects.topics/list

        Example:

        .. literalinclude:: pubsub_snippets.py
           :start-after: [START client_list_subscriptions]
           :end-before: [END client_list_subscriptions]

        :type page_size: int
        :param page_size: maximum number of topics to return, If not passed,
                          defaults to a value set by the API.

        :type page_token: string
        :param page_token: opaque marker for the next "page" of topics. If not
                           passed, the API will return the first page of
                           topics.

        :rtype: tuple, (list, str)
        :returns: list of :class:`gcloud.pubsub.subscription.Subscription`,
                  plus a "next page token" string:  if not None, indicates that
                  more topics can be retrieved with another call (pass that
                  value as ``page_token``).
        c                    s   g | ]}t j| d qS ))r-   )r   r!   r"   r   r-   r   r   r%      s   z-Client.list_subscriptions.<locals>.<listcomp>)r   list_subscriptionsr'   )r   r(   r)   r*   r+   r,   Zsubscriptionsr   r.   r   r/      s    zClient.list_subscriptionsFc                 C   s   t || |dS )a  Creates a topic bound to the current client.

        Example:

        .. literalinclude:: pubsub_snippets.py
           :start-after: [START client_topic]
           :end-before: [END client_topic]

        :type name: string
        :param name: the name of the topic to be constructed.

        :type timestamp_messages: boolean
        :param timestamp_messages: To be passed to ``Topic`` constructor.

        :rtype: :class:`gcloud.pubsub.topic.Topic`
        :returns: Topic created with the current client.
        )clienttimestamp_messagesr   )r   namer1   r   r   r   topic   s    zClient.topic)NN)NN)F)__name__
__module____qualname____doc__r   Z_connection_classr   r   r   propertyr   r   r    r&   r/   r3   r   r   r   r   r   /   s   





"
$r   )r7   osZgcloud.clientr   Zgcloud.pubsub.connectionr   r   r   r   r   r   Zgcloud.pubsub.subscriptionr   Zgcloud.pubsub.topicr	   Z$google.cloud.pubsub.v1.publisher_apir
   r   Z%google.cloud.pubsub.v1.subscriber_apir   r   Zgcloud.pubsub._gaxr   r   ImportErrorZ	_HAVE_GAXenvirongetr   r   r   r   r   r   <module>   s(   