3 /fr+@s&ddddddddgZdd lZdd lZdd lZdd lZdd lZdd lZy dd lZ Wne k rldd l Z YnXdd l Z dd lmZd Zd ad d Zee jjZdZddZdZddZdddddddgZdddddd d!d"d#d$d%d&g ZgZxeD]Zejej qWdtd'd(Z!dud)d*Z"d d d d d+Z#ej$d,ej%Z&d-d.Z'd/d0Z(ej$d1ej%Z)ej$d2ej*ej%BZ+ej$d3ej,ej%BZ-d4d5Z.ej$d6ej,ej%BZ/d7d8Z0d9d:Z1ej$d;Z2ej$d<Z3ej$d=Z4ej$d>Z5d?d@Z6ej$dAZ7dBdCZ8dDdEZ9dFdGZ:ej$dHej%Z;dIdJZdOdPZ?ej$dQej%Z@dRdSZAdTdUZBdVdWZCdXdYZDdZZEej$d[ZFd\d]ZGd^d_ZHd`daZIdbdcZJGddddZKGdeddZLGdfddeLZMdgdhZNdidjZOGdkdldlZPGdmddZQGdnddeRZSGdoddeQZTdpdqZUGdrddeTZVGdsddeTZWd S)vCookie CookieJar CookiePolicyDefaultCookiePolicy FileCookieJar LWPCookieJar LoadErrorMozillaCookieJarN)timegmFcGs(tsdStsddl}|jdatj|S)Nr zhttp.cookiejar)debugloggerloggingZ getLogger)argsr r&/usr/lib64/python3.6/http/cookiejar.py_debug.s  rzQa filename was not supplied (nor was the CookieJar instance initialised with one)cCsJddl}ddl}ddl}|j}|jd||j}|jd|dddS)Nr zhttp.cookiejar bug! %s) stacklevel)iowarnings tracebackStringIO print_excgetvaluewarn)rrrfmsgrrr_warn_unhandled_exception<s  ricCs|dd\}}}}}}|tkrd|ko2dknrd|koJdknrd|kobdknrd|kozdknrd|kodknrt|SdSdS) N r ;=) EPOCH_YEARr )ttyearmonthZmdayhourminsecrrr_timegmKs 8Hr,ZMonZTueZWedZThuZFriZSatZSunZJanZFebZMarZAprZMayZJunZJulZAugZSepZOctZNovZDeccCs@|dkrtjj}n tjj|}d|j|j|j|j|j|jfS)Nz%04d-%02d-%02d %02d:%02d:%02dZ) datetimeutcnowutcfromtimestampr'r(dayr)minutesecond)tdtrrr time2isozYs   r5cCsR|dkrtjj}n tjj|}dt|j|jt|jd|j|j |j |j fS)Nz#%s, %02d-%s-%04d %02d:%02d:%02d GMTr) r-r.r/DAYSZweekdayr0MONTHSr(r'r)r1r2)r3r4rrr time2netscapels   r8)ZGMTUTCZUTZz^([-+])?(\d\d?):?(\d\d)?$cCsjd}|tkrd}nTtj|}|rfdt|jd}|jdrR|dt|jd}|jddkrf| }|S)Nr ir<r-) UTC_ZONES TIMEZONE_REsearchintgroup)tzoffsetmrrroffset_from_tz_strings  rFc Cst|}|tjkrdSytj|jd}WnXtk ry t|}Wntk r\dSXd|kopdknr||}ndSYnX|dkrd}|dkrd}|dkrd}t|}t|}t|}t|}|dkr0tjtjd}|d} |} ||| }| | } t | dkr0| dkr(|d}n|d}t |||||||f} | dk r|dkr^d}|j }t |} | dkr|dS| | } | S)Nrr r id2r9) rAr-ZMAXYEAR MONTHS_LOWERindexlower ValueErrortimeZ localtimeabsr,upperrF) r0monyrhrr*r+rCZimonZcur_yrrEZtmpr3rDrrr _str2timesV         rSzV^[SMTWF][a-z][a-z], (\d\d) ([JFMASOND][a-z][a-z]) (\d\d\d\d) (\d\d):(\d\d):(\d\d) GMT$z+^(?:Sun|Mon|Tue|Wed|Thu|Fri|Sat)[a-z]*,?\s*a^ (\d\d?) # day (?:\s+|[-\/]) (\w+) # month (?:\s+|[-\/]) (\d+) # year (?: (?:\s+|:) # separator before clock (\d\d?):(\d\d) # hour:min (?::(\d\d))? # optional seconds )? # optional clock \s* ([-+]?\d{2,4}|(?![APap][Mm]\b)[A-Za-z]+)? # timezone \s* (?:\(\w+\))? # ASCII representation of timezone in parens. \s*$c Cstj|}|rl|j}tj|djd}t|d|t|dt|dt|dt|df}t|S|j }t j d|d}dgd\}}}}}} } t j|}|dk r|j\}}}}}} } ndSt |||||| | S) Nrrr r;)STRICT_DATE_REr@groupsrIrJrKrAfloatr,lstrip WEEKDAY_REsubLOOSE_HTTP_DATE_RErS) textrEgrPr&r0rQrRr*r+rCrrr http2times " raa^ (\d{4}) # year [-\/]? (\d\d?) # numerical month [-\/]? (\d\d?) # day (?: (?:\s+|[-:Tt]) # separator before clock (\d\d?):?(\d\d) # hour:min (?::?(\d\d(?:\.\d*)?))? # optional seconds (and fractional) )? # optional clock \s* ([-+]?\d\d?:?(:?\d\d)? |Z|z)? # timezone (Z is "zero meridian", i.e. GMT) \s*$c Csd|j}dgd\}}}}}}}tj|}|dk rL|j\}}}}}}}} ndSt|||||||S)NrW)r[ ISO_DATE_REr@rYrS) r_r0rPrQrRr*r+rCrE_rrriso2time's  rdcCs*|jd\}}|jd||j|dS)Nr )spanstring)matchstartendrrr unmatchedHsrjz^\s*([^=\s;,]+)z&^\s*=\s*\"([^\"\\]*(?:\\.[^\"\\]*)*)\"z^\s*=\s*([^\s;,]*)z\\(.)c Cs g}x|D]}|}g}x|rtj|}|rt|}|jd}tj|}|rlt|}|jd}tjd|}n.tj|}|rt|}|jd}|j}nd}|j ||fq|j j dr|j dd}|r|j |g}qt j dd|\}} |}qW|r |j |q W|S)Nrz\1,z^[=\s;]*rV)HEADER_TOKEN_REr@rjrBHEADER_QUOTED_VALUE_REHEADER_ESCAPE_REr]HEADER_VALUE_RErstripappendr[ startswithresubn) Z header_valuesresultr_Z orig_textpairsrEnamevalueZnon_junkZ nr_junk_charsrrrsplit_header_wordsQs>.         ryz([\"\\])cCsg}xt|D]l}g}xN|D]F\}}|dk rTtjd|sHtjd|}d|}d||f}|j|qW|r |jdj|q Wdj|S)Nz^\w+$z\\\1z"%s"z%s=%sz; z, )rsr@HEADER_JOIN_ESCAPE_REr]rqjoin)Zlistsheadersrvattrkvrrrjoin_header_wordss     rcCs0|jdr|dd}|jdr,|dd}|S)N"r)rrendswith)r_rrr strip_quotess     rc Csd}g}x|D]}g}d}xt|jd D]\}}|j}|jd \}} } |j}|sd|d kr*Pnq*| rp| jnd} |d kr|j} | |kr| }|dkr| dk rt| } d }n|dkr| dk rtt| } |j|| fq*W|r|s|jd|j|qW|S)Nexpiresdomainpathsecureversionportmax-ageF;=r T0)rrrrrrr)rr) enumeratesplitstrip partitionrKrrarq) Z ns_headersZ known_attrsruZ ns_headerrv version_setZiiZparamkeysepvallcrrrparse_ns_headerss@   rz\.\d+$cCs:tj|rdS|dkrdS|ddks2|ddkr6dSdS)NFrVr .rTr)IPV4_REr@)r_rrris_HDN s rcCsl|j}|j}||krdSt|s(dS|j|}|dksB|dkrFdS|jdsTdSt|ddshdSdS)NTFrr rr)rKrrfindrr)ABirrr domain_matchs  rcCstj|rdSdS)NFT)rr@)r_rrrliberal_is_HDNBs rcCsb|j}|j}t|ot|s0||kr,dSdS|jd}|rL|j|rLdS| r^||kr^dSdS)NTFr)rKrrrr)rr initial_dotrrruser_domain_matchLs rz:\d+$cCsB|j}tjj|d}|dkr,|jdd}tjd|d}|jS)NrrVZHost) get_full_urlurllibparseZurlparseZ get_header cut_port_rer]rK)requesturlhostrrr request_hostas  rcCs6t|}}|jddkr.tj| r.|d}||fS)Nrrz.localr)rfindrr@)rerhnreq_hostrrreff_request_hostqs rcCs4|j}tjj|}t|j}|jds0d|}|S)N/)rrrZurlsplit escape_pathrrr)rrpartsrrrr request_path|s    rc Cs^|j}|jd}|dkrV||dd}y t|WqZtk rRtd|dSXnt}|S)N:r rznonnumeric port: '%s')rrrArLrDEFAULT_HTTP_PORT)rrrrrrr request_ports   rz%/;:@&=+$,!~*'()z%([0-9a-fA-F][0-9a-fA-F])cCsd|jdjS)Nz%%%sr)rBrO)rgrrruppercase_escaped_charsrcCstjj|t}tjt|}|S)N)rrZquoteHTTP_PATH_SAFEESCAPED_CHAR_REr]r)rrrrrs  rcCsP|jd}|dkrL||dd}|jd}t|rL|dksD|dkrLd|S|S)Nrr rZlocal)rr)hrbrrrreachs  rcCs$t|}t|t|jsdSdSdS)NTF)rrrZorigin_req_host)rrrrris_third_partys rc@sJeZdZdddZddZdddZd d Zdd d Zd dZddZ dS)rFcCs|dk rt|}| dk r$tt| } |dkr<|dkr)rrrrxrw)rplimitZ namevaluerrr__str__%s   zCookie.__str__cCspg}x,dD]$}t||}|jd|t|fq W|jdt|j|jdt|jd|jjdj|fS)Nrrwrxrrrrrrrrrrrrz%s=%szrest=%sz rfc2109=%sz%s(%s)z, )rrwrxrrrrrrrrrrrr)getattrrqreprrr __class____name__r{)rrrwr}rrr__repr__/s zCookie.__repr__)F)N)N) r __module__ __qualname__rrrrrrrrrrrrs    c@s,eZdZddZddZddZddZd S) rcCs tdS)N)NotImplementedError)rcookierrrrset_okGszCookiePolicy.set_okcCs tdS)N)r)rrrrrr return_okPszCookiePolicy.return_okcCsdS)NTr)rrrrrrdomain_return_okTszCookiePolicy.domain_return_okcCsdS)NTr)rrrrrrpath_return_okYszCookiePolicy.path_return_okN)rrrrrrrrrrrr>s  c @seZdZdZdZdZdZeeBZdddddddddeddf dd Zd d Z d d Z ddZ ddZ ddZ ddZddZddZddZddZddZd d!Zd"d#Zd$d%Zd&d'Zd(d)Zd*d+Zd,d-Zd.d/Zd0d1Zd2d3Zd4d5ZdS)6rrrrTr NTFc Csp||_||_||_||_||_||_| |_| |_| |_| |_ |dk rPt ||_ nf|_ |dk rft |}||_ dS)N) netscaperfc2965rfc2109_as_netscape hide_cookie2 strict_domainstrict_rfc2965_unverifiablestrict_ns_unverifiablestrict_ns_domainstrict_ns_set_initial_dollarstrict_ns_set_pathtuple_blocked_domains_allowed_domains) rblocked_domainsallowed_domainsrrrrrrrrrrrrrris  zDefaultCookiePolicy.__init__cCs|jS)N)r)rrrrrsz#DefaultCookiePolicy.blocked_domainscCst||_dS)N)rr)rrrrrset_blocked_domainssz'DefaultCookiePolicy.set_blocked_domainscCs"x|jD]}t||rdSqWdS)NTF)rr)rrZblocked_domainrrr is_blockeds  zDefaultCookiePolicy.is_blockedcCs|jS)N)r)rrrrrsz#DefaultCookiePolicy.allowed_domainscCs|dk rt|}||_dS)N)rr)rrrrrset_allowed_domainssz'DefaultCookiePolicy.set_allowed_domainscCs0|jdkrdSx|jD]}t||rdSqWdS)NFT)rr)rrZallowed_domainrrris_not_alloweds    z"DefaultCookiePolicy.is_not_allowedcCsBtd|j|jx,d D]$}d|}t||}|||sd SqWd S) Nz - checking cookie %s=%sr verifiabilityrwrrrZset_ok_FT)rrrwrrr)rrwrxr)rrrnfn_namefnrrrrs   zDefaultCookiePolicy.set_okcCs^|jdkrtd|j|jdS|jdkr<|j r third-party RFC 2965 cookie during unverifiable transactionFz> third-party Netscape cookie during unverifiable transactionT) unverifiablerrrrr)rrrrrrset_ok_verifiabilitysz(DefaultCookiePolicy.set_ok_verifiabilitycCs0|jdkr,|jr,|jjdr,td|jdSdS)Nr $z' illegal name (starts with '$'): '%s'FT)rrrwrrr)rrrrrr set_ok_names   zDefaultCookiePolicy.set_ok_namecCsL|jrHt|}|jdks(|jdkrH|jrH|j|j rHtd|j|dSdS)Nr z7 path attribute %s is not a prefix of request path %sFT)rrrrrrrr)rrrreq_pathrrr set_ok_paths  zDefaultCookiePolicy.set_ok_pathc Cs|j|jrtd|jdS|j|jr8td|jdS|jrt|\}}|j}|jr|jddkr|jd}|jdd|}|dkr||dd}||d|} | j d$krt |dkrtd|dS|j dr|dd} n|} | j ddk} | r|dkrtd|dS|j dkrb|j| rb|j d rbd|j| rbtd ||dS|j dks||j|j@rt||std!||dS|j dks|j|j@r|dt | } | j ddkrtj| rtd"| |dSd#S)%Nz" domain %s is in user block-listFz& domain %s is not in user allow-listrrr rcoaccomeduorgnetgovmilrAaerobizcatcoopinfojobsmobimuseumrwprotraveleuz& country-code second level domain %sz.localz/ non-local domain %s contains no embedded dotzO effective request-host %s (even with added initial dot) does not end with %sz5 effective request-host %s does not domain-match %sz. host prefix %s for domain %s contains a dotT)rrrrrrrrrArr r r r r rrrwrrr)rrrrrrrcountrrKlenrrrrrrDomainRFC2965MatchrDomainStrictNoDotsrr@) rrrrrrrjZtldZsldZundotted_domainZ embedded_dotsZ host_prefixrrr set_ok_domainsf            z!DefaultCookiePolicy.set_ok_domainc Cs|jrt|}|dkrd}nt|}x\|jjdD]:}y t|Wntk r`td|dSX||kr2Pq2Wtd||jdSdS)N80rkz bad port %s (not numeric)Fz$ request port (%s) not found in %sT)rrstrrrrArLr)rrrreq_portrrrr set_ok_port%s"   zDefaultCookiePolicy.set_ok_portcCsBtd|j|jx,d D]$}d|}t||}|||sd SqWd S) Nz - checking cookie %s=%srrrrrrZ return_ok_FT)rrrrrr)rrwrxr)rrrrrrrrrr:s    zDefaultCookiePolicy.return_okcCs@|jdkr|j rtddS|jdkr<|j r third-party RFC 2965 cookie during unverifiable transactionFz> third-party Netscape cookie during unverifiable transactionT)rrrrrr)rrrrrrreturn_ok_verifiabilityUsz+DefaultCookiePolicy.return_ok_verifiabilitycCs |jr|jdkrtddSdS)NZhttpsz( secure cookie with non-secure requestFT)rtyper)rrrrrrreturn_ok_secureasz$DefaultCookiePolicy.return_ok_securecCs|j|jrtddSdS)Nz cookie expiredFT)r_nowr)rrrrrrreturn_ok_expiresgs z%DefaultCookiePolicy.return_ok_expirescCsP|jrLt|}|dkrd}x0|jjdD]}||kr(Pq(Wtd||jdSdS)Nrrkz0 request port %s does not match cookie port %sFT)rrrr)rrrrrrrrreturn_ok_portms z"DefaultCookiePolicy.return_ok_portcCst|\}}|j}|r,|jd r,d|}n|}|jdkrb|j|j@rb|j rb||krbtddS|jdkrt|| rtd||dS|jdkrd|j | rtd||dSdS)Nrr zQ cookie with unspecified domain does not string-compare equal to request domainFzQ effective request-host name %s does not domain-match RFC 2965 cookie domain %sz; request-host %s does not match Netscape cookie domain %sT) rrrrrrDomainStrictNonDomainrrrr)rrrrrr dotdomainrrrreturn_ok_domain{s&    z$DefaultCookiePolicy.return_ok_domaincCst|\}}|jdsd|}|jds0d|}|rJ|jd rJd|}n|}|j|p`|j|sfdS|j|r~td|dS|j|rtd|dSdS)NrFz" domain %s is in user block-listz& domain %s is not in user allow-listT)rrrrrrr)rrrrrr%rrrrs"        z$DefaultCookiePolicy.domain_return_okcCs0td|t|}|j|s,td||dSdS)Nz- checking cookie path=%sz %s does not path-match %sFT)rrrr)rrrrrrrrs    z"DefaultCookiePolicy.path_return_ok)rrrrr$rZ DomainLiberalZ DomainStrictrrrrrrrrrrrrrrrrrr r"r#r&rrrrrrr_sJ    ;  cCst|j}t|j|S)N)sortedkeysmapr)Zadictr(rrrvals_sorted_by_keys r*c csZt|}xL|D]D}d}y |jWntk r4YnXd}t|EdH|s|VqWdS)NFT)r*itemsAttributeError deepvalues)mappingvaluesobjrrrr-s  r-c@s eZdZdS)AbsentN)rrrrrrrr1sr1c@seZdZejdZejdZejdZejdZejdZ ejdej Z d2dd Z d d Z d d ZddZddZddZddZddZddZddZddZddZd d!Zd"d#Zd3d$d%Zd&d'Zd(d)Zd*d+Zd,d-Zd.d/Zd0d1Z dS)4rz\Wz([\"\\])z\.?[^.]*z[^.]*z^\.+z^\#LWP-Cookies-(\d+\.\d+)NcCs(|dkrt}||_tj|_i|_dS)N)r_policy _threadingRLock _cookies_lock_cookies)rpolicyrrrrs  zCookieJar.__init__cCs ||_dS)N)r2)rr7rrr set_policyszCookieJar.set_policycCsg}|jj||sgStd||j|}xd|jD]X}|jj||sHq4||}x:|jD].}|jj||svtdqZtd|j|qZWq4W|S)Nz!Checking %s for cookies to returnz not returning cookiez it's a match) r2rrr6r(rr/rrq)rrrcookiesZcookies_by_pathrZcookies_by_namerrrr_cookies_for_domains   zCookieJar._cookies_for_domaincCs.g}x$|jjD]}|j|j||qW|S)N)r6r(extendr:)rrr9rrrr_cookies_for_requestszCookieJar._cookies_for_requestc CsF|jddddd}g}x$|D]}|j}|sLd}|dkrL|jd||jdk r~|jj|jr~|dkr~|jjd|j}n|j}|jdkr|j|jn|jd |j|f|dkr"|j r|jd |j |j j d r|j }|j o|j d r|d d}|jd ||jdk r"d}|jr4|d|j}|j|q"W|S)NcSs t|jS)N)rr)arrrsz)CookieJar._cookie_attrs..T)rreverseFr z $Version=%sz\\\1z%s=%sz $Path="%s"rrz $Domain="%s"z$Portz="%s")sortrrqrx non_word_rer@quote_rer]rwrrrrrrrr) rr9rattrsrrrxrrrrr _cookie_attrss>      zCookieJar._cookie_attrsc Cstd|jjzttj|j_|_|j|}|j|}|r^|j ds^|j ddj ||jj r|jj r|j d rx$|D]}|jdkr|j ddPqWWd|jjX|jdS)Nadd_cookie_headerrz; ZCookie2rz $Version="1")rr5acquirerArMr2r!r<rDZ has_headerZadd_unredirected_headerr{rrrreleaseclear_expired_cookies)rrr9rCrrrrrE?s$          zCookieJar.add_cookie_headercCsg}d}d}x||D]r}|d \}}d }d } i} i} x4|d dD]"\} } | j}||ksh||krl|} | |kr| dkrd} | | krqF| dkr| dkrtdd} P| j} | dkr|rqF| dkrtdqF| dkrd}y t| } Wn$tk rtdd} PYnXd} |j| } | |ks2| |krb| dkrX| dkrXtd| d} P| | | <qF| | | <qFW| rvq|j||| | fqW|S)Nrrrrmax-agerrrr commenturlr FrTz% missing value for domain attributezM missing or invalid value for expires attribute: treating as session cookiez? missing or invalid (non-numeric) value for max-age attributez! missing value for %s attribute)rr)rrrIrrrrrJ)rrrJ)rKrrArLr!rq)r attrs_set cookie_tuples boolean_attrs value_attrsZ cookie_attrsrwrxZ max_age_setZ bad_cookiestandardrr~rrrrr_normalized_cookie_tuples`sl          z#CookieJar._normalized_cookie_tuplesc!Cs$|\}}}}|jdt}|jdt}|jdt} |jdt} |jdd} | dk rry t| } Wntk rpdSX|jdd} |jdd} |jd d}|jd d}|tk r|d krd }t|}nXd}t|}|jd }|dkr| dkr|d|}n|d|d}t|dkrd }|tk }d}|r8t|j d}|tkrTt |\}}|}n|j dshd|}d}| tk r| dkrt |} nd }t j dd | } nd} | tkrd} d } nH| |jkry|j|||Wntk rYnXtd|||dSt| ||| ||||||| | | |||S)NrrrrrrFrrrJrVTrrr rz\s+z2Expiring cookie, domain='%s', path='%s', name='%s'r)rr1rArLrrrrboolrrrrrsr]r!clearKeyErrorrr)rtuprrwrxrOrrrrrrrrrrrrrrrrrrrr_cookie_from_cookie_tuples                       z#CookieJar._cookie_from_cookie_tuplecCs:|j|}g}x&|D]}|j||}|r|j|qW|S)N)rPrUrq)rrKrrLr9rTrrrr_cookies_from_attrs_sets   z!CookieJar._cookies_from_attrs_setcCsLt|jdd}|dkr |jj }x&|D]}|jdkr&d|_|r&d|_q&WdS)NrrTr )rr2rrr)rr9Z rfc2109_as_nsrrrr_process_rfc2109_cookies&s   z"CookieJar._process_rfc2109_cookiesc Cs6|j}|jdg}|jdg}|jj}|jj}| r<| s`| rH| s`| rT| s`| rd| rdgSy|jt||}Wntk rtg}YnX|o|r2y|jt ||} Wntk rtg} YnX|j | |r"i} x |D]} d| | j | j | j f<qW| fdd} t| | } | r2|j| |S)Nz Set-Cookie2z Set-CookiecSs|j|j|jf}||kS)N)rrrw)Z ns_cookielookuprrrrno_matching_rfc2965^sz3CookieJar.make_cookies..no_matching_rfc2965)r Zget_allr2rrrVry ExceptionrrrWrrrwfilterr;) rresponserr|Z rfc2965_hdrsZns_hdrsrrr9Z ns_cookiesrXrrYrrr make_cookies2sB              zCookieJar.make_cookiesc CsN|jjz2ttj|j_|_|jj||r:|j|Wd|jjXdS)N) r5rFrArMr2r!r set_cookierG)rrrrrrset_cookie_if_okhs  zCookieJar.set_cookie_if_okc Csl|j}|jjzJ|j|kr&i||j<||j}|j|krDi||j<||j}|||j<Wd|jjXdS)N)r6r5rFrrrwrG)rrcZc2Zc3rrrr^us     zCookieJar.set_cookiec Cs|td|j|jjzRttj|j_|_x6|j||D]&}|jj ||r>td||j |q>WWd|jj XdS)Nzextract_cookies: %sz setting cookie: %s) rr r5rFrArMr2r!r]rr^rG)rr\rrrrrextract_cookiess  zCookieJar.extract_cookiescCst|dk r2|dks|dkr td|j|||=n>|dk rX|dkrJtd|j||=n|dk rj|j|=ni|_dS)Nz8domain and path must be given to remove a cookie by namez.domain must be given to remove cookies by path)rLr6)rrrrwrrrrRs  zCookieJar.clearc CsH|jjz,x&|D]}|jr|j|j|j|jqWWd|jjXdS)N)r5rFrrRrrrwrG)rrrrrclear_session_cookiess   zCookieJar.clear_session_cookiesc CsT|jjz8tj}x*|D]"}|j|r|j|j|j|jqWWd|jjXdS)N) r5rFrMrrRrrrwrG)rrrrrrrHs   zCookieJar.clear_expired_cookiescCs t|jS)N)r-r6)rrrr__iter__szCookieJar.__iter__cCsd}x|D] }|d}q W|S)Nr rr)rrrrrr__len__s zCookieJar.__len__cCs6g}x|D]}|jt|q Wd|jjdj|fS)Nz<%s[%s]>z, )rqrrrr{)rrrrrrrs zCookieJar.__repr__cCs6g}x|D]}|jt|q Wd|jjdj|fS)Nz<%s[%s]>z, )rqrrrr{)rrerrrrrs zCookieJar.__str__)N)NNN)!rrrrscompilerArBZstrict_domain_reZ domain_reZdots_reASCIImagic_rerr8r:r<rDrErPrUrVrWr]r_r^rarRrbrHrcrdrrrrrrrs6      ;!a\  6   c@s eZdZdS)rN)rrrrrrrrsc@s4eZdZd ddZd ddZd ddZdd d ZdS)rNFc CsJtj|||dk r6y |dWntdYnX||_t||_dS)NrVzfilename must be string-like)rrrLfilenamerQ delayload)rrirjr7rrrrs  zFileCookieJar.__init__cCs tdS)N)r)rriignore_discardignore_expiresrrrsaveszFileCookieJar.savec CsJ|dkr"|jdk r|j}nttt|}|j||||WdQRXdS)N)rirLMISSING_FILENAME_TEXTopen _really_load)rrirkrlrrrrloads   zFileCookieJar.loadcCs|dkr"|jdk r|j}ntt|jjzFtj|j}i|_y|j|||Wnt k rn||_YnXWd|jj XdS)N) rirLrnr5rFrdeepcopyr6rqOSErrorrG)rrirkrlZ old_staterrrreverts    zFileCookieJar.revert)NFN)NFF)NFF)NFF)rrrrrmrqrtrrrrrs    cCs$|j|jfd|jfd|jfg}|jdk r8|jd|jf|jrH|jd |jrX|jd|jrh|jd|j rx|jd|j r|jdt t |j f|j r|jd|jr|jd |jf|jr|jd |jft|jj}x$|D]}|j|t|j|fqW|jd t|jft|gS)Nrrr path_spec port_spec domain_dotrrrrrJr)ruN)rvN)rwN)rN)rN)rwrxrrrrqrrrrrr5rZrrrr'rr(rrr)rrr(r~rrrlwp_cookie_strs6         rxc@s(eZdZd ddZd ddZdd ZdS) rTcCs\tj}g}x>|D]6}| r$|jr$q| r6|j|r6q|jdt|qWdj|dgS)NzSet-Cookie3: %s rV)rMrrrqrxr{)rrkrlrrerrrr as_lwp_strGs  zLWPCookieJar.as_lwp_strNFc CsX|dkr"|jdk r|j}nttt|d"}|jd|j|j||WdQRXdS)Nwz#LWP-Cookies-2.0 )rirLrnrowriterz)rrirkrlrrrrrmWs   zLWPCookieJar.savecCsL|j}|jj|s$d|}t|tj}d}d} d} yʐx|j} | dkrRP| j|s^q@| t|dj} xt| gD]x} | d\} }i}i}x| D] }d||<qWx| ddD]t\}}|dk r|j }nd}|| ks|| kr|}|| kr|dkr d}|||<q|| kr*|||<q|||<qW|j }|d }|d}|dk r^t |}|dkrld}|d }|jd}t |d| ||d |d|||d|d |d|d|||d |d|}| r|j rq| r|j|rq|j|qWq@WWnBtk rYn,tk rFttd|| fYnXdS)Nz5%r does not look like a Set-Cookie3 (LWP) format filez Set-Cookie3:rvrurwrrrrrrrrrJrVr FrTrz&invalid Set-Cookie3 format file %r: %r)rvrurwrr)rrrrrrrJ)readlinerhr@rrMrrrrryrKrrdrrrr^rsrZr)rrrirkrlmagicrrheaderrMrNlinedatarwrxrOrr~rrrrrrrr`rrrrpcs                   zLWPCookieJar._really_load)TT)NFF)rrrrzrmrprrrrr:s  c@s,eZdZejdZdZddZd ddZdS) rz#( Netscape)? HTTP Cookie Filezr# Netscape HTTP Cookie File # http://curl.haxx.se/rfc/cookie_spec.html # This is a generated file! Do not edit. cCsntj}|j}|jj|s(td|yx|j}|dkr@P|jdrV|dd}|jjds.|jdkrrq.|jd\}} } } } } }| dk} | dk} | dkr|} d}|jd }d }| dkrd} d }t d | |dd || || d | | |ddi}| r|j rq.| r|j |rq.|j |q.WWnBt k r>Yn,tk rhttd ||fYnXdS)Nz4%r does not look like a Netscape format cookies filerVryr#r TRUErFTr z+invalid Netscape format cookies file %r: %rr)rr)rMr}rhr@rrrrrrrrrr^rsrZr)rrrirkrlrr~rrrrrrrwrxrrr`rrrrps`    zMozillaCookieJar._really_loadNFc Cs|dkr"|jdk r|j}nttt|d}|j|jtj}x|D]}| rZ|jrZqH| rl|j|rlqH|j rxd}nd}|j j drd}nd}|j dk rt |j } nd} |jdkrd} |j} n |j} |j} |jdj|j ||j|| | | gdqHWWdQRXdS)Nr{rZFALSErrVrry)rirLrnror|rrMrrrrrrrrrxrwr{r) rrirkrlrrrrrrrwrxrrrrms<          zMozillaCookieJar.save)NFF) rrrrsrfrhrrprmrrrrrs A)N)N)X__all__rr-rsrMZ urllib.parserZurllib.requestZ threadingr3 ImportErrorZdummy_threadingZ http.clientZhttpZcalendarr r r rrZclientZ HTTP_PORTrrnrr%r,r6r7rIr(rqrKr5r8r>rfrgr?rFrSrXIr\Xr^rarbrdrjrlrmrornryrzrrrrrrrrrrrrrrrrrrrrrrr*r-r1rrsrrrxrrrrrrs        88!    U D'    #b!\:x