a
    `gD                     @   s4  d dl Z d dlZd dlZd dlZd dlZd dlZd dlZd dlZd dlZd dl	Z	d dl
Z
d dlZd dlmZ d dlmZmZmZ d dlmZmZmZmZmZmZmZmZmZmZmZ d dlmZ ddl m!Z!m"Z" ddl#m$Z$ dd	l%m&Z&m'Z'm(Z( d
Z)ee*df Z+dj,Z-dj,Z.dZ/G dd de!Z0G dd de!Z1dS )    N)defaultdict)
BaseCookieMorselSimpleCookie)DefaultDictDictIterableIteratorListMappingOptionalSetTupleUnioncast)URL   )AbstractCookieJarClearCookiePredicate)is_ip_address)LooseCookiesPathLikeStrOrURL)	CookieJarDummyCookieJarMorsel[str]z{}/{}z{1}.{0}d   c                	       s  e Zd ZdZedZedZedZedej	Z
edZeejjjejjd d Zzeee W n4 eefy   ed	ZY n ey   d
ZY n0 ed Zdddddeeeeee df e e!j" dd fddZ#e$edddZ%e&ddddZ'e&ddddZ(d:e e) ddddZ*e+ddddZ,d dd!d"Z-edd#d$Z.ddd%d&Z/ee0e+e+e+f  dd'd(d)Z1e2e+e+e+dd*d+d,Z3e4 fe5e4dd-d.d/Z6e4 fe4d0d1d2d3Z7e8e+e+ed4d5d6Z9e:e+e e d7d8d9Z;  Z<S );r   z/Implements cookie storage adhering to RFC 6265.z][\x09\x20-\x2F\x3B-\x40\x5B-\x60\x7B-\x7E]*(?P<token>[\x00-\x08\x0A-\x1F\d:a-zA-Z\x7F-\xFF]+)z(\d{1,2}):(\d{1,2}):(\d{1,2})z	(\d{1,2})zG(jan)|(feb)|(mar)|(apr)|(may)|(jun)|(jul)|(aug)|(sep)|(oct)|(nov)|(dec)z	(\d{2,4}))tzinfor   )	i           ;   r!   r"   r"   iFTN)unsafequote_cookietreat_as_secure_originloop)r#   r$   r%   r&   returnc                   s   t  j|d tt| _tt| _t | _|| _	|| _
|d u rDg }n>t|trZ| g}n(t|trtt| g}ndd |D }|| _g | _i | _d S )Nr&   c                 S   s*   g | ]"}t |trt| n| qS  )
isinstancestrr   origin).0urlr)   r)   _/var/www/html/cobodadashboardai.evdpl.com/venv/lib/python3.9/site-packages/aiohttp/cookiejar.py
<listcomp>p   s   z&CookieJar.__init__.<locals>.<listcomp>)super__init__r   r   _cookiesdict_morsel_cacheset_host_only_cookies_unsafe_quote_cookier*   r   r,   r+   _treat_as_secure_origin_expire_heap_expirations)selfr#   r$   r%   r&   	__class__r)   r/   r2   W   s*    

zCookieJar.__init__r'   c                 C   s   | j S N)r9   r=   r)   r)   r/   r$   x   s    zCookieJar.quote_cookie)	file_pathr'   c                 C   sL   t |}|jdd"}t| j|tj W d    n1 s>0    Y  d S )Nwbmode)pathlibPathopenpickledumpr3   HIGHEST_PROTOCOLr=   rC   fr)   r)   r/   save|   s    
zCookieJar.savec                 C   sF   t |}|jdd}t|| _W d    n1 s80    Y  d S )NrbrE   )rG   rH   rI   rJ   loadr3   rM   r)   r)   r/   rQ      s    
zCookieJar.load	predicater'   c                    sv   d u r>j   j  j  j  j  d S t  fddj D }|rr| d S )Nc                    sT   g | ]L\\}}}|  D ]6\}}|||f  jv rBj  ksJ|r qqS r)   )itemsr<   )r-   domainpathcookienamemorselkeynowrS   r=   r)   r/   r0      s   
z#CookieJar.clear.<locals>.<listcomp>)	r;   clearr3   r5   r7   r<   timerT   _delete_cookies)r=   rS   to_delr)   rZ   r/   r]      s    





zCookieJar.clearrU   r'   c                    s     fdd d S )Nc                    s     | d S )NrU   )_is_domain_match)xrU   r=   r)   r/   <lambda>       z(CookieJar.clear_domain.<locals>.<lambda>)r]   r=   rU   r)   rd   r/   clear_domain   s    zCookieJar.clear_domainIterator[Morsel[str]]c                 c   s*   |    | j D ]}| E d H  qd S rA   )_do_expirationr3   values)r=   valr)   r)   r/   __iter__   s    zCookieJar.__iter__c                 C   s   t dd | j D S )zReturn number of cookies.

        This function does not iterate self to avoid unnecessary expiration
        checks.
        c                 s   s   | ]}t | V  qd S rA   )lenrk   )r-   rW   r)   r)   r/   	<genexpr>   rf   z$CookieJar.__len__.<locals>.<genexpr>)sumr3   rk   rB   r)   r)   r/   __len__   s    zCookieJar.__len__c                    s   t  j }sdS |tkrN|t  jd krN fdd jD  _t j t }g } jr jd \}}||krxqt j  j||krZ|	| qZ|r 
| dS )zRemove expired cookies.N   c                    s(   g | ] } j |d  |d kr|qS )r   r   )r<   get)r-   entryrB   r)   r/   r0      s   z,CookieJar._do_expiration.<locals>.<listcomp>r   )rn   r;    _MIN_SCHEDULED_COOKIE_EXPIRATIONr<   heapqheapifyr^   heappoprs   appendr_   )r=   Zexpire_heap_lenr\   r`   when
cookie_keyr)   rB   r/   rj      s*    
zCookieJar._do_expiration)r`   r'   c                 C   sd   |D ]Z\}}}| j ||f | j||f |d  | j||f |d  | j|||fd  qd S rA   )r7   discardr3   popr5   r<   )r=   r`   rU   rV   rX   r)   r)   r/   r_      s
    zCookieJar._delete_cookies)rz   rU   rV   rX   r'   c                 C   s>   |||f}| j ||krd S t| j||f || j |< d S rA   )r<   rs   rv   heappushr;   )r=   rz   rU   rV   rX   r{   r)   r)   r/   _expire_cookie   s
    
