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<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd<dd>> import Cookie Most of the time you start by creating a cookie. The __init__ routine can take several arguments, but that isn't covered here. >>> C = Cookie.Cookie() Now, you can add values to the Cookie just as is if it were a dictionary. >>> C["joe"] = "a cookie" >>> C Set-Cookie: joe="a cookie"; 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 by using the the .output() function >>> C.output("Cookie:") 'Cookie: joe="a cookie";' 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.load("mary=hadalittlelamb;") >>> C Set-Cookie: mary=hadalittlelamb; Set-Cookie: joe="a cookie"; Each element of the Cookie also supports all of the RFC 2109 Cookie attributes. Here's an example which sets the Path attribute. >>> C["joe"]["path"] = "/home/joe" >>> C Set-Cookie: mary=hadalittlelamb; Set-Cookie: joe="a cookie"; Path=/home/joe; Before I forget, the .load() method is pretty smart about identifying a cookie. Escaped quotation marks and nested semicolons do not confuse it. >>> C.load('lobotomy="joe=wolf; lobotomy=\"nested quote\"; mark=\012;";') >>> C Set-Cookie: mary=hadalittlelamb; Set-Cookie: joe="a cookie"; Path=/home/joe; Set-Cookie: lobotomy="joe=wolf; lobotomy="nested quote"; mark= ;"; Each dictionary element has a 'value' attribute, which gives you back the value associated with the key. >>> C["joe"].value 'a cookie' >>> C["lobotomy"].value 'joe=wolf; lobotomy="nested quote"; mark= ;' If you set a cookie to a non-string object, that object is automatically pickled (using cPickle or pickle) in the Set-Cookie: header. >>> C["int"] = 7 >>> C Set-Cookie: lobotomy="joe=wolf; lobotomy="nested quote"; mark= ;"; Set-Cookie: joe="a cookie"; Path=/home/joe; Set-Cookie: mary=hadalittlelamb; Set-Cookie: int="I7 ."; If the .load() method finds a pickled object in the string, then it automatically unpickles it. The 'value' attribute gives you back the true value, not the encoded representation. >>> C.load('anotherint="I45\012.";') >>> C["anotherint"].value 45 >>> C["int"].value 7 >>> C Set-Cookie: lobotomy="joe=wolf; lobotomy="nested quote"; mark= ;"; Set-Cookie: joe="a cookie"; Path=/home/joe; Set-Cookie: mary=hadalittlelamb; Set-Cookie: anotherint="I45 ."; Set-Cookie: int="I7 ."; Finally, the encoding/decoding behavior is controllable by two attributes of the Cookie: net_setfunc() Takes in an encoded string and returns a value user_setfunc() Takes in a value and returns the encoded string By default, these functions are defined in the Cookie module, but you should feel free to override them. >>> C.net_setfunc >>> C.user_setfunc Finis. s0Cookie.py requires 're' from Python 1.5 or laters CookieErrorcsRS(N((s ./Cookie.pys CookieErrorss!#$%&'*+-.^_`|~s\000ss\001ss\002ss\003ss\004ss\005ss\006ss\007ss\010ss\011s s\012s s\013s s\014s s\015s s\016ss\017ss\020ss\021ss\022ss\023ss\024ss\025ss\026ss\027ss\030ss\031ss\032ss\033ss\034ss\035ss\036ss\037ss s!s\"s"s#s$s%s&s's(s)s*s+s,s-s.s/s0s1s2s3s4s5s6s7s8s9s:s;ss?s@sAsBsCsDsEsFsGsHsIsJsKsLsMsNsOsPsQsRsSsTsUsVsWsXsYsZs[s\\s\s]s^s_s\074s=s`sasbscsdsesfsgshsisjskslsmsnsospsqsrssstsusvswsxsyszs{s|s}s~s\177ss\200ss\201ss\202ss\203ss\204ss\205ss\206ss\207ss\210ss\211ss\212ss\213ss\214ss\215ss\216ss\217ss\220ss\221ss\222ss\223ss\224ss\225ss\226ss\227ss\230ss\231ss\232ss\233ss\234ss\235ss\236ss\237ss\240ss\241ss\242ss\243ss\244ss\245ss\246ss\247ss\250ss\251ss\252ss\253ss\254ss\255ss\256ss\257ss\260ss\261ss\262ss\263ss\264ss\265ss\266ss\267ss\270ss\271ss\272ss\273ss\274ss\275ss\276ss\277ss\300ss\301ss\302ss\303ss\304ss\305ss\306ss\307ss\310ss\311ss\312ss\313ss\314ss\315ss\316ss\317ss\320ss\321ss\322ss\323ss\324ss\325ss\326ss\327ss\330ss\331ss\332ss\333ss\334ss\335ss\336ss\337ss\340ss\341ss\342ss\343ss\344ss\345ss\346ss\347ss\350ss\351ss\352ss\353ss\354ss\355ss\356ss\357ss\360ss\361ss\362ss\363ss\364ss\365ss\366ss\367ss\370ss\371ss\372ss\373ss\374ss\375ss\376ss\377scs||SdS(N(stablesc(scstables ./Cookie.pys _translatescs`x2tdr}||joPnqW|Sd|tt|ddSdS(Nis"s(s _SpecialCharssCsstrsjoinsmaps _translate(sstrsjoinsCs ./Cookie.pys_quotes   s\\[0-3][0-7][0-7]s[\\].cs%  t|djo |Sn|ddjp|d djo |Sn|dd !}d}t|}g}xd|jo |jno_ ti||}!ti||}"| o| o#|i ||$Pn&d }}'|o'|i d}n(|o(|i d}n)|o| p ||jo@*|i |||!+|i ||d,|d}nV.|i |||!/|i tti||d|d!d0|d}qW1ti|dSdS(Niis"iiis(slensstrsisnsress _OctalPattssearchsOmatchs _QuotePattsQmatchsappendsjsksstartschrsstringsatoisjoin(sstrsisnsressOmatchsQmatchsjsks ./Cookie.pys_unquote s8 &   !  1csG=>t|tdjo?t|SnAt||SdS(Ns(stypesvals_quotesdumps(svalsdumpss ./Cookie.pys _babelize=scsfDEt|}F| p|d djo F|SnGyH||SWnIJ|SnXdS(Nis.(s_unquotesvalsstrsloads(svalsloadssstrs ./Cookie.pys _debabelizeDs sMonsTuesWedsThusFrisSatsSunsJansFebsMarsAprsMaysJunsJulsAugsSepsOctsNovsDecc sv[\kll]|}^|||\ }}}} } } } } }_d|| ||||| | | fSdS(Ns#%s, %02d-%3s-%4d %02d:%02d:%02d GMT(stimesgmtimesnowsfuturesyearsmonthsdayshhsmmsssswdsyszs weekdaynames monthname(sfutures weekdaynames monthnamesgmtimestimesnowsyearsmonthsdayshhsmmsssswdsyszs ./Cookie.pys_getdate[s  .is0[\w\d\n\r!#%'~_`><@,:/\$\*\+\-\.\^\|\)\(\?\}\{]+s5[\, \w\d\n\r!#%'~_`><@,:/\$\*\+\-\.\^\|\)\(\?\}\{=&]+s (?x)(?Ps#)(\s*=\s*(?P"(?:[^\\"]|\\.)*"|s)\s*)?;?sMorselcshdd<dd<dd<dd<dd <d d <d d (sselfs OutputString(sselfs ./Cookie.pys js_outputsc sFg}|i}|d|i|ifx|idr\}}| o qGn|djot |t djo(|d|i |t |fn|djot |t djo"|d|i ||fnK|djo|d|i |n|d|i ||fqGW|i o|i oti|d oxt|d dr} |d |i  |d|i|if xL|id r9\}} | o  qn |djot |t djo(|d|i |t |fn|djot |t djo"|d|i ||fn}|djo|d|i |nQ|d jo"|d|i ||fn|d|i ||fqWqWnnti|d SdS( Ns%s=%s;isexpiresismax-ages%s=%d;ssecures%s;sdomains %ss (sresultsappendsRAsselfskeys coded_valuesitemssKsVstypes_Morsel__reserveds_getdates_clears_headerscookieClearMapshas_keysdomainsstringsjoin(sselfsresultsRAsKsVsdomains ./Cookie.pys OutputStringsD   )()""  )()"".c sh}#td|%d}&t|}'d})x)d|jo |jno,|i||}-| o-Pn/|i d|i df\}} 0|i d}2ti| } 4| tjo5d||