o
    NEg/                     @   s   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 d dlmZ ddlmZ ddlmZmZ dd	lmZm Z  d
Z!ee"df Z#G dd deZ$G dd deZ%dS )    N)defaultdict)
BaseCookieMorselSimpleCookie)
DefaultDictDictIterableIteratorMappingOptionalSetTupleUnioncast)URL   )AbstractCookieJar)is_ip_addressnext_whole_second)LooseCookiesPathLike)	CookieJarDummyCookieJarMorsel[str]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jjjejjdZejdZd	d
dddededeej ddf fddZdeddfddZdeddfddZd8ddZd9ddZdefddZd8dd Z d!ejd"e!d#e!ddfd$d%Z"e# fd&e$d'e#ddfd(d)Z%e# fd*e#de&d+ fd,d-Z'e(d"e!d.e!defd/d0Z)e(d1e!d2e!defd3d4Z*e+d5e!deej fd6d7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})tzinfoiFTN)unsafequote_cookieloopr   r   r   returnc                   sp   t  j|d tt| _t | _|| _|| _t	 | _
i | _| j| _z| j  W d S  ty7   | j| _Y d S w Nr   )super__init__r   r   _cookiesset_host_only_cookies_unsafe_quote_cookier   _next_expiration_expirationsMAX_TIME	_max_time	timestampOverflowErrorMAX_32BIT_TIME)selfr   r   r   	__class__ k/var/www/eduai.edurigo.com/doc_train/edurigo_ai/Puru/venv/lib/python3.10/site-packages/aiohttp/cookiejar.pyr#   9   s   zCookieJar.__init__	file_pathc                 C   sN   t |}|jdd}t| j|tj W d    d S 1 s w   Y  d S )Nwbmode)pathlibPathopenpickledumpr$   HIGHEST_PROTOCOLr0   r5   fr3   r3   r4   saveP   s   
"zCookieJar.savec                 C   sH   t |}|jdd}t|| _W d    d S 1 sw   Y  d S )Nrbr7   )r9   r:   r;   r<   loadr$   r?   r3   r3   r4   rC   U   s   
"zCookieJar.loadc                 C   s*   | j   | j  t | _| j  d S N)r$   clearr&   r   r)   r*   r0   r3   r3   r4   rE   Z   s   

