[Zope-Checkins] SVN: Zope/trunk/ `setHeader('Set-Cookie', ...)` special-casing can die

2011-10-13 Thread Martijn Pieters
Log message for revision 123087:
  `setHeader('Set-Cookie', ...)` special-casing can die
  
  Use the cookie APIs or addHeader instead.
  

Changed:
  U   Zope/trunk/doc/CHANGES.rst
  U   Zope/trunk/src/ZPublisher/HTTPResponse.py

-=-
Modified: Zope/trunk/doc/CHANGES.rst
===
--- Zope/trunk/doc/CHANGES.rst  2011-10-13 09:46:28 UTC (rev 123086)
+++ Zope/trunk/doc/CHANGES.rst  2011-10-13 13:18:32 UTC (rev 123087)
@@ -50,6 +50,11 @@
 Restructuring
 +
 
+- Removed the special handling of `Set-Cookie` headers in
+  `HTTPResponse.setHeader`. Use the `setCookie`/`appendCookie`/`expireCookie`
+  methods instead, or if low-level control is needed, use `addHeader` instead
+  to get the exact same effect.
+
 - Removed the `App.version_txt.getZopeVersion` API, you can use
   ``pkg_resources.get_distribution('Zope2').version`` instead.
 

Modified: Zope/trunk/src/ZPublisher/HTTPResponse.py
===
--- Zope/trunk/src/ZPublisher/HTTPResponse.py   2011-10-13 09:46:28 UTC (rev 
123086)
+++ Zope/trunk/src/ZPublisher/HTTPResponse.py   2011-10-13 13:18:32 UTC (rev 
123087)
@@ -330,13 +330,8 @@
 if not scrubbed:
 name, value = _scrubHeader(name, value)
 key = name.lower()
-# The following is crazy, given that we have APIs for cookies.
-# Special behavior will go away in Zope 2.13
-if key == 'set-cookie':  
-self.accumulated_headers.append((name, value))
-else:
-name = literal and name or key
-self.headers[name] = value
+name = literal and name or key
+self.headers[name] = value
 
 def appendHeader(self, name, value, delimiter=, ):
  Append a value to an HTTP return header.

___
Zope-Checkins maillist  -  Zope-Checkins@zope.org
https://mail.zope.org/mailman/listinfo/zope-checkins


[Zope-Checkins] SVN: Zope/trunk/ Remove the lock around the cookie parsing code.

2011-10-13 Thread Martijn Pieters
Log message for revision 123088:
  Remove the lock around the cookie parsing code.
  
  The locking here was only ever needed for the old `regex` module that was
  originally used for this code, but that was replaced by the thread-safe `re`
  some 10 years ago (see r20110, april 2001).
  

Changed:
  U   Zope/trunk/doc/CHANGES.rst
  U   Zope/trunk/src/ZPublisher/HTTPRequest.py

-=-
Modified: Zope/trunk/doc/CHANGES.rst
===
--- Zope/trunk/doc/CHANGES.rst  2011-10-13 13:18:32 UTC (rev 123087)
+++ Zope/trunk/doc/CHANGES.rst  2011-10-13 14:15:41 UTC (rev 123088)
@@ -50,6 +50,10 @@
 Restructuring
 +
 
+- Removed the (very obsolete) thread lock around the cookie parsing code
+  in HTTPRequest.py; the python `re` module is thread-safe, unlike the
+  ancient `regex` module that was once used here.
+
 - Removed the special handling of `Set-Cookie` headers in
   `HTTPResponse.setHeader`. Use the `setCookie`/`appendCookie`/`expireCookie`
   methods instead, or if low-level control is needed, use `addHeader` instead

Modified: Zope/trunk/src/ZPublisher/HTTPRequest.py
===
--- Zope/trunk/src/ZPublisher/HTTPRequest.py2011-10-13 13:18:32 UTC (rev 
123087)
+++ Zope/trunk/src/ZPublisher/HTTPRequest.py2011-10-13 14:15:41 UTC (rev 
123088)
@@ -40,7 +40,6 @@
 from ZPublisher.BaseRequest import BaseRequest
 from ZPublisher.BaseRequest import quote
 from ZPublisher.Converters import get_converter
-from ZPublisher.maybe_lock import allocate_lock
 
 # Flags
 SEQUENCE = 1
@@ -1649,7 +1648,6 @@
 return self
 
 
-parse_cookie_lock = allocate_lock()
 QPARMRE= re.compile(
 '([\x00- ]*([^\x00- ;,=]+)=([^]*)([\x00- ]*[;,])?[\x00- ]*)')
 PARMRE = re.compile(
@@ -1661,43 +1659,36 @@
  qparmre=QPARMRE,
  parmre=PARMRE,
  paramlessre=PARAMLESSRE,
- acquire=parse_cookie_lock.acquire,
- release=parse_cookie_lock.release,
  ):
 
 if result is None:
 result = {}
 
-acquire()
-try:
+mo_q = qparmre.match(text)
 
-mo_q = qparmre.match(text)
+if mo_q:
+# Match quoted correct cookies
+l = len(mo_q.group(1))
+name = mo_q.group(2)
+value = mo_q.group(3)
 
-if mo_q:
-# Match quoted correct cookies
-l = len(mo_q.group(1))
-name = mo_q.group(2)
-value = mo_q.group(3)
+else:
+# Match evil MSIE cookies ;)
+mo_p = parmre.match(text)
 
+if mo_p:
+l = len(mo_p.group(1))
+name = mo_p.group(2)
+value = mo_p.group(3)
 else:
-# Match evil MSIE cookies ;)
-mo_p = parmre.match(text)
-
-if mo_p:
-l = len(mo_p.group(1))
-name = mo_p.group(2)
-value = mo_p.group(3)
+# Broken Cookie without = nor value.
+broken_p = paramlessre.match(text)
+if broken_p:
+l = len(broken_p.group(1))
+name = broken_p.group(2)
+value = ''
 else:
-# Broken Cookie without = nor value.
-broken_p = paramlessre.match(text)
-if broken_p:
-l = len(broken_p.group(1))
-name = broken_p.group(2)
-value = ''
-else:
-return result
-finally:
-release()
+return result
 
 if name not in result:
 result[name] = unquote(value)

___
Zope-Checkins maillist  -  Zope-Checkins@zope.org
https://mail.zope.org/mailman/listinfo/zope-checkins