
    i                        d dl 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m	Z	m
Z
mZmZ d dlmZ d dlZd dlmZmZmZ d dlmZmZ d d	lmZ d
efdZdeded
efdZdede	e         dedede	e         d
eeef         fdZde	e         dededeeef         dedededede	e         de	e         d
efdZded
ee
         fdZd e	e         d!e d"eded#eded
eee!f         fd$Z"dS )%    N)AbstractEventLoop)Logger)
SSLContext)UnionOptionalBinaryIOListDicturljoin)FormData	BasicAuthClientSession)SlackRequestErrorSlackApiError)get_user_agentreturnc                      	 t          j                    S # t          $ r, t          j                    } t          j        |            | cY S w xY w)z.Retrieves the event loop or creates a new one.)asyncioget_event_loopRuntimeErrornew_event_loopset_event_loop)loops    Y/root/projects/butler/venv/lib/python3.11/site-packages/slack/web/async_internal_utils.py_get_event_loopr      sY    %'''   %''t$$$s    3A
Abase_url
api_methodc                 "    t          | |          S )a*  Joins the base Slack URL and an API method to form an absolute URL.

    Args:
        base_url (str): The base URL
        api_method (str): The Slack Web API method. e.g. 'chat.postMessage'

    Returns:
        The absolute API URL.
            e.g. 'https://slack.com/api/chat.postMessage'
    r   )r   r   s     r   _get_urlr       s     8Z(((    headerstokenhas_json	has_filesrequest_specific_headersc                 B   t                      dd}|r*|                    dd                    |          i           | i } |                    |            |r|                    |           |r|                    ddi           |r|                    dd           |S )a4  Constructs the headers need for a request.
    Args:
        has_json (bool): Whether or not the request has json.
        has_files (bool): Whether or not the request has files.
        request_specific_headers (dict): Additional headers specified by the user for a specific request.

    Returns:
        The headers dictionary.
            e.g. {
                'Content-Type': 'application/json;charset=utf-8',
                'Authorization': 'Bearer xoxb-1234-1243',
                'User-Agent': 'Python/3.7.17 slack/2.1.0 Darwin/17.7.0'
            }
    z!application/x-www-form-urlencoded)z
User-AgentContent-TypeAuthorizationz	Bearer {}Nr(   zapplication/json;charset=utf-8)r   updateformatpop)r"   r#   r$   r%   r&   final_headerss         r   _get_headersr.   (   s    . %&&; M
  Ko{/A/A%/H/HIJJJ !!!   75666 Qn.NOPPP 0.$///r!   	http_verbfilesdataparamsjsonauthsslproxyc        
   	      b   |d u}
|d u}|
r|dk    rd}t          |          |rt          |d         |d                   }|3t          |t                    rd |                                D             }|3t          |t                    rd |                                D             }|3t          |t                    rd |                                D             }| } |d|v r|                    d          } |d|v r |j        d          } t          || |
||	          ||||||	|d
}|S )NPOSTz`Json data can only be submitted as POST requests. GET requests should use the 'params' argument.	client_idclient_secretc                     i | ]
\  }}|||S N .0kvs      r   
<dictcomp>z#_build_req_args.<locals>.<dictcomp>p   s    ???A1r!   c                     i | ]
\  }}|||S r<   r=   r>   s      r   rB   z#_build_req_args.<locals>.<dictcomp>r   s    AAA$!Q1=A===r!   c                     i | ]
\  }}|||S r<   r=   r>   s      r   rB   z#_build_req_args.<locals>.<dictcomp>t   s    CCC41aQ]!Q]]]r!   r#   )r"   r#   r$   r%   r&   )r"   r1   r0   r2   r3   r5   r6   r4   )r   r   
isinstancedictitemsr,   r.   )r#   r/   r0   r1   r2   r3   r"   r4   r5   r6   r$   r%   msgreq_argss                 r   _build_req_argsrJ   Y   s    4HT!I %I''p$$$ Ck*D,ABBJtT22?????Zt44AA%++--AAAj66CC6<<>>CCC Eg//

7##GtOO!!%,
 
 
  H  Or!   rI   c                    g }|                      dd           }||                                D ]\  }}t          |t                    rWt	          |                    dd          d          }|                    |           | d                             ||i           q| d                             ||i           |S )Nr0   zutf-8ignorerbr1   )r,   rG   rE   stropenencodeappendr*   )rI   
open_filesr0   r@   rA   fs         r   _files_to_datarT      s    JLL$''EKKMM 	0 	0DAq!S!! 0'844d;;!!!$$$ ''A//// ''A////r!   current_sessiontimeoutloggerapi_urlc                   K   d}| o| j          }|r| }n=t          j        t          j        |          |                    dd                    }d}	  |j        ||fi |4 d{V }	i }
	 |	                                 d{V }
ng# t          j        $ r |                    d| d           Y n=t          j	        j
        $ r'}dt          |           }t          ||	          d}~ww xY w|
|	j        |	j        d}ddd          d{V  n# 1 d{V swxY w Y   |s|                                 d{V  n"# |s|                                 d{V  w w xY w|S )	zSubmit the HTTP request with the running session or a new session.
    Returns:
        A dictionary of the response data.
    N)totalr4   )rV   r4   z7No response data returned from the following API call: .z#Failed to parse the response body: )r1   r"   status_code)closedaiohttpr   ClientTimeoutr,   requestr3   ContentTypeErrordebugdecoderJSONDecodeErrorrN   r   r"   statusclose)rU   rV   rW   r/   rX   rI   sessionuse_running_sessionresponseresr1   emessages                r   _request_with_sessionrm      sj      G)H/2H.H 
!')888fd++
 
 

 H""7?9gBBBB 	 	 	 	 	 	 	cD2 XXZZ''''''+ c c caW^aaabbbbb</ 2 2 2HAHH#GS1112
 ;"z H	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	  # 	"--//!!!!!!! # 	"--//!!!!!!!!	"Os`   D? )D-BD(C,0D2C,"C''C,,D?D? 
DD? DD? ?E)#r   r3   r   loggingr   r5   r   typingr   r   r   r	   r
   urllib.parser   r^   r   r   r   slack.errorsr   r   	slack.webr   r   rN   r    rF   boolr.   rJ   rT   intanyrm   r=   r!   r   <module>rv      s     % % % % % %             8 8 8 8 8 8 8 8 8 8 8 8 8 8              6 6 6 6 6 6 6 6 6 6 9 9 9 9 9 9 9 9 $ $ $ $ $ $*    )s ) ) ) ) ) ).. C=. 	.
 . 'tn. 
#s(^. . . .b2C=2 2 	2
 h
2 2 2 2 2 
*	2 C=2 
2 2 2 2jT d8n    +m,+ + 	+
 + + + 
#s(^+ + + + + +r!   