o
    ~h4                     @   sZ   d Z ddlZddlmZmZmZmZmZ ddlm	Z
 ddlmZ edZG dd dZdS )	zCA Python module for interacting and consuming responses from Slack.    N)AnyOptionalTypeVarUnionoverload   )_next_cursor_is_presentTc                   @   s   e Zd ZdZdedededeeef dedefdd	Z	d
d Z
dedefddZdd Zdd Zdd Zeddedddee fddZedededefddZdddZdd ZdS )SlackResponseaB  An iterable container of response data.

    Attributes:
        data (dict): The json-encoded content of the response. Along
            with the headers and status code information.

    Methods:
        validate: Check if the response from Slack was successful.
        get: Retrieves any key from the response data.
        next: Retrieves the next portion of results,
            if 'next_cursor' is present.

    Example:
    ```python
    import os
    import slack

    client = slack.WebClient(token=os.environ['SLACK_API_TOKEN'])

    response1 = client.auth_revoke(test='true')
    assert not response1['revoked']

    response2 = client.auth_test()
    assert response2.get('ok', False)

    users = []
    for page in client.users_list(limit=2):
        users = users + page['members']
    ```

    Note:
        Some responses return collections of information
        like channel and user lists. If they do it's likely
        that you'll only receive a portion of results. This
        object allows you to iterate over the response which
        makes subsequent API requests until your code hits
        'break' or there are no more results to be found.

        Any attributes or methods prefixed with _underscores are
        intended to be "private" internal use only. They may be changed or
        removed at anytime.
    	http_verbapi_urlreq_argsdataheadersstatus_codec                C   sF   || _ || _|| _|| _|| _|| _|| _d | _|| _t	
t| _d S N)r   r   r   r   r   r   _initial_data
_iteration_clientlogging	getLogger__name___logger)selfclientr   r   r   r   r   r    r   T/var/www/html/zoom/venv/lib/python3.10/site-packages/slack_sdk/web/slack_response.py__init__8   s   zSlackResponse.__init__c                 C   s   t | jtr
td| j S )z<Return the Response data if object is converted to a string.BAs the response.data is binary data, this operation is unsupported)
isinstancer   bytes
ValueErrorr   r   r   r   __str__N   s   zSlackResponse.__str__keyreturnc                 C   s   |  |d uS r   )getr   r$   r   r   r   __contains__T   s   zSlackResponse.__contains__c                 C   s4   t | jtr
td| jdu rtd| j|dS )a  Retrieves any key from the data store.

        Note:
            This is implemented so users can reference the
            SlackResponse object like a dictionary.
            e.g. response["ok"]

        Returns:
            The value from data or None.
        r   Nz<As the response.data is empty, this operation is unsupportedr   r   r    r!   r&   r'   r   r   r   __getitem__W   s
   
zSlackResponse.__getitem__c                 C   s   d| _ | j| _| S )zEnables the ability to iterate over the response.
        It's required for the iterator protocol.

        Note:
            This enables Slack cursor-based pagination.

        Returns:
            (SlackResponse) self
        r   )r   r   r   r"   r   r   r   __iter__h   s   
zSlackResponse.__iter__c                 C   s   t | jtr
td|  jd7  _| jdkr| S t| jrf| jdi }|du r*i }| jdi dp9| jd}|d|i | jd|i | j	j
| j| jd}|d	 | _|d
 | _|d | _|  S t)a  Retrieves the next portion of results, if 'next_cursor' is present.

        Note:
            Some responses return collections of information
            like channel and user lists. If they do it's likely
            that you'll only receive a portion of results. This
            method allows you to iterate over the response until
            your code hits 'break' or there are no more results
            to be found.

        Returns:
            (SlackResponse) self
                With the new response data now attached to this object.

        Raises:
            SlackApiError: If the request to the Slack API failed.
            StopIteration: If 'next_cursor' is not present or empty.
        r   r   paramsNresponse_metadatanext_cursorcursor)r   r   r   r   r   )r   r   r    r!   r   r   r   r&   updater   _request_for_paginationr   r   r   validateStopIteration)r   r,   r.   responser   r   r   __next__v   s(   

 


zSlackResponse.__next__Ndefaultc                 C      d S r   r   r   r$   r6   r   r   r   r&         zSlackResponse.getc                 C   r7   r   r   r8   r   r   r   r&      r9   c                 C   s0   t | jtr
td| jdu rdS | j||S )a'  Retrieves any key from the response data.

        Note:
            This is implemented so users can reference the
            SlackResponse object like a dictionary.
            e.g. response.get("ok", False)

        Returns:
            The value from data or the specified default.
        r   Nr)   r8   r   r   r   r&      s
   
c                 C   sJ   | j dkr| jrt| jts| jddr| S d| j d}tj|| d)zCheck if the response from Slack was successful.

        Returns:
            (SlackResponse)
                This method returns it's own object. e.g. 'self'

        Raises:
            SlackApiError: The request to the Slack API failed.
           okFz+The request to the Slack API failed. (url: ))messager4   )r   r   r   r    r&   r   eSlackApiError)r   msgr   r   r   r2      s   *
zSlackResponse.validater   )r   
__module____qualname____doc__strdictr   r    intr   r#   boolr(   r*   r+   r5   r   r   r   r&   r	   r2   r   r   r   r   r
      s4    +
	
+
r
   )rC   r   typingr   r   r   r   r   slack_sdk.errorserrorsr>   internal_utilsr   r	   r
   r   r   r   r   <module>   s    