[0R @sdZddlZddlZdddgZdjZdjZdjZGd ddeZ ej ej d Z id d 6d d6dd6dd6dd6dd6dd6dd6dd6dd6dd 6d!d"6d#d$6d%d&6d'd(6d)d*6d+d,6d-d.6d/d06d1d26d3d46d5d66d7d86d9d:6d;d<6d=d>6d?d@6dAdB6dCdD6dEdF6dGdH6dIdJ6dKdL6dMdN6dOdP6dQdR6dSdT6dUdV6dWdX6dYdZ6d[d\6d]d^6d_d`6dadb6dcdd6dedf6dgdh6didj6dkdl6dmdn6dodp6dqdr6dsdt6dudv6dwdx6dydz6d{d|6d}d~6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6d d 6d d 6d d6dd6dd6dd6dd6dd6dd6dd6dd6dd 6d!d"6d#d$6d%d&6d'd(6d)d*6d+d,6d-d.6d/d06d1d26d3d46d5d66d7d86d9d:6d;d<6d=d>6d?d@6dAdB6dCdD6dEdF6dGdH6dIdJ6dKdL6dMdN6dOdP6dQdR6dSdT6Z e dUdVZejdWZejdXZdYdZZd[d\d]d^d_d`dagZddbdcdddedfdgdhdidjdkdldmg ZdeedndoZGdpdqdqeZdrZejdsedteduejZGdvddeZGdwddeZdS(xa. 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. N CookieError BaseCookie SimpleCookiez;  c@seZdZdS)rN)__name__ __module__ __qualname__r r "/usr/lib/python3.4/http/cookies.pyrs z!#$%&'*+-.^_`|~:z\000z\001z\002z\003z\004z\005z\006z\007z\010z\011 z\012 z\013 z\014 z\015 z\016z\017z\020z\021z\022z\023z\024z\025z\026z\027z\030z\031z\032z\033z\034z\035z\036z\037z\054,z\073;z\""z\\\z\177z\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\363óz\364ôz\365õz\366öz\367÷z\370øz\371ùz\372úz\373ûz\374üz\375ýz\376þz\377ÿcsFtfdd|Dr#|Sdtdd|DdSdS)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|]}|kVqdS)Nr ).0c) LegalCharsr r sz_quote..r.css!|]}tj||VqdS)N) _Translatorget)rsr r r rsN)all _nulljoin)strrr )rr _quotesrz\\[0-3][0-7][0-7]z[\\].cCst|dkr|S|ddks6|ddkr:|S|dd}d}t|}g}xHd|ko||knrtj||}tj||}| r| r|j||dPnd }}|r|jd}n|r|jd}n|rZ| s!||krZ|j||||j||d|d}qe|j||||jtt||d|dd|d}qeWt|S) Nrr.rr) len _OctalPattsearch _QuotePattappendstartchrintr)rinZresZo_matchZq_matchjkr r r _unquotes6    .rZMonZTueZWedZThuZFriZSatZSunZJanZFebZMarZAprZMayZJunZJulZAugZSepZOctZNovZDecc Csoddlm}m}|}|||\ }}}} } } } } }d|| ||||| | | fS)Nr)gmtimetimez#%s, %02d %3s %4d %02d:%02d:%02d GMT)rr)ZfutureZ weekdaynameZ monthnamerrZnowZyearZmonthZdayZhhZmmZssZwdyzr r r _getdate)s  +rc@seZdZdZidd6dd6dd6dd6d d 6d d 6d d6dd6Zd dhZddZddZddZe ddZ ddddZ e Z ddZ ddd Zdd!d"ZdS)#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. expiresZPathpathCommentZcommentZDomainZdomainzMax-Agezmax-ageZSecuresecureZHttpOnlyhttponlyZVersionversioncCsBd|_|_|_x$|jD]}tj||dq!WdS)Nr)keyvalue coded_value _reserveddict __setitem__)selfrr r r __init__TszMorsel.__init__cCsE|j}||jkr.td|ntj|||dS)NzInvalid Attribute %s)lowerrrrr)rKVr r r r\s zMorsel.__setitem__cCs|j|jkS)N)rr)rrr r r isReservedKeybszMorsel.isReservedKeycsy|j|jkr(td|ntfdd|DrZtd|n||_||_||_dS)Nz!Attempt to set a reserved key: %sc3s|]}|kVqdS)Nr )rr)rr r rjszMorsel.set..zIllegal key value: %s)rrranyrrr)rrvalZ coded_valrr )rr setes  z Morsel.setNz Set-Cookie:cCsd||j|fS)Nz%s %s) OutputString)rattrsheaderr r r outputrsz Morsel.outputcCs#d|jj|jt|jfS)Nz <%s: %s=%s>) __class__rrreprr)rr r r __repr__ws zMorsel.__repr__cCsd|j|jddS)Nz r.z\")rreplace)rrr r r js_output{szMorsel.js_outputcCswg}|j}|d|j|jf|dkrA|j}nt|j}x|D]\}}|dkrxqZn||krqZn|dkrt|tr|d|j|t|fqZ|dkrt|tr|d|j||fqZ|dkr(|t |j|qZ|dkrN|t |j|qZ|d|j||fqZWt |S)Nz%s=%srrzmax-agez%s=%drr) rrrrsorteditems isinstancerrr_semispacejoin)rrresultrrrrr r r rs*     $  zMorsel.OutputString)rrr __doc__r_flagsrrr _LegalCharsrr__str__rrrr r r r r1s(         rz.[\w\d!#%&'~_`><@,:/\$\*\+\-\.\^\|\)\(\?\}\{\=]z (?x) # This is a verbose pattern \s* # Optional whitespace at start of cookie (?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@seZdZdZddZddZdddZd d Zd d Zdd dddZ e Z ddZ dddZ ddZ eddZdS)rz'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. r )rrr r r 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)rrstrvalr r r value_encodes zBaseCookie.value_encodeNcCs|r|j|ndS)N)load)rinputr r r rszBaseCookie.__init__cCs?|j|t}|j|||tj|||dS)z+Private method for setting a cookie's valueN)rrrrr)rrZ real_valuerMr r r Z__setszBaseCookie.__setcCsQt|tr%tj|||n(|j|\}}|j|||dS)zDictionary style assignment.N)rrrrr_BaseCookie__set)rrrrvalcvalr r r rszBaseCookie.__setitem__z Set-Cookie:z cCsUg}t|j}x-|D]%\}}|j|j||qW|j|S)z"Return a string suitable for HTTP.)rrrrjoin)rrrseprrrrr r r rs zBaseCookie.outputcCsig}t|j}x4|D],\}}|jd|t|jfqWd|jjt|fS)Nz%s=%sz<%s: %s>)rrrrrrr _spacejoin)rlrrrr r r rs $zBaseCookie.__repr__cCsOg}t|j}x*|D]"\}}|j|j|qWt|S)z(Return a string suitable for JavaScript.)rrrrr)rrrrrrr r r rs zBaseCookie.js_outputcCsJt|tr|j|n'x$|jD]\}}|||s       2~ r