a 97aMTã¦@sždZddlmZddlmZddlmZddlmZddlmZmZm Z m Z ddl m Z m Z ddlZe rnde_ddlZgd ¢Zd jZd jZd jZGd d„deƒZejejdZddddddddddddddddd d!d"d#d$d%d&d'd(d)d*d+d,d-d.d/d0d1d2d3d4d5d6d7d8d9d:d;dd?d@dAdBdCdDdEdFdGdHdIdJdKdLdMdNdOdPdQdRdSdTdUdVdWdXdYdZd[d\d]d^d_d`dadbdcdddedfdgdhdidjdkdldmdndodpdqdrdsdtdudvdwdxdydzd{d|d}d~dd€d�d‚dƒd„d…d†d‡dˆd‰dŠd‹dŒd�dŽd�d�d‘d’d“d”d•d–d—d˜d™dšd›dœd�dždŸd d¡d¢d£d¤d¥d¦d§d¨d©dªd«d¬d­d®d¯d°d±d²d³d´dµœ¥Zefd¶d·„Ze d¸¡Ze d¹¡Zdºd»„Z gd¼¢Z!gd½¢Z"de!e"fd¾d¿„Z#GdÀdÁ„dÁeƒZ$dÂZ%e dÃe%dÄe%dÅej¡Z&GdÆdÇ„dÇeƒZ'GdÈdÉ„dÉe'ƒZ(dS)Êaf 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)ÚchrÚdictÚintÚstr)ÚPY2Ú as_native_strN)Ú CookieErrorÚ BaseCookieÚ SimpleCookieÚz; ú c@s eZdZdS)r N)Ú__name__Ú __module__Ú __qualname__©rrúx/private/var/folders/s6/9n5zrl012gv99k63s4q6ccsd4s6mqz/T/pip-target-f5cq3f2q/lib/python/future/backports/http/cookies.pyr šsr z!#$%&'*+-.^_`|~:z\000z\001z\002z\003z\004z\005z\006z\007z\010z\011z\012z\013z\014z\015z\016z\017z\020z\021z\022z\023z\024z\025z\026z\027z\030z\031z\032z\033z\034z\035z\036z\037z\054z\073ú\"z\\z\177z\200z\201z\202z\203z\204z\205z\206z\207z\210z\211z\212z\213z\214z\215z\216z\217z\220z\221z\222z\223z\224z\225z\226z\227z\230z\231z\232z\233z\234z\235z\236z\237z\240z\241z\242z\243z\244z\245z\246z\247z\250z\251z\252z\253z\254z\255z\256z\257z\260z\261z\262z\263z\264z\265z\266z\267z\270z\271z\272z\273z\274z\275z\276z\277z\300z\301z\302z\303z\304z\305z\306z\307z\310z\311z\312z\313z\314z\315z\316z\317z\320z\321z\322z\323z\324z\325z\326z\327z\330z\331z\332z\333z\334z\335z\336z\337z\340z\341z\342z\343z\344z\345z\346z\347z\350z\351z\352z\353z\354z\355z\356z\357z\360z\361z\362z\363z\364z\365z\366z\367z\370z\371z\372z\373z\374z\375z\376z\377)¥úúúúúúúúúú Ú ú ú ú úúúúúúúúúúúúúúúúúúú,ú;ú"ú\úõ€õÂ�õ‚õƒõ„õÂ…õ†õ‡õˆõ‰õŠõ‹õÂŒõÂ�õÂŽõÂ�õÂ�õ‘õÂ’õ“õ”õ•õ–õ—õ˜õ™õšõ›õœõÂ�õžõŸõ õ¡õ¢õ£õ¤õÂ¥õ¦õ§õ¨õ©õªõ«õ¬õ­õ®õ¯õ°õ±õ²õ³õ´õµõ¶õ·õ¸õ¹õºõ»õ¼õ½õ¾õ¿õÀõÃ�õÂõÃõÄõÃ…õÆõÇõÈõÉõÊõËõÃŒõÃ�õÃŽõÃ�õÃ�õÑõÃ’õÓõÔõÕõÖõ×õØõÙõÚõÛõÜõÃ�õÞõßõàõáõâõãõäõÃ¥õæõçõèõéõêõëõìõíõîõïõðõñõòõóõôõõõöõ÷õøõùõúõûõüõýõþõÿcs8t‡fdd„|Dƒƒr|Sdtdd„|DƒƒdSdS)zãQuote 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|]}|ˆvVqdS©Nr©Ú.0Úc©Ú LegalCharsrrÚ òóz_quote..r9css|]}t ||¡VqdSr¼)Ú _TranslatorÚget)r¾ÚsrrrrÂõrÃN)ÚallÚ _nulljoin)r rÁrrÀrÚ_quoteësrÉz\\[0-3][0-7][0-7]z[\\].cCsBt|ƒdkr|S|ddks(|ddkr,|S|dd…}d}t|ƒ}g}d|kr^|k�r:nnØt ||¡}t ||¡}|s˜|s˜| ||d…¡�q:d}}|r®| d¡}|r¼| d¡}|rú|rÌ||krú| |||…¡| ||d¡|d}qH| |||…¡| tt||d|d…dƒƒ¡|d}qHt|ƒS)Nérr9éÿÿÿÿééé) ÚlenÚ _OctalPattÚsearchÚ _QuotePattÚappendÚstartrrrÈ)ÚmystrÚiÚnÚresÚo_matchÚq_matchÚjÚkrrrÚ_unquoteûs6       $ rÝ)ÚMonÚTueÚWedÚThuÚFriÚSatÚSun) NÚJanÚFebÚMarÚAprÚMayÚJunÚJulÚAugÚSepÚOctÚNovÚDecc CsRddlm}m}|ƒ}|||ƒ\ }}}} } } } } }d|| ||||| | | fS)Nr)ÚgmtimeÚtimez#%s, %02d %3s %4d %02d:%02d:%02d GMT)ròrñ)ÚfutureÚ weekdaynameÚ monthnamerñròÚnowÚyearÚmonthÚdayÚhhÚmmÚssÚwdÚyÚzrrrÚ_getdate3s ÿrc @s†eZdZdZdddddddd d œZeddgƒZd d „Zd d„Zdd„Z e fdd„Zddd„Z e Z e ƒdd„ƒZddd„Zddd„ZdS) ÚMorsela‘A 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. ÚexpiresÚPathÚCommentÚDomainzMax-AgeÚsecureÚhttponlyÚVersion)rÚpathÚcommentÚdomainúmax-agerrÚversioncCs0d|_|_|_|jD]}t ||d¡qdS)Nr)ÚkeyÚvalueÚ coded_valueÚ _reservedrÚ __setitem__)ÚselfrrrrÚ__init__^s zMorsel.__init__cCs0| ¡}||jvrtd|ƒ‚t |||¡dS)NzInvalid Attribute %s)Úlowerrr rr)rÚKÚVrrrrfs  zMorsel.__setitem__cCs| ¡|jvSr¼)rr)rrrrrÚ isReservedKeylszMorsel.isReservedKeycsR| ¡|jvrtd|ƒ‚t‡fdd„|Dƒƒr.zIllegal key value: %s)rrr Úanyrrr)rrÚvalÚ coded_valrÁrrÀrÚsetos  z Morsel.setNú Set-Cookie:cCsd|| |¡fS)Nz%s %s)Ú OutputString)rÚattrsÚheaderrrrÚoutput|sz Morsel.outputcCs>trt|jtƒrt|jƒ}n|j}d|jjt|jƒt|ƒfS)Nz <%s: %s=%s>) r Ú isinstancerÚunicoder Ú __class__rrÚrepr©rrrrrÚ__repr__�s  ÿzMorsel.__repr__cCsd| |¡ dd¡S)Nz— r9r)rÚreplace)rrrrrÚ js_outputŠsúzMorsel.js_outputcCsg}|j}|d|j|jfƒ|dur,|j}t| ¡ƒ}|D]Â\}}|dkrNq<||vrXq<|dkr†t|tƒr†|d|j|t|ƒfƒq<|dkr°t|tƒr°|d|j||fƒq<|dkrÌ|t |j|ƒƒq<|dkrè|t |j|ƒƒq<|d|j||fƒq<@,:/\$\*\+\-\.\^\|\)\(\?\}\{\=]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@steZdZdZdd„Zdd„Zddd„Zd d „Zd d „Zddd„Z e Z e ƒdd„ƒZ ddd„Z dd„Zefdd„ZdS)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_decodeÙszBaseCookie.value_decodecCst|ƒ}||fS)zýreal_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 ©rrÚstrvalrrrÚ value_encodeâszBaseCookie.value_encodeNcCs|r| |¡dSr¼)Úload)rÚinputrrrrëszBaseCookie.__init__cCs.| |tƒ¡}| |||¡t |||¡dS)z+Private method for setting a cookie's valueN)rÅrrrr)rrÚ real_valuerÚMrrrÚ__setïszBaseCookie.__setcCs | |¡\}}| |||¡dS)zDictionary style assignment.N)r6Ú_BaseCookie__set)rrrÚrvalÚcvalrrrrõszBaseCookie.__setitem__rú cCs:g}t| ¡ƒ}|D]\}}| | ||¡¡q| |¡S)z"Return a string suitable for HTTP.)r+r,rÓr!Újoin)rrr Úsepr.r,rrrrrr!ús   zBaseCookie.outputcCsng}t| ¡ƒ}|D]D\}}tr8t|jtƒr8t|jƒ}n|j}| dt|ƒt|ƒf¡qd|j j t |ƒfS)Nr*z<%s: %s>) r+r,r r"rr#r rÓr%r$rÚ _spacejoin)rÚlr,rrrrrrr's   zBaseCookie.__repr__cCs6g}t| ¡ƒ}|D]\}}| | |¡¡qt|ƒS)z(Return a string suitable for JavaScript.)r+r,rÓr)rÈ)rrr.r,rrrrrr)s   zBaseCookie.js_outputcCs4t|tƒr| |¡n| ¡D]\}}|||<qdS)zÝLoad 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,)rÚrawdatarrrrrr7s    zBaseCookie.loadc Csîd}t|ƒ}d}d|kr$|krênnÂ| ||¡}|s:qê| d¡| d¡}}| d¡}|ddkr||rè|||dd…<q| ¡tjvr¼|rè|dur®| ¡tjvrºd||<qèt|ƒ||<q|dur|  |¡\} } |  || | ¡||}qdS)Nrrrú$rÌT) rÏrÑÚgroupÚendrrrr0rÝr3r<) rrÕÚpattrÖr×r:Úmatchrrr=r>rrrÚ__parse_string&s,    zBaseCookie.__parse_string)N)Nrr?)N)rrrr/r3r6rr<rr!r2r r'r)r7Ú_CookiePatternrDrrrrr Ös    r c@s eZdZdZdd„Zdd„ZdS)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¼)rÝr&rrrr3QszSimpleCookie.value_decodecCst|ƒ}|t|ƒfSr¼)r rÉr4rrrr6TszSimpleCookie.value_encodeN)rrrr/r3r6rrrrrJsr))r/Ú __future__rrrrZfuture.builtinsrrrr Z future.utilsr r ÚreÚASCIIÚstringÚ__all__r@rÈr-rBÚ Exceptionr Ú ascii_lettersÚdigitsr1rÄrÉÚcompilerÐrÒrÝÚ _weekdaynameÚ _monthnamerrZ_LegalCharsPattrLr rrrrrÚ'sÀ[    ÂA  2ýý ô ôït