zCookieJar.clearIterator[Morsel[str]]c                 c   s,    |    | j D ]	}| E d H  q
d S rD   )_do_expirationr$   values)r0   valr3   r3   r4   __iter__`   s
   zCookieJar.__iter__c                 C   s   t dd | D S )Nc                 s   s    | ]}d V  qdS )r   Nr3   ).0ir3   r3   r4   	<genexpr>f   s    z$CookieJar.__len__.<locals>.<genexpr>)sumrF   r3   r3   r4   __len__e      zCookieJar.__len__c           
      C   s   t j t jj}| j|krd S | jsd S | j}g }| j}| j}| D ]'\\}}}||krE|| 	|d  |
||f | j||f q#t||}q#|D ]}	||	= qMz|jddt jdd | _W d S  tyq   | j| _Y d S w )Nr   )microsecondr   seconds)datetimenowtimezoneutcr)   r*   r,   r$   itemspopappendr&   discardminreplace	timedeltar.   )
r0   rV   next_expirationto_delcookiesexpirationsdomainnamewhenkeyr3   r3   r4   rH   h   s4   

zCookieJar._do_expirationrf   rd   re   c                 C   s    t | j|| _|| j||f< d S rD   )r]   r)   r*   )r0   rf   rd   re   r3   r3   r4   _expire_cookie   s   zCookieJar._expire_cookierb   response_urlc              	   C   s  |j }| jst|rdS t|tr| }|D ]\}}t|ts+t }|||< || }|d }|dr9d}|d= |sM|durM| j	
||f | }|d< |dr\|dd }||d< |re| ||seq|d }|rp|ds|j}|ds{d}nd|d|d  }||d< |d }	|	rz*t|	}
ztjtjjtj|
d	 }W n ty   | j}Y nw | ||| W n& ty   d|d< Y nw |d
 }|r| |}|r| ||| nd|d
< || j| |< q|   dS )zUpdate cookies.Nrd   . r   path/zmax-agerS   expires)raw_hostr'   r   
isinstancer
   rY   r   r   endswithr&   add
startswith_is_domain_matchrl   rfindintrU   rV   rW   rX   r_   r.   r,   rh   
ValueError_parse_dater$   rH   )r0   rb   ri   hostnamere   cookietmprd   rl   max_agedelta_secondsmax_age_expirationrn   expire_timer3   r3   r4   update_cookies   sl   







zCookieJar.update_cookiesrequest_url)BaseCookie[str]zSimpleCookie[str]c           	      C   s   |    t|}| jrt nt }|jpd}|jdv}| D ]W}|j}|d }|s.|j||< q| j	s6t
|r6q||f| jv rC||krBqn| ||sJq| |j|d sTq|r[|d r[qtd||jt }||j|j|j |||< q|S )z8Returns this jar's cookies filtered by their attributes.rk   )httpswssrd   rl   securer   )rH   r   r(   r   r   ro   schemerg   valuer'   r   r&   rt   _is_path_matchrl   r   getr   r%   coded_value)	r0   r   filteredry   is_not_securerz   re   rd   mrsl_valr3   r3   r4   filter_cookies   s8   



zCookieJar.filter_cookiesry   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.TFNrj   )rq   lenr   )rd   ry   non_matchingr3   r3   r4   rt      s   


zCookieJar._is_domain_matchreq_pathcookie_pathc                 C   sP   |  dsd} | |krdS |  |sdS |drdS | t|d }| dS )z.Implements path matching adhering to RFC 6265.rm   TFN)rs   rq   r   )r   r   r   r3   r3   r4   r     s   



zCookieJar._is_path_matchdate_strc              	   C   s  |sdS d}d}d}d}d } }}d}	d}
d}| j |D ]\}|d}|s>| j|}|r>d}dd | D \}}}q|sQ| j|}|rQd}t| }	q|sh| j|}|rhd}|j	dusdJ |j	}
q|sz| j
|}|rzd}t| }qd|  krd	krn n|d
7 }nd|  krdkrn n|d7 }d||||fv rdS d|	  krdksdS  dS |dk s|dks|dks|dkrdS tj||
|	|||tjjdS )z4Implements date string parsing adhering to RFC 6265.NFr   tokenTc                 S   s   g | ]}t |qS r3   )rv   )rL   sr3   r3   r4   
<listcomp>;  s    z)CookieJar._parse_date.<locals>.<listcomp>F   c   il  E   i  r      iA     ;   r   )DATE_TOKENS_REfinditergroupDATE_HMS_TIME_REmatchgroupsDATE_DAY_OF_MONTH_RErv   DATE_MONTH_RE	lastindexDATE_YEAR_RErU   rW   rX   )clsr   
found_time	found_dayfound_month
found_yearhourminuteseconddaymonthyeartoken_matchr   
time_match	day_matchmonth_match
year_matchr3   r3   r4   rx   #  sh   

 zCookieJar._parse_dater   Nr   rG   ).__name__
__module____qualname____doc__recompiler   r   r   Ir   r   rU   maxr^   rW   rX   r+   utcfromtimestampr/   boolr   asyncioAbstractEventLoopr#   r   rA   rC   rE   rK   rv   rP   rH   strrh   r   r   r   r   r   staticmethodrt   r   classmethodrx   __classcell__r3   r3   r1   r4   r   "   s\    





N
,"r   c                       s   e Zd ZdZdddeej ddf fddZdd	d
Zde	fddZ
dddZe fdededdfddZdeddf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 r    )r"   r#   )r0   r   r1   r3   r4   r#   m  rQ   zDummyCookieJar.__init__rG   c                 c   s    d S rD   r3   rF   r3   r3   r4   rK   p  s   zDummyCookieJar.__iter__c                 C   s   dS )Nr   r3   rF   r3   r3   r4   rP   t     zDummyCookieJar.__len__c                 C      d S rD   r3   rF   r3   r3   r4   rE   w  r   zDummyCookieJar.clearrb   ri   c                 C   r   rD   r3   )r0   rb   ri   r3   r3   r4   r   z  r   zDummyCookieJar.update_cookiesr   r   c                 C   s   t  S rD   )r   )r0   r   r3   r3   r4   r   }  s   zDummyCookieJar.filter_cookiesr   r   )r   r   r   r   r   r   r   r#   rK   rv   rP   rE   r   r   r   r   r   r3   r3   r1   r4   r   f  s    "

r   )&r   rU   osr9   r<   r   collectionsr   http.cookiesr   r   r   typingr   r   r   r	   r
   r   r   r   r   r   yarlr   abcr   helpersr   r   typedefsr   r   __all__r   
CookieItemr   r   r3   r3   r3   r4   <module>   s&    0  F