[Zope-Checkins] SVN: Zope/trunk/ Collector #891: Enabled locking of
RESPONSE.setStatus and RESPONSE.setBody
Chris Withers
chris at simplistix.co.uk
Fri Jul 30 12:15:41 EDT 2004
Log message for revision 26849:
Collector #891: Enabled locking of RESPONSE.setStatus and RESPONSE.setBody
Changed:
U Zope/trunk/doc/CHANGES.txt
U Zope/trunk/lib/python/ZPublisher/HTTPResponse.py
-=-
Modified: Zope/trunk/doc/CHANGES.txt
===================================================================
--- Zope/trunk/doc/CHANGES.txt 2004-07-30 16:09:51 UTC (rev 26848)
+++ Zope/trunk/doc/CHANGES.txt 2004-07-30 16:15:40 UTC (rev 26849)
@@ -26,6 +26,11 @@
Features added
+ - RESPONSE.setBody and RESPONSE.setStatus now accept lock
+ parameters in the same way as RESPONSE.redirect. These prevent
+ further calls to the methods from overwriting the previous value.
+ This is useful when writing http proxies.
+
- DateTime: new DateTime instance can be constructed from a given
DateTime instance: d_new = DateTime(d_old)
Modified: Zope/trunk/lib/python/ZPublisher/HTTPResponse.py
===================================================================
--- Zope/trunk/lib/python/ZPublisher/HTTPResponse.py 2004-07-30 16:09:51 UTC (rev 26848)
+++ Zope/trunk/lib/python/ZPublisher/HTTPResponse.py 2004-07-30 16:15:40 UTC (rev 26849)
@@ -146,6 +146,7 @@
realm = 'Zope'
_error_format = 'text/html'
_locked_status = 0
+ _locked_body = 0
# Indicate if setBody should content-compress output.
# 0 - no compression
@@ -199,7 +200,7 @@
"""Returns true if this request requested a server shutdown."""
return self._shutdown_flag is not None
- def setStatus(self, status, reason=None):
+ def setStatus(self, status, reason=None, lock=None):
'''\
Sets the HTTP status code of the response; the argument may
either be an integer or a string from { OK, Created, Accepted,
@@ -234,6 +235,9 @@
reason = 'Unknown'
self.setHeader('Status', "%d %s" % (status,str(reason)))
self.errmsg = reason
+ # lock the status if we're told to
+ if lock:
+ self._locked_status = 1
def setHeader(self, name, value, literal=0):
'''\
@@ -268,7 +272,8 @@
latin1_alias_match=re.compile(
r'text/html(\s*;\s*charset=((latin)|(latin[-_]?1)|'
r'(cp1252)|(cp819)|(csISOLatin1)|(IBM819)|(iso-ir-100)|'
- r'(iso[-_]8859[-_]1(:1987)?)))?$',re.I).match
+ r'(iso[-_]8859[-_]1(:1987)?)))?$',re.I).match,
+ lock=None
):
'''\
Set the body of the response
@@ -285,6 +290,12 @@
If is_error is true then the HTML will be formatted as a Zope error
message instead of a generic HTML page.
'''
+ # allow locking of the body in the same way as the status
+ if self._locked_body:
+ return
+ elif lock:
+ self._locked_body = 1
+
if not body:
return self
More information about the Zope-Checkins
mailing list