\d.dZgdZddlZddlZddlZddlZddlZddlZddl Zddl Z ddl Z ddlmZdZdadZdZdZee jjZejd Zd Zd Zd Zd ZdZgdZ gdZ!de!DZ"dLdZ#dLdZ$dddddZ%ejdej&Z'dZ(dZ)ejdej&Z*ejdej+ej&zZ,ejdej-ej&zZ.dZ/ejdej-ej&zZ0dZ1dZ2ejdZ3ejd Z4ejd!Z5ejd"Z6d#Z7ejd$Z8d%Z9d&Z:d'Z;ejd(ej&Zd+Z?d,Z@ejd-ej&ZAd.ZBd/ZCd0ZDd1ZEd2ZFejd3ZGd4ZHd5ZId6ZJd7ZKGd8d9ZLGd:d;ZMGd<d=eMZNd>ZOGd?d@ZPGdAdBZQGdCdDeRZSGdEdFeQZTdGZUGdHdIeTZVGdJdKeTZWdS)MaHTTP cookie handling for web clients. This module has (now fairly distant) origins in Gisle Aas' Perl module HTTP::Cookies, from the libwww-perl library. Docstrings, comments and debug strings in this code refer to the attributes of the HTTP cookie system as cookie-attributes, to distinguish them clearly from Python attributes. Class diagram (note that BSDDBCookieJar and the MSIE* classes are not distributed with the Python standard library, but are available from http://wwwsearch.sf.net/): CookieJar____ / \ \ FileCookieJar \ \ / | \ \ \ MozillaCookieJar | LWPCookieJar \ \ | | \ | ---MSIEBase | \ | / | | \ | / MSIEDBCookieJar BSDDBCookieJar |/ MSIECookieJar )Cookie CookieJar CookiePolicyDefaultCookiePolicy FileCookieJar LWPCookieJar LoadErrorMozillaCookieJarN)timegmFcptsdStsddl}|datj|S)Nr zhttp.cookiejar)debugloggerlogging getLogger)argsrs ..\python\lib\http\cookiejar.py_debugr,sA  5""#344 < HTTPOnlyz #HttpOnly_z#( Netscape)? HTTP Cookie FilezQa filename was not supplied (nor was the CookieJar instance initialised with one)zr# Netscape HTTP Cookie File # http://curl.haxx.se/rfc/cookie_spec.html # This is a generated file! Do not edit. cddl}ddl}ddl}|}|d||}|d|zddS)Nr zhttp.cookiejar bug! %s) stacklevel)iowarnings tracebackStringIO print_excgetvaluewarn)rrrfmsgs r_warn_unhandled_exceptionr"Bsz#""""""""""" A a   **,,C MM+c1aM@@@@@ric|dd\}}}}}}|tkr_d|cxkrdkrRnnOd|cxkrdkrBnn?d|cxkrdkr2nn/d|cxkrdkr"nnd|cxkrdkrnnt|SdS) N r ;=) EPOCH_YEARr )ttyearmonthmdayhourminsecs r_timegmr3Qs(*2A2%D%tS#   !u"2"2"2"2"2"2"2"2"2db dbqC~~~~2~~~~~ANNNNNNNNNbzztr)MonTueWedThuFriSatSun) JanFebMarAprMayJunJulAugSepOctNovDecc6g|]}|S)lower).0r.s r rK\s 222% 222rc|tj}ntj|}d|j|j|j|j|j|jfzS)aHReturn a string representing time in seconds since epoch, t. If the function is called without an argument, it will use the current time. The format of the returned string is like "YYYY-MM-DD hh:mm:ssZ", representing Universal Time (UTC, aka GMT). An example of this format is: 1994-11-24 08:49:37Z Nz%04d-%02d-%02d %02d:%02d:%02dZ) datetimeutcnowutcfromtimestampr-r.dayr0minutesecondtdts r time2isozrV^sc y   % % ' '   / / 2 2 + 2627BIry/B BBrc,|tj}ntj|}dt||jt |jdz |j|j |j |j fzS)zReturn a string representing time in seconds since epoch, t. If the function is called without an argument, it will use the current time. The format of the returned string is like this: Wed, DD-Mon-YYYY HH:MM:SS GMT Nz#%s, %02d-%s-%04d %02d:%02d:%02d GMTr%) rMrNrODAYSweekdayrPMONTHSr.r-r0rQrRrSs r time2netscaper[qsy y   % % ' '   / / 2 2 0 RZZ\\BFF28A:$6 ")RY40 00r)GMTUTCUTZz^([-+])?(\d\d?):?(\d\d)?$cVd}|tvrd}nt|}|r~dt|dz}|dr(|dt|dzz}|ddkr| }|S)Nr ir<r%-) UTC_ZONES TIMEZONE_REsearchintgroup)tzoffsetms roffset_from_tz_stringrls F Y   r " "  !C OO+Fwwqzz 7"s1771::"66wwqzzS    Mrc .t|}|tjkrdS t|dz}nI#t $r< t|}n#t $rYYdSwxYwd|cxkrdkrnn|}nYdSYnwxYw|d}|d}|d}t|}t|}t|}t|}|dkrctjtjd}|dz} |} ||z| z }| | z } t| dkr| dkr|dz}n|dz }t|||||||f} | 0|d}| }t|} | dS| | z } | S)Nr%r&r id2r]) rgrMMAXYEAR MONTHS_LOWERindexrI ValueErrortime localtimeabsr3upperrl) rPmonyrhrr1r2riimoncur_yrrktmprTrjs r _str2timer~s RB H t   --a/     s88DD   444  ?????????CC44 C  z2 {!C {!C c((C RB c((C c((C Dyy ,,Q/ SL &[1_ G q66B;;1uu28bbCx" S#r3R011A} :B XXZZ&r** >4 J Hs5/A BA.-B. A=8B<A==BBzV^[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 t|}|r|}t|ddz}t |d|t |dt |dt |dt|df}t|S| }t d|d}dgd z\}}}}}} } t|}||\}}}}}} } ndSt|||||| | S) aReturns time in seconds since epoch of time represented by a string. Return value is an integer. None is returned if the format of str is unrecognized, the time is outside the representable range, or the timezone string is not recognized. If the string contains no timezone, UTC is assumed. The timezone in the string may be numerical (like "-0800" or "+0100") or a string timezone (like "UTC", "GMT", "BST" or "EST"). Currently, only the timezone strings equivalent to UTC (zero offset) are known to the function. The function loosely parses the following formats: Wed, 09 Feb 1994 22:23:32 GMT -- HTTP format Tuesday, 08-Feb-94 14:15:29 GMT -- old rfc850 HTTP format Tuesday, 08-Feb-1994 14:15:29 GMT -- broken rfc850 HTTP format 09 Feb 1994 22:23:32 GMT -- HTTP format (no weekday) 08-Feb-94 14:15:29 GMT -- rfc850 format (no weekday) 08-Feb-1994 14:15:29 GMT -- broken rfc850 format (no weekday) The parser ignores leading and trailing whitespace. The time may be absent. If the year is given with only 2 digits, the function will select the century that makes the year closest to the current date. r%rr raN)STRICT_DATE_RErfgroupsrqrrrIrgfloatr3lstrip WEEKDAY_REsubLOOSE_HTTP_DATE_REr~) textrkgrxr,rPryrzr1r2ris r http2timers:< d##A HHJJ  1..2!A$iic!A$ii!A$iiQqTE!A$KK1r{{ ;;==D >>"dA & &D'+VAX"Cb"c3 !!$''A})*&S"b#sBBt S#r2sC 4 44ra^ (\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 |}dgdz\}}}}}}}t|}||\}}}}}}}} ndSt |||||||S)av As for http2time, but parses the ISO 8601 formats: 1994-02-03 14:15:29 -0100 -- ISO 8601 format 1994-02-03 14:15:29 -- zone is optional 1994-02-03 -- only date 1994-02-03T14:15:29 -- Use T as separator 19940203T141529Z -- ISO 8601 compact format 19940203 -- only date Nr)r ISO_DATE_RErfrr~) rrPrxryrzr1r2rirk_s riso2timer2s ;;==D'+VAX"Cb"c3 4  A}-.HHJJ)Cb#sBt S#r2sC 4 44rcp|d\}}|jd||j|dzS)z)Return unmatched part of re.Match object.r N)spanstring)matchstartends r unmatchedrSs6AJE3 <  STT 2 22rz^\s*([^=\s;,]+)z&^\s*=\s*\"([^\"\\]*(?:\\.[^\"\\]*)*)\"z^\s*=\s*([^\s;,]*)z\\(.)ct|trJg}|D]}|}g}|rt|}|rt |}|d}t |}|r@t |}|d}td|}nWt|}|r9t |}|d}| }nd}| ||fn| dr6| dd}|r| |g}n4tjdd|\}} | dksJd|d |d ||}||r| ||S) amParse header values into a list of lists containing key,value pairs. The function knows how to deal with ",", ";" and "=" as well as quoted values after "=". A list of space separated tokens are parsed as if they were separated by ";". If the header_values passed as argument contains multiple values, then they are treated as if they were a single value separated by comma ",". This means that this function is useful for parsing header fields that follow this syntax (BNF as from the HTTP/1.1 specification, but we relax the requirement for tokens). headers = #header header = (token | parameter) *( [";"] (token | parameter)) token = 1* separators = "(" | ")" | "<" | ">" | "@" | "," | ";" | ":" | "\" | <"> | "/" | "[" | "]" | "?" | "=" | "{" | "}" | SP | HT quoted-string = ( <"> *(qdtext | quoted-pair ) <"> ) qdtext = > quoted-pair = "\" CHAR parameter = attribute "=" value attribute = token value = token | quoted-string Each header is represented by a list of key/value pairs. The value for a simple token (not part of a parameter) is None. Syntactically incorrect headers will not necessarily be parsed as you would want. This is easier to describe with some examples: >>> split_header_words(['foo="bar"; port="80,81"; discard, bar=baz']) [[('foo', 'bar'), ('port', '80,81'), ('discard', None)], [('bar', 'baz')]] >>> split_header_words(['text/html; charset="iso-8859-1"']) [[('text/html', None), ('charset', 'iso-8859-1')]] >>> split_header_words([r'Basic realm="\"foo\bar\""']) [[('Basic', None), ('realm', '"foobar"')]] r%z\1N,z^[=\s;]*rr zsplit_header_words bug: 'z', 'z', ) isinstancestrHEADER_TOKEN_RErfrrhHEADER_QUOTED_VALUE_REHEADER_ESCAPE_RErHEADER_VALUE_RErstripappendr startswithresubn) header_valuesresultr orig_textpairsrknamevaluenon_junk nr_junk_charss rsplit_header_wordsr\sZ------ F#'#'  &&t,,A  ||wwqzz*11$77 %$Q<>EE'..t44A%(|| !  % !% dE]++++))#.. {{}}QRR(.&--...+-'+r4*H*H'-$q((((YYee-)(( ? @ &&--&&& Mr([\"\\])cHg}|D]}g}|D]X\}}|>> join_header_words([[("text/plain", None), ("charset", "iso-8859-1")]]) 'text/plain; charset="iso-8859-1"' >>> join_header_words([[("text/plain", None)], [("charset", "iso-8859-1")]]) 'text/plain, charset="iso-8859-1"' Nz^\w+$\\\1z"%s"=; , )rrfHEADER_JOIN_ESCAPE_RErrjoin)listsheadersrattrkvs rjoin_header_wordsrsG 1 1  DAq}y1--#-11'1==A A qq!!$ KKNNNN 0 $000 99W  rc|dr |dd}|dr |dd}|S)N"r%)rendswithrs r strip_quotesrsI sABBx }}SCRCy Krcd}g}|D]6}g}d}t|dD]\}}|}|d\}} } |}|s |dkrnQ| r| nd} |dkrX|} | |vr| }|dkr| t | } d}n$|d kr| t t | } ||| f|r,|s|d ||8|S) a5Ad-hoc parser for Netscape protocol cookie-attributes. The old Netscape cookie format for Set-Cookie can for instance contain an unquoted "," in the expires field, so we have to use this ad-hoc parser instead of split_header_words. XXX This may not make the best possible effort to parse all the crap that Netscape Cookie headers contain. Ronald Tschalar's HTTPClient parser is probably better, so could do worse than following that if this ever gives any trouble. Currently, this is also used for parsing RFC 2109 cookies. )expiresdomainpathsecureversionportmax-ageF;rr NrTr)r0) enumeratesplitstrip partitionrIrrr) ns_headers known_attrsr ns_headerr version_setiiparamkeysepvallcs rparse_ns_headersrsw1KF+!+!  #9??3#7#788 % %IBKKMME!OOC00MCc))++C 77E"%.#))+++$CQwwYY[[$$C)##*3//"&KKI%%' S(9(9:: LL#s $ $ $ $  ! / -... MM% Mrz\.\d+$ct|rdS|dkrdS|ddks |ddkrdSdS)z*Return True if text is a host domain name.Frr .rTIPV4_RErfrs ris_HDNrsN~~du rzzu Aw#~~bSu 4rc.|}|}||krdSt|sdS||}|dks|dkrdS|dsdSt|ddsdSdS)aReturn True if domain A domain-matches domain B, according to RFC 2965. A and B may be host domain names or IP addresses. RFC 2965, section 1: Host names can be specified either as an IP address or a HDN string. Sometimes we compare one host name with another. (Such comparisons SHALL be case-insensitive.) Host A's name domain-matches host B's if * their host name strings string-compare equal; or * A is a HDN string and has the form NB, where N is a non-empty name string, B has the form .B', and B' is a HDN string. (So, x.y.com domain-matches .Y.com but not Y.com.) Note that domain-match is not a commutative operation: a.b.c.com domain-matches .c.com, but not the reverse. TFrr rr%N)rIrrfindr)ABis r domain_matchr&s.  A  AAvvt !99u  ABww!q&&u <<  u !ABB%==u 4rc>t|rdSdS)zdReturn True if text is a sort-of-like a host domain name. For accepting/blocking domains. FTrrs rliberal_is_HDNrMs" ~~du 4rc|}|}t|rt|s ||krdSdS|d}|r||rdS|s||krdSdS)z\For blocking/accepting domains. A and B may be host domain names or IP addresses. TFr)rIrrr)rr initial_dots ruser_domain_matchrWs  A  A 1  ."3"3 664u,,s##Kqzz!}}t 166t 5rz:\d+$c |}tj|d}|dkr|dd}t d|d}|S)zReturn request-host, as defined by RFC 2965. Variation from RFC: returned value is lowercased, for convenient comparison. r%rHost) get_full_urlurllibparseurlparse get_header cut_port_rerrI)requesturlhosts r request_hostrlsr    C <  % %a (D rzz!!&"-- ??2tQ ' 'D ::<<rct|x}}|ddkrt|s|dz}||fS)zzReturn a tuple (request-host, effective request-host name). As defined by RFC 2965, except both are lowercased. rr.local)rfindrrf)rerhnreq_hosts reff_request_hostr|sR #7+++D8}}SRx(@(@(" T>rc|}tj|}t |j}|dsd|z}|S)z6Path component of request-URI, as defined by RFC 2965./)rrrurlsplit escape_pathrr)rrpartsrs r request_pathrsY    C L ! !# & &E uz " "D ??3  Tz Krc|j}|d}|dkr?||dzd} t|n(#t$rt d|YdSwxYwt }|S)N:r r%znonnumeric port: '%s')rrrgrsrDEFAULT_HTTP_PORT)rrrrs r request_portrs >> reach("www.acme.com") '.acme.com' >>> reach("acme.com") 'acme.com' >>> reach("acme.local") '.local' rr r%Nlocal)rr)hrbs rreachrsh4 s AAvv acddG FF3KK !99 !q&&ALLq5L Hrclt|}t|t|jsdSdS)z RFC 2965, section 3.3.6: An unverifiable transaction is to a third-party host if its request- host U does not domain-match the reach R of the request-host O in the origin transaction. TF)rrrorigin_req_host)rrs ris_third_partyrs8G$$H %(?"@"@ A AturcDeZdZdZ d dZdZd dZdZd dZd Z d Z dS) raHTTP Cookie. This class represents both Netscape and RFC 2965 cookies. This is deliberately a very simple class. It just holds attributes. It's possible to construct Cookie instances that don't comply with the cookie standards. CookieJar.make_cookies is the factory function for Cookie objects -- it deals with cookie parsing, supplying defaults, and normalising to the representation used in this class. CookiePolicy is responsible for checking them to see whether they should be accepted from and returned to the server. Note that the port may be present in the headers, but unspecified ("Port" rather than"Port=80", for example); if this is the case, port is None. Fc|t|}| tt| } ||durtd||_||_||_||_||_||_ ||_ ||_ | |_ | |_ | |_| |_| |_||_||_||_t)j||_dS)NTz-if port is None, port_specified must be false)rgrrsrrrrport_specifiedrIrdomain_specifieddomain_initial_dotrpath_specifiedrrdiscardcomment comment_urlrfc2109copy_rest)selfrrrrrrrrrrrrrrrrestrs r__init__zCookie.__init__s  #g,,  #eGnn*=*= +>4urc|jd}n d|jz}|j|z|jz}|j|jd|j}n|j}d|d|dS)Nrrrz)rrrrr)r"plimit namevalues r__str__zCookie.__str__0sf 9 "aadi-a a$)+ : !#'999djj9II I'0yy%%%88rcpg}dD]9}t||}||dt|:|dt|jz|dt|jz|jjdd|dS)N)rrrrrrrrrrrrrrrrzrest=%sz rfc2109=%s(r))getattrrreprr!r __class____name__r)r"rrrs r__repr__zCookie.__repr__:s 6 6D 4&&D KK444d4 5 5 5 5 ITZ 0 00111 L4 #5#55666>222DIIdOOOODDr)Fr&) r? __module__ __qualname____doc__r$r(r,r.r2r8r@rHrrrrs6(%(%(%(%T"""----!!! 999 E E E E Errc*eZdZdZdZdZdZdZdS)ra Defines which cookies get accepted from and returned to server. May also modify cookies, though this is probably a bad idea. The subclass DefaultCookiePolicy defines the standard rules for Netscape and RFC 2965 cookies -- override that if you want a customized policy. ct)zReturn true if (and only if) cookie should be accepted from server. Currently, pre-expired cookies never get this far -- the CookieJar class deletes such cookies itself. NotImplementedErrorr"cookiers rset_okzCookiePolicy.set_okRs"###rct)zAReturn true if (and only if) cookie should be returned to server.rFrHs r return_okzCookiePolicy.return_ok[!###rcdS)zMReturn false if cookies should not be returned, given cookie domain. TrH)r"rrs rdomain_return_okzCookiePolicy.domain_return_ok_ trcdS)zKReturn false if cookies should not be returned, given cookie path. TrH)r"rrs rpath_return_okzCookiePolicy.path_return_okdrPrN)r?rArBrCrJrLrOrRrHrrrrIsZ$$$$$$ rrc eZdZdZdZdZdZdZeezZdddddddddeddd f d Z d Z d Z d Z dZ dZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZd ZdS)!rzBImplements the standard rules for accepting and returning cookies.r%rrr NTF)httpswssc ||_||_||_||_||_||_| |_| |_| |_| |_ | |_ |t||_ nd|_ |t|}||_ dS)zAConstructor arguments should be passed as keyword arguments only.NrH)netscaperfc2965rfc2109_as_netscape hide_cookie2 strict_domainstrict_rfc2965_unverifiablestrict_ns_unverifiablestrict_ns_domainstrict_ns_set_initial_dollarstrict_ns_set_pathsecure_protocolstuple_blocked_domains_allowed_domains)r"blocked_domainsallowed_domainsrWrXrYrZr[r\r]r^r_r`ras rr$zDefaultCookiePolicy.__init__ts!  #6 (*+F(&<# 0,H)"4 0  &$)/$:$:D ! !$&D !  &#O44O /rc|jS)z4Return the sequence of blocked domains (as a tuple).)rcr"s rrez#DefaultCookiePolicy.blocked_domains $$rc.t||_dS)z$Set the sequence of blocked domains.N)rbrc)r"res rset_blocked_domainsz'DefaultCookiePolicy.set_blocked_domainss %o 6 6rc@|jD]}t||rdSdSr0)rcr)r"rblocked_domains r is_blockedzDefaultCookiePolicy.is_blockeds7"3  N 88 tt urc|jS)z=Return None, or the sequence of allowed domains (as a tuple).)rdrhs rrfz#DefaultCookiePolicy.allowed_domainsrirc6|t|}||_dS)z-Set the sequence of allowed domains, or None.N)rbrd)r"rfs rset_allowed_domainsz'DefaultCookiePolicy.set_allowed_domainss#  &#O44O /rcR|jdS|jD]}t||rdSdS)NFT)rdr)r"rallowed_domains ris_not_allowedz"DefaultCookiePolicy.is_not_allowedsE  (5"3  N 88 uu trctd|j|j|jJdD]&}d|z}t||}|||sdS'dS)z If you override .set_ok(), be sure to call this method. If it returns false, so should your subclass (assuming your subclass wants to be more strict about which cookies to accept).  - checking cookie %s=%sN)r verifiabilityrrrrset_ok_FTrrrr<r"rIrnfn_namefns rrJzDefaultCookiePolicy.set_oksw )6; EEE{&&&M  AkGw''B2fg&& uu trc|jtd|j|jdS|jdkr|jstddS|jdkr|jstddSdS)Nz0 Set-Cookie2 without version attribute (%s=%s)Fr $ RFC 2965 cookies are switched off$ Netscape cookies are switched offT)rrrrrXrWrHs rset_ok_versionz"DefaultCookiePolicy.set_ok_versions > ! E;  . . .5 >A  dl  9 : : :5 ^q  9 : : :5trc|jrUt|rF|jdkr|jrt ddS|jdkr|jrt ddSdSNr z> third-party RFC 2965 cookie during unverifiable transactionFz> third-party Netscape cookie during unverifiable transactionT unverifiablerrr\rr]rHs rset_ok_verifiabilityz(DefaultCookiePolicy.set_ok_verifiabilitys   N7$;$; ~!!d&F!8999u1$$)D$8999utrc|jdkr8|jr1|jdrt d|jdSdS)Nr $z' illegal name (starts with '$'): '%s'FT)rr_rrrrHs r set_ok_namezDefaultCookiePolicy.set_ok_namesN Na  D$E  K " "3 ' ' td||jdSdS)N80rz bad port %s (not numeric)Fz$ request port (%s) not found in %sT)rrrrrrgrsrr"rIrreq_portr5s r set_ok_portzDefaultCookiePolicy.set_ok_port3s   #G,,Hx==[&&s++  !FFFF!!!!91=== 555!==E!=...utsAA76A7ctd|j|jdD]&}d|z}t||}|||sdS'dS)z If you override .return_ok(), be sure to call this method. If it returns false, so should your subclass (assuming your subclass wants to be more strict about which cookies to return). rv)rrwrrrr return_ok_FTryrzs rrLzDefaultCookiePolicy.return_okHsg )6; EEER  A"1nGw''B2fg&& uu trc|jdkr|jstddS|jdkr|jstddSdS)Nr rFrT)rrXrrWrHs rreturn_ok_versionz%DefaultCookiePolicy.return_ok_versionZsW >A  dl  9 : : :5 ^q  9 : : :5trc|jrUt|rF|jdkr|jrt ddS|jdkr|jrt ddSdSrrrHs rreturn_ok_verifiabilityz+DefaultCookiePolicy.return_ok_verifiabilitycs   N7$;$; ~!!d&F!%&&&u1$$)D$%&&&utrcR|jr|j|jvrtddSdS)Nz( secure cookie with non-secure requestFT)rtyperarrHs rreturn_ok_securez$DefaultCookiePolicy.return_ok_secureos4 = W\1FFF = > > >5trc\||jrtddSdS)Nz cookie expiredFT)r2_nowrrHs rreturn_ok_expiresz%DefaultCookiePolicy.return_ok_expiresus3   TY ' '  & ' ' '5trc|jrPt|}|d}|jdD] }||krn td||jdSdS)Nrrz0 request port %s does not match cookie port %sFT)rrrrrs rreturn_ok_portz"DefaultCookiePolicy.return_ok_port{s~ ; #G,,H[&&s++  ==E!I...utrct|\}}|j}|r|dsd|z}n|}|jdkr-|j|jzr|js||krtddS|jdkr#t||std||dS|jdkr+d|z |std||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) rrrrr^DomainStrictNonDomainrrrr)r"rIrrrr dotdomains rreturn_ok_domainz$DefaultCookiePolicy.return_ok_domains )'22$  &++C00 f III Na    "T%? ? ' ,2dNN - . . .5 >A  l4&@&@  /04f > > >5 >Q  D':':9'E'E  !6 + + +5trct|\}}|dsd|z}|dsd|z}|r|dsd|z}n|}||s||sdS||rt d|dS||rt d|dSdS)NrFrrT)rrrrnrrt)r"rrrrrs rrOz$DefaultCookiePolicy.domain_return_oks *'22$""3'' $8|Hs## t8D  &++C00 f III!!),,  i0H0H 5 ??6 " "  7 @ @ @5   v & &  ;V D D D5trctd|t|}t|}||krdS||r(|ds|||dzdkrdStd||dS)Nz- checking cookie path=%sTrr%z %s does not path-match %sF)rrrrr)r"rrrpathlens rrRz"DefaultCookiePolicy.path_return_oks*D111((d)) t  4!!$'' }}S!! %-ggai.?%@C%G%G4,h===ur) r?rArBrCrrr DomainLiberal DomainStrictr$rerkrnrfrqrtrJrrrrrrrLrrrrrrrOrRrHrrrrjsLLM%&;;L"&t%)#$-1(-"/.3$)"2!0!0!0!0F%%%777 %%%000 &         :::x*$       64     rrc#Kt|D]:}d} |jd}t|Ed{Vn#t$rYnwxYw|s|V;dS)z)Iterates over nested mapping, depth-firstFTN)listvaluesitems deepvaluesAttributeError)mappingobjs rrrsGNN$$%%   ' IIG!# & & & & & & & &     D   III  sA AAceZdZdS)AbsentNr?rArBrHrrrrrrc`eZdZdZejdZejdZejdZejdZ ejdZ ejdej Z dd Z d Zd Zd Zd ZdZdZdZdZdZdZdZdZdZddZdZdZdZdZdZ dZ!dS) rzCollection of HTTP cookies. You may not need to know about this class: try urllib.request.build_opener(HTTPCookieProcessor).open(url). z\Wrz\.?[^.]*z[^.]*z^\.+z^\#LWP-Cookies-(\d+\.\d+)Ncr|t}||_tj|_i|_dSr&)r_policy _threadingRLock _cookies_lock_cookiesr"policys rr$zCookieJar.__init__s5 >(**F '-// rc||_dSr&)rrs r set_policyzCookieJar.set_policys  rcg}|j||sgStd||j|}|D]}|j||s||}|D]Q}|j||std-td||R|S)Nz!Checking %s for cookies to returnz not returning cookiez it's a match) rrOrrkeysrRrrLr)r"rrcookiescookies_by_pathrcookies_by_namerIs r_cookies_for_domainzCookieJar._cookies_for_domains|,,VW== I2F;;;-/#((** ' 'D<..tW== -d3O)0022 ' '|--fg>>4555()))v&&&&  ' rcg}|jD]+}||||,|S)z2Return a list of cookies to be returned to server.)rrextendr)r"rrrs r_cookies_for_requestzCookieJar._cookies_for_request sPm((** F FF NN433FGDD E E E Erc>|ddd}g}|D]|}|j}|s d}|dkr|d|z|jF|j|jr'|dkr!|jd|j}n|j}|j||jn||jd ||dkr|j r|d |j z|j d rE|j }|j s| d r |d d}|d |z|j+d}|jr |d|jzz}||~|S)zReturn a list of cookie-attributes to be returned to server. like ['foo="bar"; $Path="/"', ...] The $Version attribute is also added when appropriate (currently only once per request). c*t|jSr&)rr)as rz)CookieJar._cookie_attrs..s3qv;;rT)rreverseFr z $Version=%sNrrz $Path="%s"rr%z $Domain="%s"z$Portz="%s")sortrrr non_word_rerfquote_rerrrrrrrrr) r"rrattrsrIrrrr5s r _cookie_attrszCookieJar._cookie_attrss  .. === ( $( $FnG :" Q;;LL!8999 ) '' 55*:AA++ ))'6<@@ |# V[))))  UU;<<<{{(=LL !;<<<=++C00:#]F"5,))#..,!'LL&!8999;*A,86;!67LLOOO rctd|j tt jx|j_|_||}||}|r>| ds)| dd ||jj rI|jj s=| ds(|D]%}|jdkr| ddn&|jn#|jwxYw|dS)zAdd correct Cookie: header to request (urllib.request.Request object). The Cookie2 header is also added unless policy.hide_cookie2 is true. add_cookie_headerrrCookie2r%z $Version="1"N)rracquirergrtrrrr has_headeradd_unredirected_headerrrXrZrreleaseclear_expired_cookies)r"rrrrIs rrzCookieJar.add_cookie_headerLss "### ""$$$ ),/ ,<,<
RRR+   & & ( ( ( (D  & & ( ( ( ( ""$$$$$s C0D44Ecvg}d}d}|D].}|d\}}d}d} i} i} |ddD]\} } | }||vs||vr|} | |vr| d} | | vr0| dkr)| td d} n| } | d kr|rh| td z| d krAd} t| } n"#t$rtd d} Yn@wxYwd } |j| z} | |vs| |vr"| | dvrtd| zd} n | | | <| | | <| r|||| | f0|S)aReturn list of tuples containing normalised cookie information. attrs_set is the list of lists of key,value pairs extracted from the Set-Cookie or Set-Cookie2 headers. Tuples are name, value, standard, rest, where name and value are the cookie name and value, standard is a dictionary containing the standard cookie-attributes (discard, secure, version, expires or max-age, domain, path and port) and rest is a dictionary containing the rest of the cookie-attributes. )rr)rrrrrrr commenturlr Fr%NTrz% missing value for domain attributerzM missing or invalid value for expires attribute: treating as session cookierz? missing or invalid (non-numeric) value for max-age attribute)rrrz! missing value for %s attribute)rIrrgrsrr)r" attrs_set cookie_tuples boolean_attrs value_attrs cookie_attrsrr max_age_set bad_cookiestandardr#rrrs r_normalized_cookie_tuplesz#CookieJar._normalized_cookie_tuplesms + 0 &H @H @L&q/KD% KJHD$QRR(2 2 1WWYY$$m(;(;A %%!)A====yFGGG%)  A >>"! y FGGG  >>"&KFF% 2333%)  "A A A$$!}*<*< !BBBBQFGGG%) "#HQKKDGG   $x!> ? ? ? ?s,B<<CCc2|\}}}}|dt}|dt}|dt} |dt} |dd} | " t| } n#t$rYdSwxYw|dd} |dd} |d d}|d d}|tur|d krd }t |}n_d}t |}|d }|dkr| dkr |d|}n |d|dz}t|dkrd }|tu}d}|r"t| d}|turt|\}}|}n| dsd|z}d}| tur+| t|} nd }tj dd | } nd} | turd} d } nH| |jkr= ||||n#t $rYnwxYwt#d|||dSt%| ||| ||||||| | | |||S)NrrrrrrFrrrrTrrr r%rz\s+z2Expiring cookie, domain='%s', path='%s', name='%s')r*rrgrsrrrrboolrrrrrrclearKeyErrorrr)r"tuprrrrr#rrrrrrrrrrrrrrrrs r_cookie_from_cookie_tuplez#CookieJar._cookie_from_cookie_tuples '*#eXth//||FF++||FF++,,y&11,,y$//   g,,   tt h..,,y%00,,y$//ll<66  v  $"**!Nt$$DD"N((D 3ABwwa<<8DD1:D4yyA~~ct"/"  >!%f&7&7&<&.no_matching_rfc2965ls #*ININJCf,,r)rget_allrgrtrrrXrWrr Exceptionr"rrrrrfilterr) r"responserr rfc2965_hdrsns_hdrsrXrWr ns_cookiesrrIrs r make_cookieszCookieJar.make_cookies?s--//}b99 //,33(+DIKK(8(88 DI,&<( g  !(  &.  #* I 22"<00';;GG    % ' ' 'GGG   +x + !99$W--w88    )+++    ) )* 5 5 5 E%MMFHLFFM6; DEE:@----$$7DD  +z***s$#CCC&#D D'&D'cj|j ttjx|j_|_|j||r|||jdS#|jwxYw)z-Set a cookie if policy says it's OK to do so.N) rrrgrtrrrJ set_cookierrHs rset_cookie_if_okzCookieJar.set_cookie_if_okvs ""$$$ ),/ ,<,<
> , ,<&&vw77,0&999OOF+++ ,   & & ( ( ( ( (D  & & ( ( ( (s AB22C c|)||td|j|||=dS|!|td|j||=dS| |j|=dSi|_dS)aClear some cookies. Invoking this method without arguments will clear all cookies. If given a single argument, only cookies belonging to that domain will be removed. If given two arguments, cookies belonging to the specified path within that domain are removed. If given three arguments, then the cookie with the specified name, path and domain is removed. Raises KeyError if no matching cookie exists. Nz8domain and path must be given to remove a cookie by namez.domain must be given to remove cookies by path)rsr)r"rrrs rr zCookieJar.clears  DL NPPP f%d+D111  ~ DFFF f%d+++   f%%%DMMMrc|j |D]/}|jr&||j|j|j0 |jdS#|jwxYw)zDiscard all session cookies. Note that the .save() method won't save session cookies anyway, unless you ask otherwise by passing a true ignore_discard argument. N)rrrr rrrr)r"rIs rclear_session_cookieszCookieJar.clear_session_cookiess ""$$$ ) H H>HJJv}fk6;GGG H   & & ( ( ( ( (D  & & ( ( ( (s 2A))BcP|j tj}|D]=}||r&||j|j|j> |jdS#|jwxYw)aDiscard all expired cookies. You probably don't need to call this method: expired cookies are never sent back to the server (provided you're using DefaultCookiePolicy), this method is called by CookieJar itself every so often, and the .save() method won't save expired cookies anyway (unless you ask otherwise by passing a true ignore_expires argument). N) rrrtr2r rrrr)r"r1rIs rrzCookieJar.clear_expired_cookiess ""$$$ ))++C H H$$S))HJJv}fk6;GGG H   & & ( ( ( ( (D  & & ( ( ( (s AB B%c*t|jSr&)rrrhs r__iter__zCookieJar.__iter__s$-(((rcd}|D]}|dz}|S)z#Return number of contained cookies.r r%rH)r"rrIs r__len__zCookieJar.__len__s! %%FAAArcg}|D]$}|t|%d|jjdd|dSN<[rz]>)rr=r>r?rr"rrIs rr@zCookieJar.__repr__sS 22FAHHT&\\22222!^444diillllCCrcg}|D]$}|t|%d|jjdd|dSr1)rrr>r?rr4s rr8zCookieJar.__str__sS 11FAHHS[[11111!^444diillllCCrr&)NNN)"r?rArBrCrcompilerrstrict_domain_re domain_redots_reASCIImagic_rer$rrrrrrr rrrr!r r'r r*rr-r/r@r8rHrrrrs "*U##Krz+&&H!rz+.. 8$$Ibj!!Grz6AAH$999v%%%B___BZZZx ' ' '555n ) ) ) ) ) ) ) ) )6 ) ) ))))&))) DDD DDDDDrrceZdZdS)rNrrHrrrrrrrc6eZdZdZddZd dZd dZ d dZdS) rz6CookieJar that can be loaded from and saved to a file.NFct|||tj|}||_t ||_dS)z} Cookies are NOT loaded from the named file until either the .load() or .revert() method is called. N)rr$osfspathfilenamer delayload)r"rBrCrs rr$zFileCookieJar.__init__sG 4(((  y**H  irct)zSave cookies to a file.rF)r"rBignore_discardignore_expiress rsavezFileCookieJar.saverMrc|#|j|j}nttt|5}|||||ddddS#1swxYwYdS)zLoad cookies from a file.N)rBrsMISSING_FILENAME_TEXTopen _really_loadr"rBrErFr s rloadzFileCookieJar.loads  }(T](("#8999 (^^ Kq   a>> J J J K K K K K K K K K K K K K K K K K KsAA"Ac|#|j|j}ntt|j t j|j}i|_ ||||n#t$r ||_wxYw |j dS#|j wxYw)zClear all cookies and reload cookies from a saved file. Raises LoadError (or OSError) if reversion is not successful; the object's state will not be altered if this happens. N) rBrsrIrrr deepcopyrrMOSErrorr)r"rBrErF old_states rrevertzFileCookieJar.revert s  }(T](("#8999 ""$$$ ) dm44IDM  (NNCCCC    )  D   & & ( ( ( ( (D  & & ( ( ( (s$ B+!A98B+9B  B++C)NFNNFF)r?rArBrCr$rGrMrRrHrrrrsv@@ ) ) ) )$$$$KKKK#49))))))rrc|j|jfd|jfd|jfg}|j|d|jf|jr|d|jr|d|jr|d|j r|d|j r6|d tt|j f|j r|d |jr|d |jf|jr|d |jft!|j}|D]1}||t'|j|f2|d t'|jft+|gS)zReturn string representation of Cookie in the LWP cookie file format. Actually, the format is extended a bit -- see module docstring. rrNr) path_specN) port_specN) domain_dotN)rNr)rNrrr)rrrrrrrrrrrrVrrrrsortedr!rrrr)rIrrrs rlwp_cookie_strrY's +v| $ &+  FM " $A{&&+)> ? ? ? ;ahh':;;; ;ahh':;;;  @!((+?"@"@"@ }0ahh/000 ~Bqxx(v~)>)>??!ABBB ~2qxx 1222 ~ 2::!D E$//44 ';6666b=="G"G1dE!#3[!"" ! !&!)%!,,s*;*;"""o7 #r     . . . % ' ' ')%XXtt-.. . .sG2EG8G>NFc P|#|j|j}ntttjtj|tjtjztjzdd5}| ttj }|D]}|j }|s|j r|s||r+|jrd}nd}|drd} nd} |jt%|j} nd} |j d} |j} n|j} |j} |t,r t.|z}| d|| |j|| | | gdz ddddS#1swxYwYdS) Nr_r`rqFALSErrrpr\)rBrsrIr@rarJrbrcrdreNETSCAPE_HEADER_TEXTrtrrr2rrrrrrr(rtrsrr) r"rBrErFr r1rIrrrrrrs rrGzMozillaCookieJar.save's  }(T](("#8999 Y GHbj2;6CU K K   "  GG( ) ) ))++C  %&.%&*;*;C*@*@='6&&&f$$S)),;;$+k>-!&.11GG G<'D"KEE!;D"LE..}==6,v5FIIv{FK%we=>>3  " " " " " " " " " " " " " " " " " " s3DFF"FrS)r?rArBrCrKrGrHrrr r sE>G.G.G.R''''''rr r&)XrC__all__r@r rMrrt urllib.parserurllib.request threadingr http.clienthttpcalendarr r rrrtrsrclient HTTP_PORTrr7rrrIrwr"r+r3rXrZrqrVr[rdr;rerlr~rIrXrrrrrrrrrrrrrrrrrrrrrrrrr r r rrrrrrrrrrPrrrYrr rHrrrs6 M M M  ########   C -..RZ @AA:AAA 988 4 4 4226222 BBBB&0000(T = = bj5rx@@    6 6 6 p,-/X77RZ2BD28OEE RZ & D28O)*656565pbj 4") # $555B333 $$677#$MNN#$9::2:h''SSSj# ;//2AAAH "*Y ) )   %%%N(bj28,,        $"*9::+++   ! ! ! F"_E_E_E_E_E_E_E_EDB_____,___B   "LDLDLDLDLDLDLDLD`4)4)4)4)4)I4)4)4)n"""8x.x.x.x.x.=x.x.x.vPPPPP}PPPPPr