zCookieJar._expire_cookiecookiesresponse_urlr'   c              	   C   s  |j }| jst|rdS t|tr*| }|D ]\}}t|tsXt }|||< || }|d }|rz|d dkrzd}|d= |s|dur| j	||f | }|d< |r|d dkr|dd }||d< |r| 
||sq.|d }|r|d d	kr(|j}|d	s
d	}nd	|d|d	  }||d< |d	}|d
  }	rz0t|	}
tt |
 | j}| |||| W n ty   d|d
< Y n0 n8|d  }r| | }r| |||| nd|d< ||f}| j| ||kr.|| j| |< | j| |d q.|   dS )zUpdate cookies.NrU   r"   . r   r   rV   /zmax-ageexpires)raw_hostr8   r   r*   r   rT   r   r   r7   addrb   rV   
startswithrfindrstripintminr^   MAX_TIMEr   
ValueError_parse_dater3   rs   r5   r}   rj   )r=   r   r   hostnamerX   rW   tmprU   rV   Zmax_ageZdelta_secondsZmax_age_expirationr   expire_timer[   r)   r)   r/   update_cookies   s\    


zCookieJar.update_cookiesBaseCookie[str]request_urlr'   c                 C   s  | j rt nt }| js|S |   | js.|S t|tur\tjdt| t	dd t|}|j
pdd}|jdv}|r| jrt }tt | }W d   n1 s0    Y  || jv}| jd  D ]}|j||j< qt|r| js|S |f}ntt|dt}t|jd	t}t||}	t|j}
|	D ]}| j|  D ]\}}|d
 }||f| j v rz||krzqLt|d |
krqL|r|d rqL|| j!| v r| j!| | ||< qLt"d|#|jt$ }|%|j|j|j& || j!| |< |||< qLq:|S )z8Returns this jar's cookies filtered by their attributes.zQfilter_cookies expects yarl.URL instances only,and will stop working in 4.x, got rr   )
stacklevelr   )httpswssN)r   r   r   r   rU   rV   securer   )'r9   r   r   r3   rj   typer   warningswarnDeprecationWarningr   schemer:   
contextlibsuppressr   r,   rk   valuer[   r   r8   	itertools
accumulatereversedsplit_FORMAT_DOMAIN_REVERSEDrV   _FORMAT_PATHproductrn   rT   r7   r5   r   rs   r   r6   coded_value)r=   r   filteredr   Zis_not_secureZrequest_origincdomainspathspairsZpath_lenprX   rW   rU   Zmrsl_valr)   r)   r/   filter_cookies1  sh    


