o
    aqe                     @   s   d dl Z d dlZd dlZd dlmZ d dlmZ d dlmZm	Z	m
Z
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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! G dd dZ"dS )    N)HTTPResponse)
SSLContext)DictUnionListOptional)	HTTPError)RequesturlopenOpenerDirectorProxyHandlerHTTPSHandler)SlackRequestError   )_build_body_build_request_headers_debug_log_response)WebhookResponse   )get_user_agent)
Attachment)Blockc                   @   s.  e Zd Zee Z						ddededee	 dee dee
eef  dee d	ee fd
dZdddddddee deeee
eef ef   deeee
eef ef   dee dee
eef  defddZ	dde
eef dee
eef  defddZde
eef de
eef defddZdS )WebhookClient   Nurltimeoutsslproxydefault_headersuser_agent_prefixuser_agent_suffixc                 C   s:   || _ || _|| _|| _|r|ni | _t||| jd< dS )a  API client for Incoming Webhooks and response_url
        :param url: a complete URL to send data (e.g., https://hooks.slack.com/XXX)
        :param timeout: request timeout (in seconds)
        :param ssl: ssl.SSLContext to use for requests
        :param proxy: proxy URL (e.g., localhost:9000, http://localhost:9000)
        :param default_headers: request headers to add to all requests
        :param user_agent_prefix: prefix for User-Agent header value
        :param user_agent_suffix: suffix for User-Agent header value
        z
User-AgentN)r   r   r   r   r   r   )selfr   r   r   r   r   r   r     r"   U/var/www/html/humari/django-venv/lib/python3.10/site-packages/slack/webhook/client.py__init__   s   zWebhookClient.__init__)textattachmentsblocksresponse_typeheadersr%   r&   r'   r(   r)   returnc                C   s   | j ||||d|dS )a  Performs a Slack API request and returns the result.
        :param text: the text message (even when having blocks, setting this as well is recommended as it works as fallback)
        :param attachments: a collection of attachments
        :param blocks: a collection of Block Kit UI components
        :param response_type: the type of message (either 'in_channel' or 'ephemeral')
        :param headers: request headers to append only for this request
        :return: API response
        )r%   r&   r'   r(   bodyr)   )	send_dict)r!   r%   r&   r'   r(   r)   r"   r"   r#   send1   s   zWebhookClient.sendr,   c                 C   s   | j t|t| j|dS )a<  Performs a Slack API request and returns the result.
        :param body: json data structure (it's still a dict at this point),
            if you give this argument, body_params and files will be skipped
        :param headers: request headers to append only for this request
        :return: API response
        r+   )_perform_http_requestr   r   r   )r!   r,   r)   r"   r"   r#   r-   L   s   	
zWebhookClient.send_dictc             
   C   s  t |}d|d< | jjtjkr | jd| j d| d|  z}| j}d}| 	dr`t
d||d	|d
}| jdur_t| jtrVtjt| j| jdt| jd}ntd| j dntd| d}|rt|j|| jd}n	t|| j| jd}|j pd	}| |}t||j||jd}t| j| |W S  t y }	 z3|	j pd	}|	 |}t||	j!||	jd}|	j!dkr|jd |jd< t| j| |W  Y d}	~	S d}	~	w t"y }
 z| j#d|
  |
d}
~
ww )a  Performs an HTTP request and parses the response.
        :param url: a complete URL to send data (e.g., https://hooks.slack.com/XXX)
        :param body: request body data
        :param headers: complete set of request headers
        :return: API response
        zapplication/json;charset=utf-8zContent-TypezSending a request - url: z, body: z, headers: NhttpPOSTzutf-8)methodr   datar)   )r0   https)contextzInvalid proxy detected: z must be a str valuezInvalid URL detected: )r   )r5   r   )r   status_coder,   r)   i  zretry-afterzRetry-Afterz.Failed to send a request to Slack API server: )$jsondumpsloggerlevelloggingDEBUGdebugr   lower
startswithr	   encoder   
isinstancestrurllibrequestbuild_openerr   r   r   r   openr   r
   r)   get_content_charsetreaddecoder   statusr   r   code	Exceptionerror)r!   r,   r)   r   openerreqrespcharsetresponse_bodyeerrr"   r"   r#   r/   Z   sv   
	



z#WebhookClient._perform_http_request)r   NNNNN)N)__name__
__module____qualname__r;   	getLoggerr9   rB   intr   r   r   r$   r   r   anyr   r   r   r.   r-   r/   r"   r"   r"   r#   r      sp    






r   )#r7   r;   rC   http.clientr   r   r   typingr   r   r   r   urllib.errorr   urllib.requestr	   r
   r   r   r   slack.errorsr   internal_utilsr   r   r   webhook_responser   webr   web.classes.attachmentsr   web.classes.blocksr   r   r"   r"   r"   r#   <module>   s    