bg?+ldZddlmZddlmZddlmZddlmZddlmZmZm Z m Z m Z ddl m Z mZgdZdd lZdd lZdd lZerde_dd lZdd lmZmZmZdd lmZ dd lZn#e$rdd lZYnwxYwdd lm Z d Z!d a"dZ#e eZ$dZ%dZ&dZ'dZ(gdZ)gdZ*gZ+e*D])Z,e+-e,.*dPdZ/dPdZ0d d d d dZ1ej2dejZ3dZ4dZ5ej2dejZ6ej2dej7ejzZ8ej2dej9ejzZ:dZ;ej2dej9ejzZej2d"Z?ej2d#Z@ej2d$ZAej2d%ZBd&ZCej2d'ZDd(ZEd)ZFd*ZGej2d+ejZHd,ZId-ZJd.ZKd/ZLej2d0ejZMd1ZNd2ZOd3ZPd4ZQd5ZRej2d6ZSd7ZTd8ZUd9ZVd:ZWGd;deXZZGd?d@eZZ[dAZ\dBZ]GdCdDeXZ^GdEdFeXZ_GdGdHe`ZaGdIdJe_ZbdKZcGdLdMebZdGdNdOebZed S)QaHTTP cookie handling for web clients. This is a backport of the Py3.3 ``http.cookiejar`` module for python-future. 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 )unicode_literals)print_function)division)absolute_import)filterintmapopenstr) as_native_strPY2)Cookie CookieJar CookiePolicyDefaultCookiePolicy FileCookieJar LWPCookieJar LoadErrorMozillaCookieJarN)urlparseurlsplitquote) HTTP_PORT)timegmFcptsdStsddl}|datj|S)Nrzhttp.cookiejar)debugloggerlogging getLogger)argsrs p/builddir/build/BUILD/cloudlinux-venv-1.0.7/venv/lib/python3.11/site-packages/future/backports/http/cookiejar.py_debugr":sA  5""#344 < zQa filename was not supplied (nor was the CookieJar instance initialised with one)cddl}ddl}ddl}|}|d||}|d|zddS)Nrzhttp.cookiejar bug! %s) stacklevel)iowarnings tracebackStringIO print_excgetvaluewarn)r'r(r)fmsgs r!_warn_unhandled_exceptionr0Hsz#""""""""""" A a   **,,C MM+c1aM@@@@@r#ic|dd\}}}}}}|tkr_d|cxkrdkrRnnOd|cxkrdkrBnn?d|cxkrdkr2nn/d|cxkrdkr"nnd|cxkrdkrnnt|SdS) N r;=) EPOCH_YEARr)ttyearmonthmdayhourminsecs r!_timegmrAWs(*2A2%D%tS#   !u"2"2"2"2"2"2"2"2"2db dbqC~~~~2~~~~~ANNNNNNNNNbzztr#)MonTueWedThuFriSatSun) JanFebMarAprMayJunJulAugSepOctNovDecc|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<dayr>minutesecondtdts r! time2isozr_esc y   % % ' '   / / 2 2 + 2627BIry/B BBr#c,|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 GMTr3) rVrWrXDAYSweekdayrYMONTHSr<r;r>rZr[r\s r! time2netscaperdxsy y   % % ' '   / / 2 2 / RZZ\\BFF28A:$6 ")RY30 00r#)GMTUTCUTZz^([-+])?(\d\d?):?(\d\d)?$cVd}|tvrd}nt|}|r~dt|dz}|dr(|dt|dzz}|ddkr| }|S)Nrir%<r3-) UTC_ZONES TIMEZONE_REsearchrgroup)tzoffsetms r!offset_from_tz_stringrts F Y   r " "  !C OO+Fwwqzz 7"s1771::"66wwqzzS    Mr#c   t|dz}nI#t$r< t |}n#t$rYYdSwxYwd|cxkrdkrnn|}nYdSYnwxYw|d}|d}|d}t |}t |}t |}t |}t |}|dkrct jt jd}|dz} |} ||z| z }| | z } t| dkr| dkr|dz}n|dz }t|||||||f} | 0|d}| }t|} | dS| | z } | S)Nr3r4rid2rf) MONTHS_LOWERindexlower ValueErrorrtime localtimeabsrAupperrt) rYmonyrhrr?r@rqimoncur_yrrstmpr]rrs r! _str2timers   --a/     s88DD   444  ?????????CC44 C  z2 {!C {!C RB c((C RB c((C c((C Dyy ,,Q/ SL &[1_ G q66B;;1uu28bbCx" S#r3R011A} :B XXZZ&r** >4 J Hs2/2 A8A  A8 AA8AA87A8zV^[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. r3r%rrjN)STRICT_DATE_RErogroupsrxryrzrfloatrAlstrip WEEKDAY_REsubLOOSE_HTTP_DATE_REr) textrsgrr:rYrrr?r@rqs 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 44r#a^ (\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_RErorr) rrYrrrr?r@rqrs_s r!iso2timer6s ;;==D'+VAX"Cb"c3 4  A}-.HHJJ)Cb#sBt S#r2sC 4 44r#cp|d\}}|jd||j|dzS)z)Return unmatched part of re.Match object.rN)spanstring)matchstartends r! unmatchedrWs6AJE3 <  STT 2 22r#z^\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"')]] r3z\1N,z^[=\s;]*rrzsplit_header_words bug: 'z', 'z', ) isinstancer HEADER_TOKEN_RErorrpHEADER_QUOTED_VALUE_REHEADER_ESCAPE_RErHEADER_VALUE_RErstripappendr startswithresubn) header_valuesresultr orig_textpairsrsnamevaluenon_junk nr_junk_charss r!split_header_wordsr`sZ----- - F#'#'  &&t,,A  ||wwqzz*11$77 %$Q<>EE'..t44A%(|| !  % !% dE]++++))#.. {{}}QRR(.&--...+-'*b$*G*G'-$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"=; , )rroHEADER_JOIN_ESCAPE_RErrjoin)listsheadersrattrkvs r!join_header_wordsrsG 1 1  DAq}y1--#-11'1==A A qq!!$ KKNNNN 0 $000 99W  r#c|dr |dd}|dr |dd}|S)N"r3)rendswithrs r! strip_quotesrsI sABBx }}SCRCy Kr#cRd}g}|D]}g}d}ttjd|D]\}}|}|dkr d|vr|d} }n-tjd|d\}} |}|d krS|} | |vr| }|d krt | } d }|d krtt | } ||| f|r,|s|d || |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-ageFz;\s*rrNz\s*=\s*r3rrTr)r0) enumeratersplitrrrzrrr) ns_headers known_attrsr ns_headerr version_setiiparamrrlcs r!parse_ns_headersrsQ1KF!!  "28GY#?#?@@ ! !IBLLNNE{{H%d1x E1551HHJJQwwWWYY$$A >>$QA"&K >>!,q//22A LL!Q  ! / -... MM% Mr#z\.\d+$ct|rdS|dkrdS|ddks |ddkrdSdS)z*Return True if text is a host domain name.Frr.rTIPV4_RErors r!is_HDNr sN~~du rzzu Aw#~~bSu 4r#c.|}|}||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. TFrrrr3N)rzrrfindr)ABis r! domain_matchrs.  A  AAvvt !99u  ABww!q&&u <<  u !ABB%==u 4r#c>t|rdSdS)zdReturn True if text is a sort-of-like a host domain name. For accepting/blocking domains. FTrrs r!liberal_is_HDNrAs" ~~du 4r#c|}|}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)rzrrr)rr initial_dots r!user_domain_matchrKs  A  A 1  ."3"3 664u,,s##Kqzz!}}t 166t 5r#z:\d+$c|}t|d}|dkr|dd}td|d}|S)zReturn request-host, as defined by RFC 2965. Variation from RFC: returned value is lowercased, for convenient comparison. r3rHost) get_full_urlr get_header cut_port_rerrz)requesturlhosts r! request_hostr`sh    C C== D rzz!!&"-- ??2tQ ' 'D ::<<r#ct|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)rfindrro)rerhnreq_hosts r!eff_request_hostrpsR #7+++D8}}SRx(@(@(" T>r#c|}t|}t|j}|dsd|z}|S)z6Path component of request-URI, as defined by RFC 2965./)rr escape_pathrr)rrpartsrs r! request_pathr{sO    C SMME uz " "D ??3  Tz Kr#c|j}|d}|dkr?||dzd} t|n(#t$rt d|YdSwxYwt }|S)N:rr3znonnumeric port: '%s')rrrr{r"DEFAULT_HTTP_PORT)rrrrs r! request_portrs >> reach("www.acme.com") '.acme.com' >>> reach("acme.com") 'acme.com' >>> reach("acme.local") '.local' rrr3Nlocal)rr)hrbs r!reachrsh4 s AAvv acddG FF3KK !99 !q&&ALLq5L Hr#ct|}t|t|sdSdS)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)rrrget_origin_req_host)rrs r!is_third_partyrsAG$$H %(C(C(E(E"F"F G Gtur#cdeZdZdZ d dZdZd dZdZd dZd Z e 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|}| t| } ||durtd||_||_||_||_||_||_||_ ||_ | |_ | |_ | |_ | |_| |_||_||_||_t'j||_dS)NTz-if port is None, port_specified must be false)rr{rrrrport_specifiedrzrdomain_specifieddomain_initial_dotrpath_specifiedrrdiscardcomment comment_urlrfc2109copy_rest)selfrrrrrrrrrrrrrrrrestrs r!__init__zCookie.__init__s  #g,,  #g,, +>4ur#c|jd}n d|jz}|j|z|jz}|j|jd|j}n|j}d|d|dS)Nrrrz)rrrrr)rplimit namevalues r!__str__zCookie.__str__$sf 9 "aadi-a a$)+ : !#'999djj9II I'0yy%%%88r#cg}dD]j}t||}t|trt|}|td|t |fzk|dt |jz|dt |jzdd|zS)N)rrrrrrrrrrrrrrrz%s=%szrest=%sz rfc2109=%sz Cookie(%s)r)getattrrr rreprrrr)rr rrs r!__repr__zCookie.__repr__.s ; ;D 4&&D$$$ !4yy KKG d4jj'99 : : : : ITZ 0 00111 L4 #5#55666diioo--r#)Fr") __name__ __module__ __qualname____doc__r r$r(r*r.r4r r8r#r!rrs6(%(%(%(%T"""----!!! 999]__.._...r#rc*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 customised 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. NotImplementedErrorrcookiers r!set_okzCookiePolicy.set_okLs"###r#ct)zAReturn true if (and only if) cookie should be returned to server.r@rBs r! return_okzCookiePolicy.return_okU!###r#cdS)zMReturn false if cookies should not be returned, given cookie domain. Tr=)rrrs r!domain_return_okzCookiePolicy.domain_return_okY tr#cdS)zKReturn false if cookies should not be returned, given cookie path. Tr=)rrrs r!path_return_okzCookiePolicy.path_return_ok^rJr#N)r9r:r;r<rDrFrIrLr=r#r!rrCsZ$$$$$$ r#rc eZdZdZdZdZdZdZeezZdddddddddeddf d Z d Z d Z d Z d Z dZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdS) rzBImplements the standard rules for accepting and returning cookies.r3r%rrNTFc ||_||_||_||_||_||_| |_| |_| |_| |_ |t||_ nd|_ |t|}||_ dS)zAConstructor arguments should be passed as keyword arguments only.Nr=) 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_domainsrOrPrQrRrSrTrUrVrWrXs r!r zDefaultCookiePolicy.__init__ns!  #6 (*+F(&<# 0,H)"4  &$)/$:$:D ! !$&D !  &#O44O /r#c|jS)z4Return the sequence of blocked domains (as a tuple).)rZrs r!r\z#DefaultCookiePolicy.blocked_domains $$r#c.t||_dS)z$Set the sequence of blocked domains.N)rYrZ)rr\s r!set_blocked_domainsz'DefaultCookiePolicy.set_blocked_domainss %o 6 6r#c@|jD]}t||rdSdSr,)rZr)rrblocked_domains r! is_blockedzDefaultCookiePolicy.is_blockeds7"3  N 88 tt ur#c|jS)z=Return None, or the sequence of allowed domains (as a tuple).)r[r_s r!r]z#DefaultCookiePolicy.allowed_domainsr`r#c6|t|}||_dS)z-Set the sequence of allowed domains, or None.N)rYr[)rr]s r!set_allowed_domainsz'DefaultCookiePolicy.set_allowed_domainss#  &#O44O /r#cR|jdS|jD]}t||rdSdS)NFT)r[r)rrallowed_domains r!is_not_allowedz"DefaultCookiePolicy.is_not_allowedsE  (5"3  N 88 uu tr#ctd|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_FTr"rrr6rrCrnfn_namefns r!rDzDefaultCookiePolicy.set_oksw )6; EEE{&&&M  AkGw''B2fg&& uu tr#c|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)rr"rrrPrOrBs r!set_ok_versionz"DefaultCookiePolicy.set_ok_versions > ! E;  . . .5 >A  dl  9 : : :5 ^q  9 : : :5tr#c|jrUt|rF|jdkr|jrt ddS|jdkr|jrt ddSdSNrz> third-party RFC 2965 cookie during unverifiable transactionFz> third-party Netscape cookie during unverifiable transactionT unverifiablerrrTr"rUrBs r!set_ok_verifiabilityz(DefaultCookiePolicy.set_ok_verifiabilitys   N7$;$; ~!!d&F!8999u1$$)D$8999utr#c|jdkr8|jr1|jdrt d|jdSdS)Nr$z' illegal name (starts with '$'): '%s'FT)rrWrrr"rBs 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)rrr rrrr{r"rrCrreq_portr1s r! set_ok_portzDefaultCookiePolicy.set_ok_port*s   #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). rm)rrnrrrr return_ok_FTrprqs r!rFzDefaultCookiePolicy.return_ok?sg )6; EEER  A"1nGw''B2fg&& uu tr#c|jdkr|jstddS|jdkr|jstddSdS)NrrvFrwT)rrPr"rOrBs r!return_ok_versionz%DefaultCookiePolicy.return_ok_versionQsW >A  dl  9 : : :5 ^q  9 : : :5tr#c|jrUt|rF|jdkr|jrt ddS|jdkr|jrt ddSdSrzr{rBs r!return_ok_verifiabilityz+DefaultCookiePolicy.return_ok_verifiabilityZs   N7$;$; ~!!d&F!%&&&u1$$)D$%&&&utr#cL|jr|jdkrtddSdS)Nhttpsz( secure cookie with non-secure requestFT)rtyper"rBs r!return_ok_securez$DefaultCookiePolicy.return_ok_securefs1 = W\W44 = > > >5tr#c\||jrtddSdS)Nz cookie expiredFT)r._nowr"rBs r!return_ok_expiresz%DefaultCookiePolicy.return_ok_expiresls3   TY ' '  & ' ' '5tr#c|jrPt|}|d}|jdD] }||krn td||jdSdS)Nrrz0 request port %s does not match cookie port %sFT)rrrr"rs r!return_ok_portz"DefaultCookiePolicy.return_ok_portrs~ ; #G,,H[&&s++  ==E!I...utr#cpt|\}}|j}|jdkr-|j|jzr|js||krt ddS|jdkr#t||st d||dS|jdkr+d|z|st d||dSdS)NrzQ 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 %srz; request-host %s does not match Netscape cookie domain %sT) rrrrVDomainStrictNonDomainrr"rr)rrCrrrrs r!return_ok_domainz$DefaultCookiePolicy.return_ok_domains)'22$ Na    "T%? ? ' ,2dNN - . . .5 >A  l4&@&@  /04f > > >5 >Q  D':':6'B'B  !6 + + +5tr#ct|\}}|dsd|z}|dsd|z}||s||sdS||rt d|dS||rt d|dSdS)NrFrrT)rrrrer"rk)rrrrrs r!rIz$DefaultCookiePolicy.domain_return_oks*'22$""3'' $8|Hs## t8D!!&)) T]]6-B-B 5 ??6 " "  7 @ @ @5   v & &  ;V D D D5tr#ctd|t|}||std||dSdS)Nz- checking cookie path=%sz %s does not path-match %sFT)r"rr)rrrrs r!rLz"DefaultCookiePolicy.path_return_oksS*D111((""4((  0(D A A A5tr#) r9r:r;r<rrr DomainLiberal DomainStrictr r\rbrer]rhrkrDrxr}rrrrrFrrrrrrrIrLr=r#r!rrdsLLM%&;;L"&t%)#$-1(-"/.3$)0000B%%%777 %%%000 &         999v*$       ,,r#rcnt|}t|j|Sr")sortedkeysr r&)adictrs r!vals_sorted_by_keyrs) %**,,  D uy$  r#c#Kt|}|D];}d} |jd}t|D]}|Vn#t$rYnwxYw|s|V(**F '-// r#c||_dSr")rrs r! set_policyzCookieJar.set_policys  r#cg}|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) rrIr"rrrLrrFr)rrrcookiescookies_by_pathrcookies_by_namerCs r!_cookies_for_domainzCookieJar._cookies_for_domains|,,VW== I2F;;;-/#((** ' 'D<..tW== -d3O)0022 ' '|--fg>>4555()))v&&&&  ' r#cg}|jD]+}||||,|S)z2Return a list of cookies to be returned to server.)rrextendr)rrrrs r!_cookies_for_requestzCookieJar._cookies_for_requestsPm((** F FF NN433FGDD E E E Er#c>|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 r!z)CookieJar._cookie_attrs.. s3qv;;r#T)keyreverseFrz $Version=%sNrrz $Path="%s"rr3z $Domain="%s"z$Portz="%s")sortrrr non_word_reroquote_rerrrrrrrrr) rrrattrsrCrrrr1s r! _cookie_attrszCookieJar._cookie_attrss  .. === ( $( $FnG :" Q;;LL!8999 ) '' 55*:AA++ ))'6<@@ |# V[))))  UU;<<<{{(=LL !;<<<=++C00:#]F"5,))#..,!'LL&!8999;*A,86;!67LLOOO r#ctd|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_headerrrCookie2r3z $Version="1"N)r"racquirerr|rrrr has_headeradd_unredirected_headerrrPrRrreleaseclear_expired_cookies)rrrrrCs r!rzCookieJar.add_cookie_header<ss "### ""$$$ ),/ ,<,<
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 commenturlrFr3NTrz% 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)rzr"rr{rr)r attrs_set cookie_tuples boolean_attrs value_attrs cookie_attrsrr max_age_set bad_cookiestandardrrrrs r!_normalized_cookie_tuplesz#CookieJar._normalized_cookie_tuples]s + 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)NrrrrrrFrrrrTrrrr3rz\s+z2Expiring cookie, domain='%s', path='%s', name='%s')r&rrr{rrrrboolrrrrrrclearKeyErrorr"r)rtuprrrrrrrrrrrrrrrrrrrrrs 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_rfc2965[s #*ININJCf,,r#)rget_allrrPrOr r Exceptionr0rr rrrrr) rresponserr rfc2965_hdrsns_hdrsrPrOr ns_cookiesrrCrs r! make_cookieszCookieJar.make_cookies/s--//}b99 //,33,&<( g  !(  &.  #* I 22"<00';;GG    % ' ' 'GGG   +x + !99$W--w88    )+++    ) )* 5 5 5 E%MMFHLFFM6; DEE:@----$$7DD  +z***s$,#BB-,B-5#CC65C6cj|j ttjx|j_|_|j||r|||jdS#|jwxYw)z-Set a cookie if policy says it's OK to do so.N) rrrr|rrrD set_cookierrBs r!set_cookie_if_okzCookieJar.set_cookie_if_okes ""$$$ ),/ ,<,<
> , ,<&&vw77,0&999OOF+++ ,   & & ( ( ( ( (D  & & ( ( ( (s B C##C>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)r{r)rrrrs r!rzCookieJar.clears  DL NPPP f%d+D111  ~ DFFF f%d+++   f%%%DMMMr#c|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)rrrrrrrr)rrCs r!clear_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) rrr|r.rrrrr)rr-rCs r!rzCookieJar.clear_expired_cookiess ""$$$ ))++C H H$$S))HJJv}fk6;GGG H   & & ( ( ( ( (D  & & ( ( ( (s AB B%c*t|jSr")rrr_s r!__iter__zCookieJar.__iter__s$-(((r#cd}|D]}|dz}|S)z#Return number of contained cookies.rr3r=)rrrCs r!__len__zCookieJar.__len__s! %%FAAAr#cg}|D]$}|t|%d|jdd|dSN<[rz]>)rr7 __class__rrrrCs r!r8zCookieJar.__repr__sN 22FAHHT&\\22222!^^^TYYq\\\\::r#cg}|D]$}|t|%d|jdd|dSr+)rr r.rr/s r!r4zCookieJar.__str__sN 11FAHHS[[11111!^^^TYYq\\\\::r#r")NNN)#r9r:r;r<rcompilerrstrict_domain_re domain_redots_reASCIImagic_rer rrrrrrrr r rrrr!rr$rr'r)r r8r4r=r#r!rrs "*U##Krz+&&H!rz+.. 8$$Ibj!!Grz6AAH$999v%%%B___BZZZx ' ' '444l ) ) ) ) ) ) ) ) )6 ) ) ))))&))) ]__;;_; ;;;;;r#rceZdZdS)rNrr=r#r!rrrr#rc6eZdZdZddZd dZd dZ d dZdS) rz6CookieJar that can be loaded from and saved to a file.NFct||| |dzn#tdxYw||_t ||_dS)z} Cookies are NOT loaded from the named file until either the .load() or .revert() method is called. Nrzfilename must be string-like)rr r{filenamer delayload)rr;r<rs r!r zFileCookieJar.__init__sb 4(((   A  A !?@@@  is%6ct)zSave cookies to a file.r@)rr;ignore_discardignore_expiress r!savezFileCookieJar.saverGr#c|#|j|j}nttt|} ||||||dS#|wxYw)zLoad cookies from a file.N)r;r{MISSING_FILENAME_TEXTr _really_loadcloserr;r>r?r.s r!loadzFileCookieJar.loadst  }(T](("#8999 NN    a>> J J J GGIIIIIAGGIIIIs A$$A:c|#|j|j}ntt|j t j|j}i|_ ||||n#ttf$r ||_wxYw |j dS#|j wxYw)zClear 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;r{rBrrrdeepcopyrrFrIOErrorr)rr;r>r? old_states r!revertzFileCookieJar.reverts  }(T](("#8999 ""$$$ ) dm44IDM  (NNCCCCw'    )  D   & & ( ( ( ( (D  & & ( ( ( (s$ B2!A98B29BB22C )NFNNFF)r9r:r;r<r r@rFrKr=r#r!rrsr@@ ) ) ) )$$$$    #49))))))r#rc|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 an the LWP cookie file format. Actually, the format is extended a bit -- see module docstring. rrNr) path_specN) port_specN) domain_dotN)rNr)rNrrr)rrrrrrrrrrrr_rrrrrrrr rr)rCr rrs r!lwp_cookie_strrQs +v| $ &+  FM " $A{&&+)> ? ? ? ;ahh':;;; ;ahh':;;;  @!((+?"@"@"@ }0ahh/000 ~Bqxx(v~)>)>??!ABBB ~2qxx 1222 ~r?r-r0rCs r! as_lwp_strzLWPCookieJar.as_lwp_strHs ikk  A AF! fn ! f&7&7&<&<  HH&)?)?? @ @ @ @yyB4   r#NFcH|#|j|j}nttt|d} |d|||||dS#|wxYw)Nwz#LWP-Cookies-2.0 )r;r{rBr writerUrDrEs r!r@zLWPCookieJar.saveXs  }(T](("#8999 3    GG( ) ) ) GGDOONNCC D D D GGIIIIIAGGIIIIs >B B!c|}|j|sd|z}t|t j}d}d} d} |} | dkrdS| |s3| t |d} t| gD]f} | d\} }i}i}| D]}d||<| ddD]E\}}|| }nd}|| vs|| vr|}|| vr |d }|||<6|| vr|||<@|||<F|j }|d }|d }|t|}|d }|d }|d }t|d| ||d|d|||d|d|d|d|||d|d|}|s |j r8|s||rQ||h#t $rt"$r$t%td|d| wxYw)Nz5%r does not look like a Set-Cookie3 (LWP) format filez Set-Cookie3:)rOrNrPrr)rrrrrrrr3rrFTrrrrrrrOrPrrNrrrz invalid Set-Cookie3 format file : )readliner7rorr|rrstriprrzr&rrrr.rrIrr0)rr.r;r>r?magicr/r-headerrrlinedatarrrrrrrr rrrrrs r!rCzLWPCookieJar._really_loadgs% }##E** !$%CC.. ikk. 0 < .4 'zz||2::uuv..CKKLL)//11.v66-'-'D"&q'KD%!HD*,,&+ $QRR((1=!"BB!%B+--23F3F "A -- yd!*+HQKK+--*+HQKK&'DGG Aa llGa llG*"*7"3"3"&Qx[[F'-'8'8'='=$qq||T5 qyy!!K..%'7< qyy!!K.. q{{&& q|| q# % %A*!ai! )!all3.?.?! OOA&&&&i4 'l     . . . % ' ' ')%XXtt-.. . .sH3:F9H338I+)TTrL)r9r:r;r<rUr@rCr=r#r!rr;sZ  !!!!    M.M.M.M.M.r#rcDeZdZdZejdZdZdZddZ dS) ra WARNING: you may want to backup your browser's cookies file if you use this class to save cookies. I *think* it works, but there have been bugs in the past! This class differs from CookieJar only in the format it uses to save and load cookies to and from a file. This class uses the Mozilla/Netscape `cookies.txt' format. lynx uses this file format, too. Don't expect cookies saved while the browser is running to be noticed by the browser (in fact, Mozilla on unix will overwrite your saved cookies if you change them on disk while it's running; on Windows, you probably can't save at all while the browser is running). Note that the Mozilla/Netscape format will downgrade RFC2965 cookies to Netscape cookies on saving. In particular, the cookie version and port number information is lost, together with information about whether or not Path, Port and Discard were specified by the Set-Cookie2 (or Set-Cookie) header, and whether or not the domain as set in the HTTP header started with a dot (yes, I'm aware some domains in Netscape files start with a dot and some don't -- trust me, you really don't want to know any more about this). Note that though Mozilla and Netscape use the same format, they use slightly different headers. The class saves cookies using the Netscape header by default (Mozilla can cope with that). z#( Netscape)? HTTP Cookie Filez~# Netscape HTTP Cookie File # http://www.netscape.com/newsref/std/cookie_spec.html # This is a generated file! Do not edit. ctj}|}|j|s&|t d|z |}|dkrdS|dr |dd}|ds|dkr|| d\}} } } } } }| dk} | dk} | dkr|} d}|d }| |ksJd }| dkrd} d }td | |dd || || d | | |ddi}|s |j r|s| |r| |0#t$rt$r$t!t d |d|wxYw)Nz4%r does not look like a Netscape format cookies filer3rrTr)#r TRUErFTrz%invalid Netscape format cookies file rZ)r|r[r7rorDrrr\rrrrr.rrIrr0)rr.r;r>r?r-r]r_rrrrrrrrrrs r!rCzMozillaCookieJar._really_loadsLikk }##E**  GGIIIF 6 .. #zz||2::uu==&&8tCRCyJJLL++J77JJLLB&& 4((M($u F*$4$> 2::!D E$//44 ';6666b=="G"G1dE!#3[!""  &!)%!,,s*;*;"""]. #`     . . . % ' ' ')%XXtt-.. . .s)FDF8GNFc |#|j|j}nttt|d} ||jt j}|D]}|s|jr |s||r$|j rd}nd}|j drd}nd}|j t|j } nd} |j d} |j} n|j} |j} |d|j ||j|| | | gdz |dS#|wxYw)NrWreFALSErrrdrT)r;r{rBr rXr^r|rr.rrrrr rrrrrD) rr;r>r?r.r-rCrrrrrs r!r@zMozillaCookieJar.save s  }(T](("#8999 3    GGDK )++C  %&.%&*;*;C*@*@='6&&&f=++C00,++$+k>-!&.11GG G<'D"KEE!;D"LEIIv}k6;%we=>>- 6 GGIIIIIAGGIIIIs C8EErL) r9r:r;r<rr2r7r^rCr@r=r#r!rrs`<rz:;;HF@.@.@.D$$$$$$r#rr")fr< __future__rrrrfuture.builtinsrrr r r future.utilsr r __all__rrVrr6r|future.backports.urllib.parserrrfuture.backports.http.clientr threadingr ImportErrordummy_threadingcalendarrrrr"rrBr0r9rArarcrxr<rrzr_rdrmr2rnrtrrIrXrrrrrrrrrrrrrrrrrrrrrrrrrr rrrrobjectrrrrrrrrIrrrQrrr=r#r!rus<('''''%%%%%%&&&&&&77777777777777++++++++ M M M  BH CCCCCCCCCC222222)""""")))(((((()  C NN:AAA 988 4 4 4 77E\((7777BBBB&0000(T = = bj5rx@@    3 3 3 j+,.H66RZ2BD28OEE RZ & D28O)*656565pbj 4") # $555B333 $$677#$MNN#$9::2:h''SSSj# ;//2111h "*Y ) )   %%%N(bj28,,        $"*9::+++   ! ! ! F"e.e.e.e.e.Ve.e.e.P6BNNNNN,NNNb    &VN;N;N;N;N;N;N;N;d:):):):):)I:):):)z"""8y.y.y.y.y.=y.y.y.xMMMMM}MMMMMsA$$ A0/A0