&

zCookieJar.filter_cookies)rU   r   r'   c                 C   sD   || krdS | | sdS |dt|   }| ds:dS t| S )z0Implements domain matching adhering to RFC 6265.TFNr   )endswithrn   r   )rU   r   Znon_matchingr)   r)   r/   rb     s    

zCookieJar._is_domain_match)date_strr'   c                 C   s  |sdS d}d}d}d}d } }}d}	d}
d}| j |D ]}|d}|s|| j|}|r|d}dd | D \}}}q<|s| j|}|rd}t| }	q<|s| j|}|rd}|j	dusJ |j	}
q<|s<| j
|}|r<d}t| }q<d|  krd	krn n
|d
7 }n$d|  kr4dkr@n n|d7 }d||||fv rVdS d|	  krndkstn dS |dk s|dks|dks|dkrdS t||
|	|||dddf	S )z4Implements date string parsing adhering to RFC 6265.NFr   tokenTc                 s   s   | ]}t |V  qd S rA   )r   )r-   sr)   r)   r/   ro     rf   z(CookieJar._parse_date.<locals>.<genexpr>F   c   il  E   i  r   r   iA  r    r!   r"   )DATE_TOKENS_REfinditergroupDATE_HMS_TIME_REmatchgroupsDATE_DAY_OF_MONTH_REr   DATE_MONTH_RE	lastindexDATE_YEAR_REcalendartimegm)clsr   Z
found_timeZ	found_dayZfound_monthZ
found_yearhourminuteseconddaymonthyearZtoken_matchr   Z
time_matchZ	day_matchZmonth_matchZ
year_matchr)   r)   r/   r     s^    

(zCookieJar._parse_date)N)=__name__
__module____qualname____doc__recompiler   r   r   Ir   r   r   datetimemaxreplacetimezoneutc	timestampr   r   r   r^   gmtimeOSErrorr   OverflowErrorZSUB_MAX_TIMEboolr   r   r
   r   asyncioAbstractEventLoopr2   propertyr$   r   rO   rQ   r   r]   r+   rh   rm   rq   rj   r   r_   floatr   r   r   r   r   staticmethodrb   classmethodr   __classcell__r)   r)   r>   r/   r   2   s`   



!+JNr   c                       s   e Zd ZdZddeej dd fddZddd	d
Ze	dddZ
eedddZdee ddddZeddddZe feeddddZeddddZ  ZS )r   zxImplements a dummy cookie storage.

    It can be used with the ClientSession when no cookie processing is needed.

    Nr(   )r&   r'   c                   s   t  j|d d S )Nr(   )r1   r2   )r=   r&   r>   r)   r/   r2     s    zDummyCookieJar.__init__ri   r@   c                 c   s   d S rA   r)   rB   r)   r)   r/   rm     s    zDummyCookieJar.__iter__c                 C   s   dS )Nr   r)   rB   r)   r)   r/   rq     s    zDummyCookieJar.__len__c                 C   s   dS )NTr)   rB   r)   r)   r/   r$     s    zDummyCookieJar.quote_cookierR   c                 C   s   d S rA   r)   )r=   rS   r)   r)   r/   r]     s    zDummyCookieJar.clearra   c                 C   s   d S rA   r)   rg   r)   r)   r/   rh     s    zDummyCookieJar.clear_domainr   c                 C   s   d S rA   r)   )r=   r   r   r)   r)   r/   r     s    zDummyCookieJar.update_cookiesr   r   c                 C   s   t  S rA   )r   )r=   r   r)   r)   r/   r     s    zDummyCookieJar.filter_cookies)N)r   r   r   r   r   r   r   r2   rm   r   rq   r   r   r$   r   r]   r+   rh   r   r   r   r   r   r)   r)   r>   r/   r     s    r   )2r   r   r   r   rv   r   osrG   rJ   r   r^   r   collectionsr   http.cookiesr   r   r   typingr   r   r   r	   r
   r   r   r   r   r   r   Zyarlr   abcr   r   helpersr   Ztypedefsr   r   r   __all__r+   Z
CookieItemformatr   r   ru   r   r   r)   r)   r)   r/   <module>   s8   4   !