o
    Df                     @  s   d 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mZmZ zddlZdZW n ey9   d	ZY nw d
dlmZ eeddZeeZG dd deZdd Zdd ZeZ		dddZdddZdddZdd ZdS )zURL Utilities.    )annotations)Mapping)partial)
NamedTuple)	parse_qslquoteunquoteurlparseNTF   )
get_logger )safec                   @  sJ   e Zd ZU dZded< ded< ded< ded< ded< ded	< d
ed< dS )urlpartsz*Named tuple representing parts of the URL.strschemehostnameintportusernamepasswordpathr   queryN)__name__
__module____qualname____doc____annotations__ r   r   H/home/ubuntu/webapp/venv/lib/python3.10/site-packages/kombu/utils/url.pyr      s   
 r   c           
   	   C  s   t | \}}}}}}}|rEdd | D }|D ],}	|	dkr1t||	 ||	< ||	 du r1td d|vr9i |d< ||	 |d |	< ||	= qtd||||||d|S )	z%Parse URL into mapping of components.c                 S  s   g | ]	}| d r|qS )ssl_)
startswith).0keyr   r   r   
<listcomp>(   s    zparse_url.<locals>.<listcomp>ssl_cert_reqsNz%Defaulting to insecure SSL behaviour.ssl)	transportr   r   useridr   virtual_hostr   )
_parse_urlkeysparse_ssl_cert_reqsloggerwarningdict)
urlr   hostr   userr   r   r   r*   r"   r   r   r   	parse_url#   s$   
r2   c              
   C  s   t | j}| t|d d }t d| }|jpd}|r(|d dkr(|dd n|}t|t|jp1dp4d|jt|jp;dp>dt|j	pCdpFdt|pJdpMdt
t|jS )z5Parse URL into :class:`urlparts` tuple of components.   Nzhttp://r   r   /   )r	   r   lenr   r   r   r   r   r   r   r.   r   r   )r/   r   
schemelesspartsr   r   r   r   url_to_parts:   s   

 r9   **c	           
      C  s   |  dg}	|s
|r2|r|	 t| |r-|r$|	|rd|gndg n	|	dt|g |	 d |	 |r:t|nd |rF|	d|g |	d|g ddd |	D S )z"Generate URL from component parts.://:@r   r4   c                 s  s    | ]	}|rt |V  qd S )N)r   )r!   partr   r   r   	<genexpr>c   s    zas_url.<locals>.<genexpr>)append	safequoteextendjoin)
r   r0   r   r1   r   r   r   sanitizemaskr8   r   r   r   as_urlQ   s   
rF   c                 C  s   t t| d|dS )z)Return copy of URL with password removed.T)rD   rE   )rF   r)   r/   rE   r   r   r   sanitize_urlf   s   rH   c                 C  s    t | trd| v rt| |S | S )z-Sanitize url, or do nothing if url undefined.r;   )
isinstancer   rH   rG   r   r   r   maybe_sanitize_urll   s   
rJ   c                 C  s.   t rtjtjtjtjtjtjd}||  S dS )zMGiven the query parameter for ssl_cert_reqs, return the SSL constant or None.)CERT_REQUIREDCERT_OPTIONAL	CERT_NONErequiredoptionalnoneN)ssl_availabler%   rK   rL   rM   )query_valuequery_value_to_constantr   r   r   r+   t   s   r+   )NNNNNNFr:   )r:   )r   
__future__r   collections.abcr   	functoolsr   typingr   urllib.parser   r   r   r	   r%   rQ   ImportErrorlogr   rA   r   r,   r   r2   r9   r)   rF   rH   rJ   r+   r   r   r   r   <module>   s2    


