fQc @s dZddlZddlZdddgZdjZdjZdjZGd 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 ZdeedndoZGdpdqdqeZdrZedsZejdteduedvejZGdwddeZGdxddeZdS(yu. 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. iNu CookieErroru BaseCookieu SimpleCookieuu; u cBs|EeZdZdS(u CookieErrorN(u__name__u __module__u __qualname__(u __locals__((u1/opt/alt/python33/lib64/python3.3/http/cookies.pyu CookieErrorsu!#$%&'*+-.^_`|~:u\000uu\001uu\002uu\003uu\004uu\005uu\006uu\007uu\010uu\011u u\012u u\013u u\014u u\015u u\016uu\017uu\020uu\021uu\022uu\023uu\024uu\025uu\026uu\027uu\030uu\031uu\032uu\033uu\034uu\035uu\036uu\037uu\054u,u\073u;u\"u"u\\u\u\177uu\200u€u\201uu\202u‚u\203uƒu\204u„u\205u…u\206u†u\207u‡u\210uˆu\211u‰u\212uŠu\213u‹u\214uŒu\215uu\216uŽu\217uu\220uu\221u‘u\222u’u\223u“u\224u”u\225u•u\226u–u\227u—u\230u˜u\231u™u\232ušu\233u›u\234uœu\235uu\236užu\237uŸu\240u u\241u¡u\242u¢u\243u£u\244u¤u\245u¥u\246u¦u\247u§u\250u¨u\251u©u\252uªu\253u«u\254u¬u\255u­u\256u®u\257u¯u\260u°u\261u±u\262u²u\263u³u\264u´u\265uµu\266u¶u\267u·u\270u¸u\271u¹u\272uºu\273u»u\274u¼u\275u½u\276u¾u\277u¿u\300uÀu\301uÁu\302uÂu\303uÃu\304uÄu\305uÅu\306uÆu\307uÇu\310uÈu\311uÉu\312uÊu\313uËu\314uÌu\315uÍu\316uÎu\317uÏu\320uÐu\321uÑu\322uÒu\323uÓu\324uÔu\325uÕu\326uÖu\327u×u\330uØu\331uÙu\332uÚu\333uÛu\334uÜu\335uÝu\336uÞu\337ußu\340uàu\341uáu\342uâu\343uãu\344uäu\345uåu\346uæu\347uçu\350uèu\351uéu\352uêu\353uëu\354uìu\355uíu\356uîu\357uïu\360uðu\361uñu\362uòu\363uóu\364uôu\365uõu\366uöu\367u÷u\370uøu\371uùu\372uúu\373uûu\374uüu\375uýu\376uþu\377uÿcsFtfdd|Dr#|Sdtdd|DdSdS(uQuote 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(N((u.0uc(u LegalChars(u1/opt/alt/python33/lib64/python3.3/http/cookies.pyu su_quote..u"css!|]}tj||VqdS(N(u _Translatoruget(u.0us((u1/opt/alt/python33/lib64/python3.3/http/cookies.pyu sN(uallu _nulljoin(ustru LegalChars((u LegalCharsu1/opt/alt/python33/lib64/python3.3/http/cookies.pyu_quotesu_quoteu\\[0-3][0-7][0-7]u[\\].c Cst|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( Niiu"iiiiii( ulenu _OctalPattusearchu _QuotePattuappendustartuchruintu _nulljoin(ustruiunuresuo_matchuq_matchujuk((u1/opt/alt/python33/lib64/python3.3/http/cookies.pyu_unquotes6    .u_unquoteuMonuTueuWeduThuuFriuSatuSunuJanuFebuMaruApruMayuJunuJuluAuguSepuOctuNovuDecc Csoddlm}m}|}|||\ }}}} } } } } }d|| ||||| | | fS(Ni(ugmtimeutimeu#%s, %02d %3s %4d %02d:%02d:%02d GMT(utimeugmtime(ufutureu weekdaynameu monthnameugmtimeutimeunowuyearumonthudayuhhummussuwduyuz((u1/opt/alt/python33/lib64/python3.3/http/cookies.pyu_getdate)s  +u_getdatecBs|EeZdZdZidd6dd6dd6dd6d d 6d d 6d d 6d d6Zd d hZddZddZddZe ddZ d dddZ e Z ddZd ddZd ddZd S(!uMorseluA 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. uexpiresuPathupathuCommentucommentuDomainudomainuMax-Ageumax-ageusecureuhttponlyuVersionuversioncCsBd|_|_|_x$|jD]}tj||dq!WdS(Nu(uNoneukeyuvalueu coded_valueu _reservedudictu __setitem__(uselfukey((u1/opt/alt/python33/lib64/python3.3/http/cookies.pyu__init__TsuMorsel.__init__cCsE|j}||jkr.td|ntj|||dS(NuInvalid Attribute %s(uloweru _reservedu CookieErrorudictu __setitem__(uselfuKuV((u1/opt/alt/python33/lib64/python3.3/http/cookies.pyu __setitem__\s uMorsel.__setitem__cCs|j|jkS(N(uloweru _reserved(uselfuK((u1/opt/alt/python33/lib64/python3.3/http/cookies.pyu isReservedKeybsuMorsel.isReservedKeycsy|j|jkr(td|ntfdd|DrZtd|n||_||_||_dS(Nu!Attempt to set a reserved key: %sc3s|]}|kVqdS(N((u.0uc(u LegalChars(u1/opt/alt/python33/lib64/python3.3/http/cookies.pyu jsuMorsel.set..uIllegal key value: %s(uloweru _reservedu CookieErroruanyukeyuvalueu coded_value(uselfukeyuvalu coded_valu LegalChars((u LegalCharsu1/opt/alt/python33/lib64/python3.3/http/cookies.pyusetes  u Morsel.setu Set-Cookie:cCsd||j|fS(Nu%s %s(u OutputString(uselfuattrsuheader((u1/opt/alt/python33/lib64/python3.3/http/cookies.pyuoutputrsu Morsel.outputcCs#d|jj|jt|jfS(Nu <%s: %s=%s>(u __class__u__name__ukeyurepruvalue(uself((u1/opt/alt/python33/lib64/python3.3/http/cookies.pyu__repr__ws uMorsel.__repr__cCsd|j|jddS(Nu u"u\"(u OutputStringureplace(uselfuattrs((u1/opt/alt/python33/lib64/python3.3/http/cookies.pyu js_output{suMorsel.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(Nu%s=%suuexpiresumax-ageu%s=%dusecureuhttponly( uappendukeyu coded_valueuNoneu _reservedusorteduitemsu isinstanceuintu_getdateustru_semispacejoin(uselfuattrsuresultuappenduitemsukeyuvalue((u1/opt/alt/python33/lib64/python3.3/http/cookies.pyu OutputStrings*     $  uMorsel.OutputStringN(u__name__u __module__u __qualname__u__doc__u _reservedu_flagsu__init__u __setitem__u isReservedKeyu _LegalCharsusetuNoneuoutputu__str__u__repr__u js_outputu OutputString(u __locals__((u1/opt/alt/python33/lib64/python3.3/http/cookies.pyuMorsel1s(        uMorselu,\w\d!#%&'~_`><@,:/\$\*\+\-\.\^\|\)\(\?\}\{\=u\[\]u (?x) # This is a verbose pattern \s* # Optional whitespace at start of cookie (?P # Start of group 'key' [u ]+? # 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 [u-]* # 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. cBs|EeZdZdZddZddZdddZdd Zd d Z dd d ddZ e Z ddZ dddZ ddZeddZdS(u BaseCookieu'A container class for a set of Morsels.cCs ||fS(u 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. ((uselfuval((u1/opt/alt/python33/lib64/python3.3/http/cookies.pyu value_decodesuBaseCookie.value_decodecCst|}||fS(ureal_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. (ustr(uselfuvalustrval((u1/opt/alt/python33/lib64/python3.3/http/cookies.pyu value_encodes uBaseCookie.value_encodecCs|r|j|ndS(N(uload(uselfuinput((u1/opt/alt/python33/lib64/python3.3/http/cookies.pyu__init__suBaseCookie.__init__cCs?|j|t}|j|||tj|||dS(u+Private method for setting a cookie's valueN(ugetuMorselusetudictu __setitem__(uselfukeyu real_valueu coded_valueuM((u1/opt/alt/python33/lib64/python3.3/http/cookies.pyu__setsuBaseCookie.__setcCs,|j|\}}|j|||dS(uDictionary style assignment.N(u value_encodeu_BaseCookie__set(uselfukeyuvalueurvalucval((u1/opt/alt/python33/lib64/python3.3/http/cookies.pyu __setitem__suBaseCookie.__setitem__u Set-Cookie:u cCsUg}t|j}x-|D]%\}}|j|j||qW|j|S(u"Return a string suitable for HTTP.(usorteduitemsuappenduoutputujoin(uselfuattrsuheaderusepuresultuitemsukeyuvalue((u1/opt/alt/python33/lib64/python3.3/http/cookies.pyuoutputs uBaseCookie.outputcCsig}t|j}x4|D],\}}|jd|t|jfqWd|jjt|fS(Nu%s=%su<%s: %s>(usorteduitemsuappendurepruvalueu __class__u__name__u _spacejoin(uselfuluitemsukeyuvalue((u1/opt/alt/python33/lib64/python3.3/http/cookies.pyu__repr__s $uBaseCookie.__repr__cCsOg}t|j}x*|D]"\}}|j|j|qWt|S(u(Return a string suitable for JavaScript.(usorteduitemsuappendu js_outputu _nulljoin(uselfuattrsuresultuitemsukeyuvalue((u1/opt/alt/python33/lib64/python3.3/http/cookies.pyu js_outputs uBaseCookie.js_outputcCsJt|tr|j|n'x$|jD]\}}|||suSimpleCookie.value_decodecCst|}|t|fS(N(ustru_quote(uselfuvalustrval((u1/opt/alt/python33/lib64/python3.3/http/cookies.pyu value_encodeAs uSimpleCookie.value_encodeN(u__name__u __module__u __qualname__u__doc__u value_decodeu value_encode(u __locals__((u1/opt/alt/python33/lib64/python3.3/http/cookies.pyu SimpleCookie7s (u__doc__ureustringu__all__ujoinu _nulljoinu_semispacejoinu _spacejoinu Exceptionu CookieErroru ascii_lettersudigitsu _LegalCharsu _Translatoru_quoteucompileu _OctalPattu _QuotePattu_unquoteu _weekdaynameuNoneu _monthnameu_getdateudictuMorselu_LegalKeyCharsu_LegalValueCharsuASCIIu_CookiePatternu BaseCookieu SimpleCookie(((u1/opt/alt/python33/lib64/python3.3/http/cookies.pyus       2~  n