From 3f0f43d1c19eb0849f8bbd2e749e57d0b5019ec5 Mon Sep 17 00:00:00 2001 From: bwarsaw Date: Sat, 18 Aug 2001 18:22:11 +0000 Subject: Morsel.set(): Add optional argument `strict', defaulting to 1, which controls whether reserved key checking is done. Cookie.__ParseString(): When calling Morsel.set(), set strict=0 so no reserved key checking will be done. This makes sense because normally, the input data is coming from the web and we should be liberal in what we accept here. E.g. if a browser is setting "Version=1" we shouldn't crap out on the whole cookie just because of that. We /do/ want to be more strict when we're setting individual keys programmatically (but that will never call __ParseString()). --- misc/Cookie.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/misc/Cookie.py b/misc/Cookie.py index d2fe81c22..23af3e2f7 100644 --- a/misc/Cookie.py +++ b/misc/Cookie.py @@ -4,6 +4,7 @@ #### # Copyright (C) 1998 GTE Internetworking # Author: Timothy O'Malley +# Hacked: Barry Warsaw # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Library General Public @@ -416,8 +417,8 @@ class Morsel(UserDict): UserDict.__setitem__(self, K, V) # end __setitem__ - def set(self, key, val, coded_val): - if string.lower(key) in self.__reserved_keys: + def set(self, key, val, coded_val, strict=1): + if strict and string.lower(key) in self.__reserved_keys: raise CookieError("Attempt to set a reserved key: %s" % key) self.key = key self.value = val @@ -570,7 +571,7 @@ class Cookie(UserDict): # (Does anyone care?) else: M = Morsel() - M.set(K, apply(self.net_setfunc, (V,)), V) + M.set(K, apply(self.net_setfunc, (V,)), V, strict=0) UserDict.__setitem__(self, K, M) return # end __ParseString -- cgit v1.2.3-70-g09d2