[Zope-Checkins] CVS: Zope3/lib/python/Zope/Publisher/HTTP - BrowserPayload.py:1.1.2.2 HTTPRequest.py:1.1.2.5
Shane Hathaway
shane@digicool.com
Fri, 16 Nov 2001 11:05:30 -0500
Update of /cvs-repository/Zope3/lib/python/Zope/Publisher/HTTP
In directory cvs.zope.org:/tmp/cvs-serv4421/Zope/Publisher/HTTP
Modified Files:
Tag: Zope-3x-branch
BrowserPayload.py HTTPRequest.py
Log Message:
Mainly improved exception handling
=== Zope3/lib/python/Zope/Publisher/HTTP/BrowserPayload.py 1.1.2.1 => 1.1.2.2 ===
from IPayload import IRequestPayload, IResponsePayload
from Zope.Publisher.Converters import get_converter
-from Zope.Publisher.Exceptions import Redirect
+from Zope.Publisher.Exceptions import Redirect, Unauthorized
#from Zope.Publisher.Browser import IBrowserPublish
@@ -29,8 +29,8 @@
__implements__ = IRequestPayload
def getPreferredPublishingType(self):
- return IBrowserPublish
-
+ #return IBrowserPublish
+ return None
def processInputs(
self, request, fs=None,
@@ -56,14 +56,12 @@
method = environ.get('REQUEST_METHOD', 'GET')
meth = None
- if fs is None:
- if method == 'GET':
- fp = request.full_instream
- else:
- fp = None
+ if fs is None and method != 'GET':
+ # Process form if not a GET request.
+ fp = request.full_instream
fs = FieldStorage(fp=fp, environ=environ, keep_blank_values=1)
- fslist = fs.list
+ fslist = getattr(fs, 'list', None)
if fslist is not None:
tuple_items={}
lt=type([])
@@ -472,26 +470,38 @@
(body[:index], response.base, body[index:]))
return body
+ def _html(self, title, content):
+ t = escape(title)
+ return (
+ "<html><head><title>%s</title></head>\n"
+ "<body><h2>%s</h2>\n"
+ "%s\n"
+ "</body></html>\n" %
+ (t, t, content)
+ )
+
def handleException(self, response, exc_info):
"""
Calls setBody() with an error response.
"""
t, v = exc_info[:2]
if isinstance(t, ClassType):
+ title = tname = t.__name__
if issubclass(t, Redirect):
response.redirect(v.getLocation())
return
- response.setStatus(t)
- body = ("<html><head><title>Site error</title></head>\n"
- "<body><p>A site error occurred.</p>\n"
- "<pre>\n"
- "%s\n"
- "</pre>\n"
- "</body></html>\n" %
- escape(traceback_string(t, v, exc_info[2]))
- )
+ elif issubclass(t, Unauthorized):
+ response.setHeader('WWW-Authenticate', 'basic realm="%s"'
+ % response.realm, 1)
+ title = 'You are not authorized to access this resource.'
+ else:
+ title = tname = str(t)
+
+ response.setStatus(tname)
+ tb = escape(traceback_string(t, v, exc_info[2]))
+ body = self._html(title, "<pre>\n%s\n</pre>" % tb)
response.setBody(body)
-
+
class FileUpload:
=== Zope3/lib/python/Zope/Publisher/HTTP/HTTPRequest.py 1.1.2.4 => 1.1.2.5 ===
_script = () # SERVER_URL + _script + quoted_steps == full URL
script = '' # script + quoted_steps = full URL
+
+ # payload is a protocol-specific handler for the body of
+ # the request.
payload = BrowserRequestPayload()
-
+
SERVER_URL = '' # The SERVER_URL header
retry_count = 0
@@ -266,7 +269,9 @@
self.cookies=cookies
def processInputs(self):
- self.payload.processInputs(self)
+ payload = self.payload
+ self.ptype = payload.getPreferredPublishingType()
+ payload.processInputs(self)
def get_header(self, name, default=None):
"""Return the named HTTP header, or an optional default
@@ -407,7 +412,7 @@
def text(self):
result = "URL: %s\n" % self.URL
- result = result + "SERVER_URL: %s" % self.SERVER_URL
+ result = result + "SERVER_URL: %s\n\n" % self.SERVER_URL
result = result + "FORM\n\n"
row='%-20s %s\n'
for k,v in self.form.items():