o
    ߥi\                     @   s   d dl m Z mZ d dlmZ d dlmZ d dlmZm	Z	m
Z
 z
d dlmZmZ W n ey9   dd Zdd	 ZY nw d
dlmZmZmZmZ d
dlmZ eddG dd dZdS )    )datetimetimezone)parsedate_to_datetime)cookies)DictListOptional)
mypyc_attrtraitc                 C      | S N )clsr   r   B/home/ubuntu/.local/lib/python3.10/site-packages/baize/requests.pyr
   
   s   r
   c                  O   s   dd S )Nc                 S   r   r   r   )xr   r   r   <lambda>   s    zmypyc_attr.<locals>.<lambda>r   )attrskwattrsr   r   r   r	      s   r	      )URLContentTypeHeaders	MediaType)cached_propertyT)allow_interpreted_subclassesc                   @   s   e Zd ZdZedefddZedee fddZ	de
defdd	Zedefd
dZedee fddZedee
e
f fddZedee fddZedee fddZdS )MoreInfoFromHeaderMixinz>
    Parse more information from the header for quick use
    returnc                 C   s   t r   )NotImplementedErrorselfr   r   r   headers   s   zMoreInfoFromHeaderMixin.headersc                 C   s   dd | j dddD S )z*
        Request's accepted types
        c                 S   s   g | ]
}|  rt|qS r   )stripr   ).0tokenr   r   r   
<listcomp>$   s    z:MoreInfoFromHeaderMixin.accepted_types.<locals>.<listcomp>Acceptz*/*,)r    getsplitr   r   r   r   accepted_types   s   z&MoreInfoFromHeaderMixin.accepted_types
media_typec                    s   t  fdd| jD S )z<
        e.g. `request.accepts("application/json")`
        c                 3   s    | ]}|  V  qd S r   )match)r"   accepted_typer*   r   r   	<genexpr>.   s    

z2MoreInfoFromHeaderMixin.accepts.<locals>.<genexpr>)anyr)   )r   r*   r   r-   r   accepts*   s   zMoreInfoFromHeaderMixin.acceptsc                 C   s   t | jddS )z(
        Request's content-type
        zcontent-type )r   r    r'   r   r   r   r   content_type2   s   z$MoreInfoFromHeaderMixin.content_typec              	   C   sZ   | j dddkrdS | j dd}|du rdS ztdt|W S  ttfy,   Y dS w )z*
        Request's content-length
        ztransfer-encodingr1   chunkedNzcontent-lengthr   )r    r'   maxint
ValueError	TypeError)r   content_lengthr   r   r   r8   9   s   z&MoreInfoFromHeaderMixin.content_lengthc                 C   sx   i }| j dd}|dD ]+}|sqd|v r |dd\}}nd|}}| | }}|s2|r9t|||< q|S )z
        Returns cookies in as a `dict`.

        NOTE: Modifications to this dictionary will not affect the
        response value. In fact, this value should not be modified.
        cookier1   ;=r   )r    r'   r(   r!   http_cookies_unquote)r   r   cookie_headerchunkkeyvalr   r   r   r   J   s   
zMoreInfoFromHeaderMixin.cookiesc              	   C   s\   | j dd}|du rdS zt|}W n ttfy   Y dS w |jdu r,|jtjdS |S )zh
        The sending time of the request.

        NOTE: The datetime object is timezone-aware.
        dateN)tzinfo)	r    r'   r   r7   r6   rC   replacer   utc)r   valuerB   r   r   r   rB   g   s   
zMoreInfoFromHeaderMixin.datec                 C   s$   | j dd}|du rdS t|dS )z
        The `Referer` HTTP request header contains an absolute or partial address
        of the page making the request.
        refererN)url)r    r'   r   )r   referrerr   r   r   rI   |   s   
z MoreInfoFromHeaderMixin.referrerN)__name__
__module____qualname____doc__r   r   r    r   r   r)   strboolr0   r   r2   r   r5   r8   r   r   r   rB   r   rI   r   r   r   r   r      s"    
r   N)r   r   email.utilsr   httpr   r<   typingr   r   r   mypy_extensionsr	   r
   ImportErrordatastructuresr   r   r   r   utilsr   r   r   r   r   r   <module>   s    	