U '7`/@sddlZddlZddlZddlZddlZddlZddlmZddlm Z m Z m Z ddl m Z mZmZmZmZmZmZmZmZmZddlmZddlmZddlmZmZdd lmZm Z d Z!ee"d fZ#Gd d d eZ$GdddeZ%dS)N) defaultdict) BaseCookieMorsel SimpleCookie) DefaultDictDictIterableIteratorMappingOptionalSetTupleUnioncast)URL)AbstractCookieJar) is_ip_addressnext_whole_second) LooseCookiesPathLike) CookieJarDummyCookieJar Morsel[str]csxeZdZdZedZedZedZedej Z edZ e j j je jjdZe j dZd d d d eeeejd d fddZed dddZed dddZd dddZddddZedddZd dddZ e j e!e!d dd d!Z"e#fe$e#d d"d#d$Z%e#fe#e&d%d&d'd(Z'e(e!e!ed)d*d+Z)e(e!e!ed,d-d.Z*e+e!ee j d/d0d1Z,Z-S)2rz/Implements cookie storage adhering to RFC 6265.z][\x09\x20-\x2F\x3B-\x40\x5B-\x60\x7B-\x7E]*(?P[\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})tzinfoiFTN)unsafe quote_cookieloop)rrrreturncsrtj|dtt|_t|_||_||_t |_ i|_ |j |_ z|j Wntk rl|j|_ YnXdSNr)super__init__rr_cookiesset_host_only_cookies_unsafe _quote_cookier_next_expiration _expirationsMAX_TIME _max_time timestamp OverflowErrorMAX_32BIT_TIME)selfrrr __class__D/opt/alt/python38/lib64/python3.8/site-packages/aiohttp/cookiejar.pyr#9szCookieJar.__init__) file_pathrc Cs8t|}|jdd}t|j|tjW5QRXdS)Nwbmode)pathlibPathopenpickledumpr$ZHIGHEST_PROTOCOLr0r5fr3r3r4savePs zCookieJar.savec Cs2t|}|jdd}t||_W5QRXdS)Nrbr7)r9r:r;r<loadr$r>r3r3r4rBUs zCookieJar.loadrcCs*|j|jt|_|jdSN)r$clearr&rr)r*r0r3r3r4rEZs  zCookieJar.clearIterator[Morsel[str]]ccs*||jD]}|EdHqdSrD)_do_expirationr$values)r0valr3r3r4__iter__`szCookieJar.__iter__cCstdd|DS)Ncss|] }dVqdS)rNr3).0ir3r3r4 fsz$CookieJar.__len__..)sumrFr3r3r4__len__eszCookieJar.__len__c Cstjtjj}|j|krdS|js(dS|j}g}|j}|j}|D]N\\}}}||kr|| |d| ||f|j ||fqFt ||}qF|D] } || =qz|jddtjdd|_Wntk r|j|_YnXdS)Nr) microsecondrseconds)datetimenowtimezoneutcr)r*r,r$itemspopappendr&discardminreplace timedeltar.) r0rUZnext_expirationZto_delcookiesZ expirationsdomainnamewhenkeyr3r3r4rHhs2   zCookieJar._do_expiration)rbr`rarcCs t|j||_||j||f<dSrD)r\r)r*)r0rbr`rar3r3r4_expire_cookieszCookieJar._expire_cookier_ response_urlrc Cs|j}|jst|rdSt|tr*|}|D]\}}t|tsXt}|||<||}|d}|drtd}|d=|s|dk r|j ||f|}|d<| dr|dd}||d<|r| ||sq.|d}|r| ds|j }| dsd}nd|d|d}||d<|d} | rzXt| } z tjtjjtj| d } Wntk rl|j} YnX|| ||Wntk rd|d<YnXn6|d } | r|| } | r|| ||nd|d <||j||<q.|dS) zUpdate cookies.Nr`.rpath/zmax-agerRexpires)raw_hostr'r isinstancer rXrrendswithr&add startswith_is_domain_matchrirfindintrTrUrVrWr^r.r,rd ValueError _parse_dater$rH)r0r_rfhostnameracookietmpr`riZmax_ageZ delta_secondsZmax_age_expirationrkZ expire_timer3r3r4update_cookiessh           zCookieJar.update_cookies)BaseCookie[str]zSimpleCookie[str] request_urlrc Cs|t|}|jrtnt}|jp*d}|jdk}|D]}|j}|d}|s\|j||<q:|j slt |rlq:||f|j kr||krq:n| ||sq:| |j|dsq:|r|drq:td||jt}||j|j|j|||<q:|S)z8Returns this jar's cookies filtered by their attributes.rh)httpswssr`riZsecurer)rHrr(rrrlschemercvaluer'rr&rq_is_path_matchrirgetrr%Z coded_value) r0r|filteredrvZ is_not_securerwrar`Zmrsl_valr3r3r4filter_cookiess6      zCookieJar.filter_cookies)r`rvrcCsD||kr dS||sdS|dt| }|ds:dSt| S)z0Implements domain matching adhering to RFC 6265.TFNrg)rnlenr)r`rv non_matchingr3r3r4rqs  zCookieJar._is_domain_match)req_path cookie_pathrcCsP|dsd}||krdS||s(dS|dr6dS|t|d}|dS)z.Implements path matching adhering to RFC 6265.rjTFN)rprnr)rrrr3r3r4rs   zCookieJar._is_path_match)date_strrc Cs|sdSd}d}d}d}d}}}d} d} d} |j|D]} | d} |s||j| }|r|d}dd|D\}}}q<|s|j| }|rd}t|} q<|s|j| }|rd}|j dk st |j } q<|s<|j | }|r;sz)CookieJar._parse_date..FcilEiriA;r)DATE_TOKENS_REfinditergroupDATE_HMS_TIME_REmatchgroupsDATE_DAY_OF_MONTH_RErs DATE_MONTH_RE lastindexAssertionError DATE_YEAR_RErTrVrW)clsrZ found_timeZ found_dayZ found_monthZ found_yearhourminuteseconddaymonthyearZ token_matchrZ time_matchZ day_matchZ month_matchZ year_matchr3r3r4ru#sn        (zCookieJar._parse_date).__name__ __module__ __qualname____doc__recompilerrrIrrrTmaxr]rVrWr+utcfromtimestampr/boolr asyncioAbstractEventLoopr#rr@rBrErKrsrPrHstrrdrrryrr staticmethodrqr classmethodru __classcell__r3r3r1r4r"sR    N ,rcseZdZdZddeejddfddZddd d Ze dd d Z ddd dZ e fe e ddddZe ddddZZS)rzxImplements a dummy cookie storage. It can be used with the ClientSession when no cookie processing is needed. Nr!)rrcstj|ddSr )r"r#)r0rr1r3r4r#mszDummyCookieJar.__init__rGrCccsdSrDr3rFr3r3r4rKpszDummyCookieJar.__iter__cCsdS)Nrr3rFr3r3r4rPtszDummyCookieJar.__len__cCsdSrDr3rFr3r3r4rEwszDummyCookieJar.clearrecCsdSrDr3)r0r_rfr3r3r4ryzszDummyCookieJar.update_cookiesrzr{cCstSrD)r)r0r|r3r3r4r}szDummyCookieJar.filter_cookies)rrrrr rrr#rKrsrPrErrryrrr3r3r1r4rfs r)&rrTosr9r<r collectionsrZ http.cookiesrrrtypingrrrr r r r r rrZyarlrabcrZhelpersrrZtypedefsrr__all__rZ CookieItemrrr3r3r3r4s$ 0   F