[Python-Dev] Cookie.py and `:' in the key (original) (raw)

Barry A. Warsaw barry@zope.com
Tue, 2 Oct 2001 21:39:04 -0400


In Mailman, I use a version of Cookie.py written by Timothy dated from 1998. I'm now trying to see if I can get rid of my independent copy and just use Cookie.py in the Python 2.x standard library.

I've hit a snag; in Mailman's copy, it is legal to have a `:' in the key name, but in Python's Cookie.py it isn't:

-------------------- snip snip -------------------- % python Python 2.1.1 (#1, Aug 31 2001, 17:07:00) [GCC egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)] on linux2 Type "copyright", "credits" or "license" for more information.

import Cookie c = Cookie.Cookie() c['foo:bar'] = 'hello' Traceback (most recent call last): File "", line 1, in ? File "/usr/local/lib/python2.1/Cookie.py", line 583, in setitem self.__set(key, rval, cval) File "/usr/local/lib/python2.1/Cookie.py", line 576, in __set M.set(key, real_value, coded_value) File "/usr/local/lib/python2.1/Cookie.py", line 456, in set raise CookieError("Illegal key value: %s" % key) Cookie.CookieError: Illegal key value: foo:bar % PYTHONPATH=/path/to/mailman/misc python Python 2.1.1 (#1, Aug 31 2001, 17:07:00) [GCC egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)] on linux2 Type "copyright", "credits" or "license" for more information. import Cookie c = Cookie.Cookie() c['foo:bar'] = 'hello' print c Set-Cookie: foo:bar=hello; -------------------- snip snip --------------------

I don't see any reason why `:' shouldn't be allowed in Set-Cookie: value, but maybe I'm missing something in the RFCs. This patch fixes the problem but perhaps not in the right way. Comments?

-Barry

-------------------- snip snip -------------------- Index: Cookie.py

RCS file: /cvsroot/python/python/dist/src/Lib/Cookie.py,v retrieving revision 1.11 diff -u -r1.11 Cookie.py --- Cookie.py 2001/08/02 07:15:29 1.11 +++ Cookie.py 2001/10/03 01:38:39 @@ -249,7 +249,7 @@

_LegalChars is the list of chars which don't require "'s

_Translator hash-table for fast quoting

-LegalChars = string.ascii_letters + string.digits + "!#$%&'*+-.^|~" +_LegalChars = string.ascii_letters + string.digits + "!#$%&'*+-.^_|~:" _Translator = { '\000' : '\000', '\001' : '\001', '\002' : '\002', '\003' : '\003', '\004' : '\004', '\005' : '\005',