o ,]MT@sdZddlmZddlmZddlmZddlmZddlmZmZm Z m Z ddl m Z m Z ddlZe r7de_ddlZgd Zd jZd jZd jZGd ddeZejejdZiddddddddddddddddd d!d"d#d$d%d&d'd(d)d*d+d,d-d.d/d0d1id2d3d4d5d6d7d8d9d:d;dd?d@dAdBdCdDdEdFdGdHdIdJdKdLdMdNdOdPdQdRdSidTdUdVdWdXdYdZd[d\d]d^d_d`dadbdcdddedfdgdhdidjdkdldmdndodpdqdrdsdtduidvdwdxdydzd{d|d}d~dddddddddddddddddddddddddiddddddddddddddddddddddddddddddddddiddddddddddÓddœddǓddɓdd˓dd͓ddϓddѓddӓddՓddדddٓddۓiddݓddߓddddddddddddddddddddddddddddddidddddddddddd d d d d ddddddddddddddddddid d!d"d#d$d%d&d'd(d)d*d+d,d-d.d/d0d1d2d3d4d5d6d7d8d9d:d;d<d=d>d?d@dAdBdCdDdEdFdGdHdIdJdKdLdMdN ZefdOdPZedQZedRZdSdTZ gdUZ!gdVZ"de!e"fdWdXZ#GdYdZdZeZ$d[Z%ed\e%d]e%d^ejZ&Gd_d`d`eZ'Gdadbdbe'Z(dS(caf http.cookies module ported to python-future from Py3.3 Here's a sample session to show how to use this module. At the moment, this is the only documentation. The Basics ---------- Importing is easy... >>> from http import cookies Most of the time you start by creating a cookie. >>> C = cookies.SimpleCookie() Once you've created your Cookie, you can add values just as if it were a dictionary. >>> C = cookies.SimpleCookie() >>> C["fig"] = "newton" >>> C["sugar"] = "wafer" >>> C.output() 'Set-Cookie: fig=newton\r\nSet-Cookie: sugar=wafer' Notice that the printable representation of a Cookie is the appropriate format for a Set-Cookie: header. This is the default behavior. You can change the header and printed attributes by using the .output() function >>> C = cookies.SimpleCookie() >>> C["rocky"] = "road" >>> C["rocky"]["path"] = "/cookie" >>> print(C.output(header="Cookie:")) Cookie: rocky=road; Path=/cookie >>> print(C.output(attrs=[], header="Cookie:")) Cookie: rocky=road The load() method of a Cookie extracts cookies from a string. In a CGI script, you would use this method to extract the cookies from the HTTP_COOKIE environment variable. >>> C = cookies.SimpleCookie() >>> C.load("chips=ahoy; vienna=finger") >>> C.output() 'Set-Cookie: chips=ahoy\r\nSet-Cookie: vienna=finger' The load() method is darn-tootin smart about identifying cookies within a string. Escaped quotation marks, nested semicolons, and other such trickeries do not confuse it. >>> C = cookies.SimpleCookie() >>> C.load('keebler="E=everybody; L=\\"Loves\\"; fudge=\\012;";') >>> print(C) Set-Cookie: keebler="E=everybody; L=\"Loves\"; fudge=\012;" Each element of the Cookie also supports all of the RFC 2109 Cookie attributes. Here's an example which sets the Path attribute. >>> C = cookies.SimpleCookie() >>> C["oreo"] = "doublestuff" >>> C["oreo"]["path"] = "/" >>> print(C) Set-Cookie: oreo=doublestuff; Path=/ Each dictionary element has a 'value' attribute, which gives you back the value associated with the key. >>> C = cookies.SimpleCookie() >>> C["twix"] = "none for you" >>> C["twix"].value 'none for you' The SimpleCookie expects that all values should be standard strings. Just to be sure, SimpleCookie invokes the str() builtin to convert the value to a string, when the values are set dictionary-style. >>> C = cookies.SimpleCookie() >>> C["number"] = 7 >>> C["string"] = "seven" >>> C["number"].value '7' >>> C["string"].value 'seven' >>> C.output() 'Set-Cookie: number=7\r\nSet-Cookie: string=seven' Finis. )unicode_literals)print_function)division)absolute_import)chrdictintstr)PY2 as_native_strN) CookieError BaseCookie SimpleCookiez;  c@s eZdZdS)r N)__name__ __module__ __qualname__rr?/usr/lib/python3/dist-packages/future/backports/http/cookies.pyr sr z!#$%&'*+-.^_`|~:z\000z\001z\002z\003z\004z\005z\006z\007z\010 z\011 z\012 z\013 z\014 z\015z\016z\017z\020z\021z\022z\023z\024z\025z\026z\027z\030z\031z\032z\033z\034z\035z\036z\037,z\054;z\073"\"\z\\z\177€z\200z\201‚z\202ƒz\203„z\204…z\205†z\206‡z\207ˆz\210‰z\211Šz\212‹z\213Œz\214z\215Žz\216z\217z\220‘z\221’z\222“z\223”z\224•z\225–z\226—z\227˜z\230™z\231šz\232›z\233œz\234z\235žz\236Ÿz\237 z\240¡z\241¢z\242£z\243¤z\244¥z\245¦z\246§z\247¨z\250©z\251ªz\252«z\253¬z\254­z\255®z\256¯z\257°z\260±z\261²z\262³z\263´z\264µz\265¶z\266·z\267¸z\270¹z\271ºz\272»z\273¼z\274½z\275¾z\276¿z\277Àz\300Áz\301Âz\302Ãz\303Äz\304Åz\305Æz\306Çz\307Èz\310Éz\311Êz\312Ëz\313Ìz\314Íz\315Îz\316Ïz\317Ðz\320Ñz\321Òz\322Óz\323Ôz\324Õz\325Öz\326×z\327Øz\330Ùz\331Úz\332Ûz\333Üz\334Ýz\335Þz\336ßz\337àz\340áz\341âz\342ãz\343äz\344åz\345æz\346çz\347èz\350éz\351êz\352ëz\353ìz\354íz\355îz\356ïz\357ðz\360ñz\361òz\362óz\363z\364z\365z\366z\367z\370z\371z\372z\373z\374z\375z\376z\377) ôõö÷øùúûüýþÿcs4tfdd|Dr |Sdtdd|DdS)zQuote a string for use in a cookie header. If the string does not need to be double-quoted, then just return the string. Otherwise, surround the string in doublequotes and quote (with a \) special characters. c3s|]}|vVqdSNr.0c LegalCharsrr z_quote..r8css|] }t||VqdSr) _Translatorget)rsrrrrs)all _nulljoin)r rrrr_quotesrz\\[0-3][0-7][0-7]z[\\].cCsft|dkr|S|ddks|ddkr|S|dd}d}t|}g}d|kr.|krnt|St||}t||}|sQ|sQ|||d t|Sd}}|r\|d}|rc|d}|r|rk||kr|||||||d|d}n|||||tt||d|dd|d}d|kr|ks3t|St|S)Nrr8) len _OctalPattsearch _QuotePattappendstartrrr)mystrinreso_matchq_matchjkrrr_unquotes@      $r)MonTueWedThuFriSatSun) NJanFebMarAprMayJunJulAugSepOctNovDecc CsRddlm}m}|}|||\ }}}} } } } } }d|| ||||| | | fS)Nr)gmtimetimez#%s, %02d %3s %4d %02d:%02d:%02d GMT)rr)future weekdayname monthnamerrnowyearmonthdayhhmmsswdyzrrr_getdate3s rc @seZdZdZdddddddd d ZeddgZd d Zd dZddZ e fddZdddZ e Z e ddZdddZdddZdS)MorselaA class to hold ONE (key, value) pair. In a cookie, each such pair may have several attributes, so this class is used to keep the attributes associated with the appropriate key,value pair. This class also includes a coded_value attribute, which is used to hold the network representation of the value. This is most useful when Python objects are pickled for network transit. expiresPathCommentDomainzMax-AgesecurehttponlyVersion)rpathcommentdomainmax-agerrversioncCs0d|_|_|_|jD] }t||dq dS)Nr)keyvalue coded_value _reservedr __setitem__)selfrrrr__init__^s zMorsel.__init__cCs0|}||jvrtd|t|||dS)NzInvalid Attribute %s)lowerrr rr)rKVrrrrfs  zMorsel.__setitem__cCs||jvSr)rr)rrrrr isReservedKeylszMorsel.isReservedKeycsR||jvr td|tfdd|Drtd|||_||_||_dS)Nz!Attempt to set a reserved key: %sc3s|]}|vVqdSrrrrrrrtrzMorsel.set..zIllegal key value: %s)rrr anyrrr)rrval coded_valrrrrsetos   z Morsel.setN Set-Cookie:cCsd|||fS)Nz%s %s) OutputString)rattrsheaderrrroutput|sz Morsel.outputcCs>trt|jtrt|j}n|j}d|jjt|jt|fS)Nz <%s: %s=%s>) r isinstancerunicoder __class__rrreprrrrrr__repr__s  zMorsel.__repr__cCsd||ddS)Nz r8r9)rreplace)rrrrr js_outputszMorsel.js_outputcCsg}|j}|d|j|jf|dur|j}t|}|D]a\}}|dkr'q||vr,q|dkrCt|trC|d|j|t|fq|dkrXt|trX|d|j||fq|dkrf|t |j|q|dkrt|t |j|q|d|j||fqt |S)N%s=%srrr z%s=%drr) rrrrsorteditemsr"rrr _semispacejoin)rrresultrr,rrrrrrs*  zMorsel.OutputString)Nrr)rrr__doc__rr_flagsrrr _LegalCharsr!__str__r r'r)rrrrrr;s,      rz.[\w\d!#%&'~_`><@,:/\$\*\+\-\.\^\|\)\(\?\}\{\=]z~ (?x) # This is a verbose pattern (?P # Start of group 'key' a+? # Any word of at least one letter ) # End of group 'key' ( # Optional group: there may not be a value. \s*=\s* # Equal Sign (?P # Start of group 'val' "(?:[^\\"]|\\.)*" # Any doublequoted string | # or \w{3},\s[\w\d\s-]{9,11}\s[\d:]{8}\sGMT # Special case for "expires" attr | # or a,* # Any word or empty string ) # End of group 'val' )? # End of optional value group \s* # Any number of spaces. (\s+|;|$) # Ending either at space, semicolon, or EOS. c@steZdZdZddZddZdddZd d Zd d ZdddZ e Z e ddZ dddZ ddZefddZdS)r z'A container class for a set of Morsels.cCs||fS)a real_value, coded_value = value_decode(STRING) Called prior to setting a cookie's value from the network representation. The VALUE is the value read from HTTP header. Override this function to modify the behavior of cookies. rr&rrr value_decodeszBaseCookie.value_decodecCst|}||fS)zreal_value, coded_value = value_encode(VALUE) Called prior to setting a cookie's value from the dictionary representation. The VALUE is the value being assigned. Override this function to modify the behavior of cookies. )r rrstrvalrrr value_encodeszBaseCookie.value_encodeNcCs|r ||dSdSr)load)rinputrrrrszBaseCookie.__init__cCs.||t}||||t|||dS)z+Private method for setting a cookie's valueN)rrrrr)rr real_valuerMrrr__setszBaseCookie.__setcCs ||\}}||||dS)zDictionary style assignment.N)r6_BaseCookie__set)rrrrvalcvalrrrrszBaseCookie.__setitem__r cCs:g}t|}|D] \}}||||q ||S)z"Return a string suitable for HTTP.)r+r,rr!join)rrr sepr.r,rrrrrr!s    zBaseCookie.outputcCsng}t|}|D]"\}}trt|jtrt|j}n|j}|dt|t|fq d|j j t |fS)Nr*z<%s: %s>) r+r,r r"rr#r rr%r$r _spacejoin)rlr,rrrrrrr's   zBaseCookie.__repr__cCs6g}t|}|D] \}}|||q t|S)z(Return a string suitable for JavaScript.)r+r,rr)r)rrr.r,rrrrrr)s   zBaseCookie.js_outputcCs6t|tr ||dS|D]\}}|||<qdS)zLoad cookies from a string (presumably HTTP_COOKIE) or from a dictionary. Loading cookies from a dictionary 'd' is equivalent to calling: map(Cookie.__setitem__, d.keys(), d.values()) N)r"r _BaseCookie__parse_stringr,)rrawdatarrrrrr7s   zBaseCookie.loadc Cs d}t|}d}d|kr|krndS|||}|sdS|d|d}}|d}|ddkr@|r?|||dd<n6|tjvr`|r_|durY|tjvrXd||<nt|||<n|durv| |\} } | || | ||}d|kr|ksdSdSdS)Nrrr$rT) rrgroupendrrrr0rr3r<) rrpattrrr:matchrrr=r>rrr__parse_string&s4     zBaseCookie.__parse_stringr)Nrr?)rrrr/r3r6rr<rr!r2r r'r)r7_CookiePatternrDrrrrr s    r c@s eZdZdZddZddZdS)rz SimpleCookie supports strings as cookie values. When setting the value using the dictionary assignment notation, SimpleCookie calls the builtin str() to convert the value to a string. Values received from HTTP are kept as strings. cCs t||fSr)rr&rrrr3Qs zSimpleCookie.value_decodecCst|}|t|fSr)r rr4rrrr6Ts zSimpleCookie.value_encodeN)rrrr/r3r6rrrrrJs r))r/ __future__rrrrfuture.builtinsrrrr future.utilsr r reASCIIstring__all__r@rr-rB Exceptionr ascii_lettersdigitsr1rrcompilerrr _weekdayname _monthnamerr_LegalCharsPattrLr rrrrrs& [              !!!"""###$$$%%%&&&'''((()))***+++,,,---...///000111222333444555666777888999::: ;    A   2   t