mò %U²Ic @sÚdZdkZdkZdkZdkZdkZdkZdkZdkl Z y dk Z Wne j odk Z nXdkZdklZeidƒiZeeiƒZdZfd„ZdZd„Zd d d d d ddgZddddddddddddg ZgZx!eD]Zeieiƒƒq(We d„Z!e d„Z"hde <de <d e <d!e d:„Z?d;„Z@d<„ZAd=„ZBd>ZCei$d?ƒZDd@„ZEdA„ZFdB„ZGdC„ZHdDfdE„ƒYZIdFfdG„ƒYZJdHeJfdI„ƒYZKdJ„ZLdK„ZMdLfdM„ƒYZNdNfdO„ƒYZOdPePfdQ„ƒYZQdReOfdS„ƒYZRdTkSlTZTlUZUdUkVlWZWdS(VsªHTTP 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 the classes which do not derive from FileCookieJar are not distributed with the Python standard library, but are available from http://wwwsearch.sf.net/): CookieJar____ / \ FileCookieJar \ / | \ \ MozillaCookieJar | LWPCookieJar \ | | | ---MSIEBase | | / | | | / MSIEDBCookieJar BSDDBCookieJar |/ MSIECookieJar N(s StringTypes(stimegmt cookielibsQa filename was not supplied (nor was the CookieJar instance initialised with one)cCs˜|tttf}tiƒd}t||ƒo‚ndk}dk }dk }|i ƒ}|i d|ƒ|iƒ}|id|ddƒdS(Niscookielib bug! %st stackleveli(tunmaskedtKeyboardInterruptt SystemExitt MemoryErrortsystexc_infotetypet issubclasstwarningst tracebacktStringIOtft print_exctNonetgetvaluetmsgtwarn(RR R R RRR ((t&/data/zmath/lib/python2.4/cookielib.pytreraise_unmasked_exceptions+s  i²cCsÕ|d \}}}}}}|tjo¤d|jo djno†d|jo djnohd|jo djnoJd|jo djno,d|jo djnot|ƒSndSdS( Niii iiii;i=( ttttyeartmonthtmdaythourtmintsect EPOCH_YEARttimegmR(RRRRRRR((Rt_timegm?s£tMontTuetWedtThutFritSattSuntJantFebtMartAprtMaytJuntJultAugtSeptOcttNovtDeccCs\|djotiƒ}nti|ƒd \}}}}}}d||||||fS(sHReturn 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 is%04d-%02d-%02d %02d:%02d:%02dZN( ttRttimetgmtimeRtmonRRRR(R2RRRRRR5((Rt time2isozMs  %cCsn|djotiƒ}nti|ƒd \}}}}}}}dt ||t |d||||fS(sðReturn 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 is"%s %02d-%s-%04d %02d:%02d:%02d GMTiN( R2RR3R4RR5RRRRtwdaytDAYStMONTHS(R2RRRRRR7R5((Rt time2netscape^s  (tGMTtUTCtUTtZs^([-+])?(\d\d?):?(\d\d)?$cCs¦d}|tjo d}n†ti|ƒ}|oodt|idƒƒ}|idƒo!|dt|idƒƒ}n|idƒdjo | }q¢n|S(Niiiii<it-( Rtoffsetttzt UTC_ZONESt TIMEZONE_REtsearchtmtinttgroup(RARER@((Rtoffset_from_tz_stringrs  !c Csyti|iƒƒd}Wnitj o]yt|ƒ} Wntj o dSnXd| jo djno | }q‰dSnX|djo d}n|djo d}n|djo d}nt|ƒ}t|ƒ}t|ƒ}t|ƒ}t|ƒ}|djo�t it i ƒƒd} | d} |}|| | }| |} t| ƒdjo)| djo|d}q”|d}q˜nt|||||||fƒ} | dj oR|djo d}n|iƒ}t|ƒ}|djodSn| |} n| S(Nii iièidi2R<(t MONTHS_LOWERtindexR5tlowert ValueErrorRFtimonRthrRRtyrtdayR3t localtimetcur_yrREttmptabsRRAR2tupperRHR@( RPR5RORNRRRARSR@RERMRRR2((Rt _str2time€sR               !      sV^[SMTWF][a-z][a-z], (\d\d) ([JFMASOND][a-z][a-z]) (\d\d\d\d) (\d\d):(\d\d):(\d\d) GMT$s+^(?:Sun|Mon|Tue|Wed|Thu|Fri|Sat)[a-z]*,?\s*sÒ^ (\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 Cs;ti|ƒ}|o�|iƒ}ti|diƒƒd}t |dƒ|t |dƒt |dƒt |dƒt |dƒf}t |ƒSn|iƒ}tid|dƒ}d gd\} }}}}} }ti|ƒ}|d j o%|iƒ\} }}}}} }nd St| ||||| |ƒS( sÕReturns 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. iiiiiitiN(tSTRICT_DATE_RERDttextREtgroupstgRIRJRKR5RFtfloatRRtlstript WEEKDAY_REtsubRRPRORNRRRAtLOOSE_HTTP_DATE_RERV( RYRORAR[RRRERNR5RRP((Rt http2timeËs J " %sÆ^ (\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 Cs’|iƒ}dgd\}}}}}}}t i |ƒ}|dj o(|i ƒ\}}}}}}}} ndSt|||||||ƒS(sv 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 iN(RYR]RRPR5RORNRRRAt ISO_DATE_RERDRERZt_RV( RYRARRNRERR5RORPRc((Rtiso2times  " (cCs+|idƒ\}}|i| |i|S(s)Return unmatched part of re.Match object.iN(tmatchtspantstarttendtstring(ReRgRh((Rt unmatched4ss^\s*([^=\s;,]+)s&^\s*=\s*\"([^\"\\]*(?:\\.[^\"\\]*)*)\"s^\s*=\s*([^\s;,]*)s\\(.)c CsËt|ƒtjpt‚g}x¤|D]œ}|}g}xo|ogti |ƒ}|oÀt |ƒ}|i dƒ}ti |ƒ}|o1t |ƒ}|i dƒ} tid| ƒ} nHti |ƒ}|o+t |ƒ}|i dƒ} | iƒ} nd} |i|| fƒq<|iƒidƒo2|iƒd}|o|i|ƒng}q<tidd|ƒ\}}|djptd|||f‚|}q<W|o|i|ƒq'q'W|S( smParse 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"')]] is\1t,s^[=\s;]*RWis&split_header_words bug: '%s', '%s', %sN(ttypet header_valuest StringTypestAssertionErrortresultRYt orig_texttpairstHEADER_TOKEN_RERDRERjRGtnametHEADER_QUOTED_VALUE_REtvaluetHEADER_ESCAPE_RER_tHEADER_VALUE_REtrstripRtappendR]t startswithtretsubntnon_junkt nr_junk_chars( RmRrRtRRYR~RERqRpRv((Rtsplit_header_words=sH,    $ s([\"\\])cCsÃg}x­|D]¥}g}xu|D]m\}}|dj oGtid|ƒp t i d|ƒ}d|}nd||f}n|i |ƒq W|o|i di |ƒƒq q Wdi |ƒS(s»Do the inverse (almost) of the conversion done by split_header_words. Takes a list of lists of (key, value) pairs and produces a single header value. Attribute values are quoted if needed. >>> 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"' s^\w+$s\\\1s"%s"s%s=%ss; s, N( theaderstlistsRrtattrtktvRR|RDtHEADER_JOIN_ESCAPE_RER_Rztjoin(R‚RrRƒR„R�R…((Rtjoin_header_words“s   c Cs¢d}g}x�|D]‡} g}t} xBtti d| ƒƒD](\}}|i ƒ}|djoq>nd |jo|d}}n(ti d |d ƒ\}}|iƒ}|d jo—|iƒ}||jo |}n|d jo t} n|djoL|idƒo|d }n|idƒo|d }nt|ƒ}qSn|i||fƒq>W|o)| p|idƒn|i|ƒqqW|S(s5Ad-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. texpirestdomaintpathtsecuretportsmax-ages;\s*RWt=s\s*=\s*iitversiont"iÿÿÿÿt0N(sexpiressdomainspathssecuresportsmax-age(sversionR‘(t known_attrsRpt ns_headerst ns_headerRrtFalset version_sett enumerateR|tsplittiitparamRyRR„R…R]RKtlctTrueR{tendswithRaRz( R“RrR’R›R„R…RšR™RpR”R–((Rtparse_ns_headers¬sD            s\.\d+$cCs[ti|ƒotSn|djotSn|ddjp|ddjotSntS(s*Return True if text is a host domain name.RWit.iÿÿÿÿN(tIPV4_RERDRYR•Rœ(RY((Rtis_HDNås "cCs¨|iƒ}|iƒ}||jotSnt|ƒptSn|i|ƒ}|djp |djotSn|idƒptSnt|dƒptSntS(sýReturn 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. iÿÿÿÿiRŸiN( tARKtBRœR¡R•trfindtiR{(R¢R£R¥((Rt domain_matchôs    cCsti|ƒotSntS(sdReturn True if text is a sort-of-like a host domain name. For accepting/blocking domains. N(R RDRYR•Rœ(RY((Rtliberal_is_HDNscCsž|iƒ}|iƒ}t|ƒo t|ƒp||jotSntSn|idƒ}|o|i|ƒotSn| o||jotSntS(s\For blocking/accepting domains. A and B may be host domain names or IP addresses. RŸN( R¢RKR£R§RœR•R{t initial_dotR�(R¢R£R¨((Rtuser_domain_match%s   s:\d+$cCsa|iƒ}ti|ƒd}|djo|iddƒ}ntid|dƒ}|iƒS(sˆReturn request-host, as defined by RFC 2965. Variation from RFC: returned value is lowercased, for convenient comparison. iRWtHostN( trequestt get_full_urlturlturlparsethostt get_headert cut_port_reR_RK(R«R­R¯((Rt request_host:s  cCsOt|ƒ}}|idƒdjoti|ƒ o|d}n||fS(szReturn a tuple (request-host, effective request-host name). As defined by RFC 2965, except both are lowercased. RŸiÿÿÿÿs.localN(R²R«terhntreq_hosttfindR RD(R«R´R³((Rteff_request_hostJs 'cCs•|iƒ}ti|ƒd\}}}}|od||f}nt|ƒ}ti dd|d||fƒ}|i dƒpd|}n|S(s$request-URI, as defined by RFC 2965.is%s;%sRWt/N( R«R¬R­R®R‹t parameterstquerytfragt escape_patht urlunparsetreq_pathR{(R«RºR¸R­R¹R‹R½((Rt request_pathUs  !cCsy|iƒ}|idƒ}|djoG||d}yt|ƒWqutj otd|ƒdSquXnt }|S(Nt:iisnonnumeric port: '%s'( R«tget_hostR¯RµR¥R�RFRLtdebugRtDEFAULT_HTTP_PORT(R«R¥R¯R�((Rt request_portds    s%/;:@&=+$,!~*'()s%([0-9a-fA-F][0-9a-fA-F])cCsd|idƒiƒS(Ns%%%si(ReRGRU(Re((Rtuppercase_escaped_charvscCsKt|tƒo|idƒ}nti|tƒ}tit |ƒ}|S(sEEscape any invalid characters in HTTP URL, and uppercase all escapes.sutf-8N( t isinstanceR‹tunicodetencodeturllibtquotetHTTP_PATH_SAFEtESCAPED_CHAR_RER_RÄ(R‹((RR»xs  cCst|idƒ}|djoT||d}|idƒ}t|ƒo&|djp |djo d|Sqpn|S(sBReturn reach of host h, as defined by RFC 2965, section 1. The reach R of a host name H is defined as follows: * If - H is the host domain name of a host; and, - H has the form A.B; and - A has no embedded (that is, interior) dots; and - B has at least one embedded dot, or B is the string "local". then the reach of H is .B. * Otherwise, the reach of H is H. >>> reach("www.acme.com") '.acme.com' >>> reach("acme.com") 'acme.com' >>> reach("acme.local") '.local' RŸiitlocalN(thRµR¥tbR¡(RÍR¥RÎ((Rtreachˆs 'cCs8t|ƒ}t|t|iƒƒƒptSntSdS(sÜ 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. N(R²R«R´R¦RÏtget_origin_req_hostRœR•(R«R´((Rtis_third_party«s  tCookiecBsStZdZd„Zd„Zed„Zd„Zed„Zd„Z d„Z RS(sÐHTTP 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. cCs|dj ot|ƒ}n| dj ot| ƒ} n|djo|tjotdƒ‚n||_||_ ||_ ||_||_|i ƒ|_ ||_ ||_| |_| |_| |_| |_| |_||_||_ti|ƒ|_dS(Ns-if port is None, port_specified must be false(R�RRFR‰R�tport_specifiedRœRLtselfRtRvRŠRKtdomain_specifiedtdomain_initial_dotR‹tpath_specifiedRŒtdiscardtcommentt comment_urltcopytrestt_rest(RÔR�RtRvR�RÓRŠRÕRÖR‹R×RŒR‰RØRÙRÚRÜ((Rt__init__Îs,                cCs ||ijS(N(RtRÔRÝ(RÔRt((Rthas_nonstandard_attrõscCs|ii||ƒS(N(RÔRÝtgetRttdefault(RÔRtRá((Rtget_nonstandard_attr÷scCs||i|( RÔR�RtpRŠR‹tlimitRvRtt namevalue(RÔRæRçRè((Rt__str__s   cCs›g}xgddddddddd d d d d ddgD]2}t||ƒ}|id|t|ƒfƒq:W|idt|iƒƒddi|ƒS(NR�RtRvR�RÓRŠRÕRÖR‹R×RŒR‰RØRÙRÚs%s=%ssrest=%ss Cookie(%s)s, ( targsRttgetattrRÔRƒRztreprRÝR‡(RÔRtRêRƒ((Rt__repr__ s4!( t__name__t __module__t__doc__RÞRßRRâRãRåRéRí(((RRÒ¼s  '     t CookiePolicycBs2tZdZd„Zd„Zd„Zd„ZRS(s 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 customised policy. cCs tƒ‚dS(sÄReturn 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. N(tNotImplementedError(RÔtcookieR«((Rtset_ok#scCs tƒ‚dS(sAReturn true if (and only if) cookie should be returned to server.N(Rò(RÔRóR«((Rt return_ok,scCstS(sMReturn false if cookies should not be returned, given cookie domain. N(Rœ(RÔRŠR«((Rtdomain_return_ok0scCstS(sKReturn false if cookies should not be returned, given cookie path. N(Rœ(RÔR‹R«((Rtpath_return_ok5s(RîRïRðRôRõRöR÷(((RRñs   tDefaultCookiePolicyc Bs tZdZdZdZdZdZeeBZeee e e e e e ee e d„ Z d„Z d„Z d„Zd „Zd „Zd „Zd „Zd „Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Z d„Z!RS(sBImplements the standard rules for accepting and returning cookies.iiiic Cs¤||_||_||_||_||_||_| |_| |_| |_ |dj ot |ƒ|_ n f|_ |dj ot |ƒ}n||_dS(sAConstructor arguments should be passed as keyword arguments only.N(tnetscapeRÔtrfc2965t hide_cookie2t strict_domaintstrict_rfc2965_unverifiabletstrict_ns_unverifiabletstrict_ns_domaintstrict_ns_set_initial_dollartstrict_ns_set_pathtblocked_domainsRttuplet_blocked_domainstallowed_domainst_allowed_domains( RÔRRRùRúRûRüRýRþRÿRR((RRÞEs             cCs|iS(s4Return the sequence of blocked domains (as a tuple).N(RÔR(RÔ((RRdscCst|ƒ|_dS(s$Set the sequence of blocked domains.N(RRRÔR(RÔR((Rtset_blocked_domainsgscCs0x)|iD]}t||ƒotSq q WtS(N(RÔRtblocked_domainR©RŠRœR•(RÔRŠR((Rt is_blockedks   cCs|iS(s=Return None, or the sequence of allowed domains (as a tuple).N(RÔR(RÔ((RRqscCs*|dj ot|ƒ}n||_dS(s-Set the sequence of allowed domains, or None.N(RRRRÔR(RÔR((Rtset_allowed_domainsts cCsH|idjotSnx)|iD]}t||ƒotSq"q"WtS(N(RÔRRR•tallowed_domainR©RŠRœ(RÔRŠR ((Rtis_not_allowedzs  cCsstd|i|iƒ|id j pt‚x?d D]7}d|}t||ƒ}|||ƒpt Sq4q4Wt S( sØ 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). s - checking cookie %s=%sR�t verifiabilityRtR‹RŠR�tset_ok_N(sversionR snamespathsdomainsport(RÁRóRtRvRRotntfn_nameRëRÔtfnR«R•Rœ(RÔRóR«RRR((RRô‚s  cCsŒ|idjotd|i|iƒtSn|idjo|i otdƒtSn.|idjo|i otdƒtSnt S(Ns0 Set-Cookie2 without version attribute (%s=%s)is$ RFC 2965 cookies are switched offs$ Netscape cookies are switched off( RóR�RRÁRtRvR•RÔRúRùRœ(RÔRóR«((Rtset_ok_version•s  cCsz|iƒoit|ƒo\|idjo|iotdƒtSqv|idjo|i otdƒtSqvnt S(Nis> third-party RFC 2965 cookie during unverifiable transactions> third-party Netscape cookie during unverifiable transaction( R«tis_unverifiableRÑRóR�RÔRýRÁR•RþRœ(RÔRóR«((Rtset_ok_verifiability¤s   cCsI|idjo5|io+|iidƒotd|iƒtSntS(Nit$s' illegal name (starts with '$'): '%s'( RóR�RÔRRtR{RÁR•Rœ(RÔRóR«((Rt set_ok_name°s-cCsw|ioit|ƒ}|idjp|idjo|io/|i|i ƒ ot d|i |ƒt Sqsnt S(Nis7 path attribute %s is not a prefix of request path %s( RóR×R¾R«R½R�RÔRR{R‹RÁR•Rœ(RÔRóR«R½((Rt set_ok_path¹s  >  c CsÙ|i|iƒotd|iƒtSn|i|iƒotd|iƒtSn|iout|ƒ\}} |i}|i oÄ|i dƒdjo®|idƒ}|idd|ƒ}|djoy||d} ||d|!} | iƒddd d d d d ddg jo(t| ƒdjotd|ƒtSqEqIn|idƒo|d}n|}|idƒdj}| o"|djotd|ƒtSn|idjoS| i|ƒ o>| idƒ o-d| i|ƒ otd| |ƒtSqn|idjp|i|i@o,t| |ƒptd| |ƒtSq\n|idjp|i|i@oT|t|ƒ } | idƒdjo)t i!|ƒ otd| |ƒtSqÑqÕnt"S(Ns" domain %s is in user block-lists& domain %s is not in user allow-listRŸiiitcotactcomtedutorgtnettgovtmilRFs& country-code second level domain %ss.locals/ non-local domain %s contains no embedded dotsS effective request-host %s (even with added initial dot) does not end end with %ss5 effective request-host %s does not domain-match %ss. host prefix %s for domain %s contains a dot(#RÔR RóRŠRÁR•R RÕR¶R«R´R³RütcountR¤R¥tjttldtsldRKtlenR{tundotted_domainRµt embedded_dotsR�R�RÿtDomainRFC2965MatchR¦tDomainStrictNoDotst host_prefixR RDRœ( RÔRóR«RŠR%R¥R!R´R&R#R)R³R"((Rt set_ok_domainÄsV    A 7  !  !' cCs¼|io®t|ƒ}|djo d}n t|ƒ}x||iidƒD]M}yt |ƒWn$t j ot d|ƒt SnX||joPqLqLWt d||iƒt SntS(Nt80Rks bad port %s (not numeric)s$ request port (%s) not found in %s(RóRÓRÃR«treq_portRtstrR�R˜RæRFRLRÁR•Rœ(RÔRóR«RæR,((Rt set_ok_portüs$          cCs\td|i|iƒx?d D]7}d|}t||ƒ}|||ƒpt SqqWt S( sÛ 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). s - checking cookie %s=%sR�R RŒR‰R�RŠt return_ok_N(sversions verifiabilityssecuresexpiressportsdomain( RÁRóRtRvRRRëRÔRR«R•Rœ(RÔRóR«RRR((RRõs  cCs^|idjo|i otdƒtSn.|idjo|i otdƒtSntS(Nis$ RFC 2965 cookies are switched offs$ Netscape cookies are switched off(RóR�RÔRúRÁR•RùRœ(RÔRóR«((Rtreturn_ok_version#s  cCsz|iƒoit|ƒo\|idjo|iotdƒtSqv|idjo|i otdƒtSqvnt S(Nis> third-party RFC 2965 cookie during unverifiable transactions> third-party Netscape cookie during unverifiable transaction( R«RRÑRóR�RÔRýRÁR•RþRœ(RÔRóR«((Rtreturn_ok_verifiability,s   cCs3|io%|iƒdjotdƒtSntS(Nthttpss( secure cookie with non-secure request(RóRŒR«tget_typeRÁR•Rœ(RÔRóR«((Rtreturn_ok_secure8s cCs)|i|iƒotdƒtSntS(Ns cookie expired(RóRåRÔt_nowRÁR•Rœ(RÔRóR«((Rtreturn_ok_expires>s cCs{|iomt|ƒ}|djo d}nxG|iidƒD]}||joPq@q@Wtd||iƒt Snt S(NR+Rks0 request port %s does not match cookie port %s( RóR�RÃR«R,RR˜RæRÁR•Rœ(RÔRóR«RæR,((Rtreturn_ok_portDs       cCsàt|ƒ\}}|i}|idjo;|i|i @o*|i o||jot dƒt Sn|idjo)t ||ƒ ot d||ƒt Sn|idjo-d|i|ƒ ot d||ƒt SntS(NisQ cookie with unspecified domain does not string-compare equal to request domainsQ effective request-host name %s does not domain-match RFC 2965 cookie domain %sRŸs; request-host %s does not match Netscape cookie domain %s(R¶R«R´R³RóRŠR�RÔRÿtDomainStrictNonDomainRÕRÁR•R¦R�Rœ(RÔRóR«RŠR´R³((Rtreturn_ok_domainRs 9 ! % cCsÄt|ƒ\}}|idƒpd|}n|idƒpd|}n|i|ƒp |i|ƒptSn|i |ƒot d|ƒtSn|i |ƒot d|ƒtSnt S(NRŸs" domain %s is in user block-lists& domain %s is not in user allow-list( R¶R«R´R³R{R�RŠR•RÔR RÁR Rœ(RÔRŠR«R´R³((RRöhs   cCsEtd|ƒt|ƒ}|i|ƒptd||ƒtSntS(Ns- checking cookie path=%ss %s does not path-match %s(RÁR‹R¾R«R½R{R•Rœ(RÔR‹R«R½((RR÷~s   ("RîRïRðR(R8R't DomainLiberalt DomainStrictRRœR•RÞRRR RR R RôRRRRR*R.RõR0R1R4R6R7R9RöR÷(((RRø;s:  *         8       cCs&|iƒ}|iƒt|i|ƒS(N(tadicttkeystsorttmapRà(R<R=((Rtvals_sorted_by_key‡s  ccsxt|ƒ}xe|D]]}t}y |iWntj on#Xt}xt|ƒD] }|VqSW|p|VqqWdS(sBIterates over nested mapping, depth-first, in sorted order by key.N( R@tmappingtvaluestobjR•titemstAttributeErrorRœt deepvaluestsubobj(RARCRGRB((RRFŒs   tAbsentcBstZRS(N(RîRï(((RRHŸst CookieJarcBstZdZeidƒZeidƒZeidƒZeidƒZeidƒZ dZ e d„Z d„Z d „Zd „Zd „Zd „Zd „Zd„Zd„Zd„Zd„Zd„Zd„Ze e e d„Zd„Zd„Zd„Zd„Zd„Zd„ZRS(sŽCollection of HTTP cookies. You may not need to know about this class: try urllib2.build_opener(HTTPCookieProcessor).open(url). s\Ws([\"\\])s\.?[^.]*s[^.]*s^\.+s^\#LWP-Cookies-(\d+\.\d+)cCs?|djo tƒ}n||_tiƒ|_h|_dS(N( tpolicyRRøRÔt_policyt _threadingtRLockt _cookies_lockt_cookies(RÔRJ((RRÞ±s    cCs ||_dS(N(RJRÔRK(RÔRJ((Rt set_policy¹scCsÕg}|ii||ƒpgSntd|ƒ|i|}x�|i ƒD]‚}|ii ||ƒpqKn||}xR|i ƒD]D}|ii||ƒptdƒq…ntdƒ|i|ƒq…WqKW|S(Ns!Checking %s for cookies to returns not returning cookies it's a match(tcookiesRÔRKRöRŠR«RÁROtcookies_by_pathR=R‹R÷tcookies_by_nameRBRóRõRz(RÔRŠR«RRRSRQRóR‹((Rt_cookies_for_domain¼s$       cCs=g}x0|iiƒD]}|i|i||ƒƒqW|S(s2Return a list of cookies to be returned to server.N(RQRÔROR=RŠtextendRTR«(RÔR«RQRŠ((Rt_cookies_for_requestÎs c CsÜd„}|i|ƒt} g}x³|D]«}|i}| p,t} |djo|i d|ƒqkn|i d j o?|i i|i ƒo)|djo|iid|i ƒ}n |i }|i d jo|i |iƒn|i d|i|fƒ|djoÆ|io|i d|iƒn|iidƒoG|i}|i o|idƒo|d}n|i d |ƒn|id j o6d }|io|d |i}n|i |ƒqÔq)q)W|S( sÜReturn 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). cCstt|iƒt|iƒƒS(N(tcmpR$RÎR‹ta(RXRÎ((Rtdecreasing_sizeßsis $Version=%ss\\\1s%s=%ss $Path="%s"RŸis $Domain="%s"s$Ports="%s"N(RYRQR>R•R–tattrsRóR�RœRzRvRRÔt non_word_reRDtquote_reR_RtR×R‹RŠR{RÖR�RæRÓ( RÔRQRYRvRæR�RóRZRŠR–((Rt _cookie_attrsÕs@    3     cCs5tdƒ|iiƒttiƒƒ|i_|_t|ƒ\}}|ii |ii @}|i|ƒ}|i|ƒ}|o1|idƒp|iddi|ƒƒq´n|iioY|ii oK|idƒ o:x7|D]+}|idjo|iddƒPqçqçWn|iiƒ|iƒdS(s—Add correct Cookie: header to request (urllib2.Request object). The Cookie2 header is also added unless policy.hide_cookie2 is true. tadd_cookie_headerRÒs; tCookie2is $Version="1"N(RÁRÔRNtacquireRFR3RKR5R¶R«R´R³RÿR8tstrict_non_domainRVRQR]RZt has_headertadd_unredirected_headerR‡RúRûRóR�treleasetclear_expired_cookies(RÔR«RQR³R´RaRóRZ((RR^s&  !,  cCsDg}d} d}x+|D]#}|d \}}t}t} h}h} xË|d D]¿\} } | iƒ}||jp || jo |} n| | jo| djo t} n| |joqRn| djo2| djotd ƒt} Pn| iƒ} n| djo0|oqRn| djotdƒqRqBn| djoTt}yt| ƒ} Wn$tj otdƒt} PnXd} |i| } n| |jp | | joJ| djo/| dd d gjotd| ƒt} Pn| || |D]6}|i|ƒo |i|i|i |i ƒq q W|ii ƒdS(s”Discard 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( RÔRNR`R3RäRóRåRrRŠR‹RtRd(RÔRäRó((RReus   $cCs t|iƒS(N(RFRÔRO(RÔ((Rt__iter__†scCs%d}x|D]}|d}q W|S(s#Return number of contained cookies.iiN(R¥RÔRó(RÔR¥Ró((Rt__len__‰s cCsDg}x!|D]}|it|ƒƒq Wd|idi|ƒfS(Ns<%s[%s]>s, (trRÔRóRzRìt __class__R‡(RÔR‹Ró((RRí�s cCsDg}x!|D]}|it|ƒƒq Wd|idi|ƒfS(Ns<%s[%s]>s, (R‹RÔRóRzR-RŒR‡(RÔR‹Ró((RRé”s ( RîRïRðR|tcompileR[R\tstrict_domain_ret domain_retdots_retmagic_reRRÞRPRTRVR]R^RoRtRuR�RƒR‚R‡RrRˆReR‰RŠRíRé(((RRI¡s6      < # a X 4     t LoadErrorcBstZRS(N(RîRï(((RR’›st FileCookieJarcBsVtZdZeeed„Zeeed„Zeeed„Zeeed„ZRS(s6CookieJar that can be loaded from and saved to a file.cCs_ti||ƒ|dj o&y |dWqCtdƒ‚qCXn||_t|ƒ|_dS(s} Cookies are NOT loaded from the named file until either the .load() or .revert() method is called. RWsfilename must be string-likeN( RIRÞRÔRJtfilenameRRLRqt delayload(RÔR”R•RJ((RRÞ s   cCs tƒ‚dS(sSave cookies to a file.N(Rò(RÔR”tignore_discardtignore_expires((Rtsave¯scCsr|djo-|idj o |i}q:ttƒ‚nt|ƒ}z|i||||ƒWd|i ƒXdS(sLoad cookies from a file.N( R”RRÔRLtMISSING_FILENAME_TEXTtopenR t _really_loadR–R—tclose(RÔR”R–R—R ((Rtload³s   cCs²|djo-|idj o |i}q:ttƒ‚n|iiƒti|i ƒ}h|_ y|i |||ƒWn%ttfj o||_ ‚nX|iiƒdS(sÈClear all cookies and reload cookies from a saved file. Raises LoadError (or IOError) if reversion is not successful; the object's state will not be altered if this happens. N(R”RRÔRLR™RNR`RÛtdeepcopyROt old_stateR�R–R—R’tIOErrorRd(RÔR”R–R—RŸ((Rtrevert¿s     ( RîRïRðRR•RÞR˜R�R¡(((RR“�s  (s LWPCookieJarslwp_cookie_str(sMozillaCookieJar(XRðRR|R®RÛR3RÈtloggingttypesRnt threadingRLt ImportErrortdummy_threadingthttplibtcalendarRt getLoggerRÁR-t HTTP_PORTRÂR™RRRR8R9RIRRzRKRR6R:RBR�RCRHRVRXtIR^tXR`RaRbRdRjRsRuRxRwR€R†RˆRžR R¡R¦R§R©R±R²R¶R¾RÃRÊRËRÄR»RÏRÑRÒRñRøR@RFRHRIR R’R“t _LWPCookieJart LWPCookieJartlwp_cookie_strt_MozillaCookieJartMozillaCookieJar(FR R¦RÊRËR’RÑR@R¯RRRñRjR6RbRR©R®RøRÄRuRRdR¡R»R€RÈR†R²R|R:RVR±RnRBR¾RxR±RÒRsRHRIR¶R™RÏR§RCRRIRFRRÛRwRˆR§R¢R“RLR9RaR8RHR®R^RÂR3RÁRžRÃRXR`((Rt?sŒ?      *  *  5 8 !  U  8  '       # ^!ÿM  ÿû: