[Zope-Checkins] CVS: Zope3/lib/python/Zope/Publisher/HTTP - __init__.py:1.1.2.1 HTTPRequest.py:1.1.2.3 HTTPResponse.py:1.1.2.2
Shane Hathaway
shane@digicool.com
Thu, 15 Nov 2001 14:28:51 -0500
Update of /cvs-repository/Zope3/lib/python/Zope/Publisher/HTTP
In directory cvs.zope.org:/tmp/cvs-serv28805/HTTP
Modified Files:
Tag: Zope-3x-branch
HTTPRequest.py HTTPResponse.py
Added Files:
Tag: Zope-3x-branch
__init__.py
Log Message:
Added a minitest module to ensure everything works. Bugfixes:
- Missed attributes, misspelled signatures, etc.
- Print module name instead of filename in tracebacks--this could be
backported to Zope 2.x easily.
- publication.handleException() has to return a response object
- Include SERVER_URL in request.__str__()
=== Added File Zope3/lib/python/Zope/Publisher/HTTP/__init__.py ===
"""
HTTP publisher
"""
=== Zope3/lib/python/Zope/Publisher/HTTP/HTTPRequest.py 1.1.2.2 => 1.1.2.3 ===
#cgi hotfix:
if not hasattr(cgi, 'valid_boundary'):
- import cgi_hotfix
+ try: import cgi_hotfix
+ except ImportError: pass
isCGI_NAME = {
# These fields are placed in request.environ instead of request.form.
@@ -132,7 +133,7 @@
if hostname is None: hostname = oldhostname
if port is None: port = oldport
- if (port is None or DEFAULT_PORTS.get(protocol, 80) == port):
+ if (not port or DEFAULT_PORTS.get(protocol, 80) == port):
host = hostname
else:
host = hostname + ':' + port
@@ -205,6 +206,7 @@
self._computed_urls = ()
def _deduceServerURL(self):
+ have_env = self.environ.has_key
if have_env('HTTPS') and (
environ['HTTPS'] == "on" or environ['HTTPS'] == "ON"):
protocol = 'https'
@@ -229,14 +231,14 @@
# port=s_port
else:
- hostname = environ['SERVER_NAME'].strip()
- port = environ['SERVER_PORT']
+ hostname = self.environ.get('SERVER_NAME', '').strip()
+ port = self.environ.get('SERVER_PORT', '')
self.setServerURL(protocol=protocol, hostname=hostname, port=port)
return self.SERVER_URL
def __init__(self, full_instream, environ, response):
- BaseRequest.__init__(response)
+ BaseRequest.__init__(self, response)
self.full_instream = full_instream
self._orig_env = environ
environ = sane_environment(environ)
@@ -246,7 +248,6 @@
del environ['HTTP_AUTHORIZATION']
self.environ=environ
- have_env=environ.has_key
get_env=environ.get
other=self.other={'RESPONSE': response}
self.form={}
@@ -694,10 +695,16 @@
v.insert(0, '')
else:
v.insert(0, self.SERVER_URL)
- other[key] = res = '/'.join(v)
+ self.other[key] = res = '/'.join(v)
self._computed_urls = self._computed_urls + (key,)
return res
+ _key_handlers = BaseRequest._key_handlers.copy()
+
+ def getServerURL(self, defaut=None):
+ return self.SERVER_URL
+ _key_handlers['SERVER_URL'] = getServerURL
+
def get(self, key, default=None):
"""
@@ -751,7 +758,7 @@
return self.get(key, _marker) is not _marker
def keys(self):
- keys = {'URL':1}
+ keys = {'URL':1, 'SERVER_URL':1}
keys.update(self.common)
for key in self.environ.keys():
@@ -780,6 +787,7 @@
def __str__(self):
result = "<p>URL: %s</p>" % self.URL
+ result = result + "<p>SERVER_URL: %s</p>" % self.SERVER_URL
result = result + "<h3>form</h3><table>"
row='<tr valign="top" align="left"><th>%s</th><td>%s</td></tr>'
for k,v in self.form.items():
@@ -809,6 +817,7 @@
def text(self):
result = "URL: %s\n" % self.URL
+ result = result + "SERVER_URL: %s" % self.SERVER_URL
result = result + "FORM\n\n"
row='%-20s %s\n'
for k,v in self.form.items():
=== Zope3/lib/python/Zope/Publisher/HTTP/HTTPResponse.py 1.1.2.1 => 1.1.2.2 ===
from Zope.Publisher.BaseResponse import BaseResponse
+from Zope.Publisher.Exceptions import Redirect
nl2sp = string.maketrans('\n',' ')
@@ -115,6 +116,7 @@
accumulated_headers = ''
body = ''
+ base = None
realm = 'Zope'
_error_format = 'text/html'
@@ -333,8 +335,11 @@
return
self.setStatus(t)
body = ("<html><head><title>Site error</title></head>\n"
- "<body><p>A site error occurred.</p><pre>%s</pre>"
- "</body></html>" %
+ "<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]))
)
self.setBody(body)
@@ -441,9 +446,11 @@
co = f.f_code
filename = co.co_filename
name = co.co_name
- locals=f.f_locals
- result.append(' File %s, line %d, in %s'
- % (filename,lineno,name))
+ locals = f.f_locals
+ globals = f.f_globals
+ modname = globals.get('__name__', filename)
+ result.append(' Module %s, line %d, in %s'
+ % (modname,lineno,name))
try: result.append(' (Object: %s)' %
locals[co.co_varnames[0]].__name__)
except: pass