Commit 8a8ea9b0 authored by 's avatar

Bug 1797: unicode safety

parent 4c3767ed
...@@ -83,7 +83,7 @@ ...@@ -83,7 +83,7 @@
# #
############################################################################## ##############################################################################
__version__='$Revision: 1.40 $'[11:-2] __version__='$Revision: 1.41 $'[11:-2]
import regex, re, sys, os, string, urllib import regex, re, sys, os, string, urllib
from string import lower, atoi, rfind, split, strip, join, upper, find from string import lower, atoi, rfind, split, strip, join, upper, find
...@@ -871,14 +871,14 @@ class HTTPRequest(BaseRequest): ...@@ -871,14 +871,14 @@ class HTTPRequest(BaseRequest):
result="<h3>form</h3><table>" result="<h3>form</h3><table>"
row='<tr valign="top" align="left"><th>%s</th><td>%s</td></tr>' row='<tr valign="top" align="left"><th>%s</th><td>%s</td></tr>'
for k,v in self.form.items(): for k,v in self.form.items():
result=result + row % (html_quote(k), html_quote(v)) result=result + row % (html_quote(k), html_quote(repr(v)))
result=result+"</table><h3>cookies</h3><table>" result=result+"</table><h3>cookies</h3><table>"
for k,v in self.cookies.items(): for k,v in self.cookies.items():
result=result + row % (html_quote(k), html_quote(v)) result=result + row % (html_quote(k), html_quote(repr(v)))
result=result+"</table><h3>other</h3><table>" result=result+"</table><h3>other</h3><table>"
for k,v in self.other.items(): for k,v in self.other.items():
if k in ('PARENTS','RESPONSE'): continue if k in ('PARENTS','RESPONSE'): continue
result=result + row % (html_quote(k), html_quote(v)) result=result + row % (html_quote(k), html_quote(repr(v)))
for n in "0123456789": for n in "0123456789":
key = "URL%s"%n key = "URL%s"%n
...@@ -1051,7 +1051,10 @@ class record: ...@@ -1051,7 +1051,10 @@ class record:
L1.sort() L1.sort()
return join(map(lambda item: "%s: %s" %item, L1), ", ") return join(map(lambda item: "%s: %s" %item, L1), ", ")
__repr__ = __str__ def __repr__(self):
L1 = self.__dict__.items()
L1.sort()
return join(map(lambda item: "%s: %s" %item, repr(L1)), ", ")
# Flags # Flags
SEQUENCE=1 SEQUENCE=1
......
...@@ -84,8 +84,8 @@ ...@@ -84,8 +84,8 @@
############################################################################## ##############################################################################
'''CGI Response Output formatter '''CGI Response Output formatter
$Id: HTTPResponse.py,v 1.39 2000/12/15 16:14:01 evan Exp $''' $Id: HTTPResponse.py,v 1.40 2000/12/27 16:36:12 brian Exp $'''
__version__='$Revision: 1.39 $'[11:-2] __version__='$Revision: 1.40 $'[11:-2]
import string, types, sys, regex, re import string, types, sys, regex, re
from string import find, rfind, lower, upper, strip, split, join, translate from string import find, rfind, lower, upper, strip, split, join, translate
...@@ -161,8 +161,6 @@ status_codes['redirect']=300 ...@@ -161,8 +161,6 @@ status_codes['redirect']=300
start_of_header_search=re.compile('(<head[^>]*>)', re.IGNORECASE).search start_of_header_search=re.compile('(<head[^>]*>)', re.IGNORECASE).search
#end_of_header_search=regex.compile('</head>',regex.casefold).search
accumulate_header={'set-cookie': 1}.has_key accumulate_header={'set-cookie': 1}.has_key
class HTTPResponse(BaseResponse): class HTTPResponse(BaseResponse):
...@@ -578,7 +576,7 @@ class HTTPResponse(BaseResponse): ...@@ -578,7 +576,7 @@ class HTTPResponse(BaseResponse):
"\\(#[^\000- \"\\#<>]*\\)?" "\\(#[^\000- \"\\#<>]*\\)?"
"$" "$"
).match, ).match,
tag_search=regex.compile('[a-zA-Z]>').search, tag_search=re.compile('[a-zA-Z]>').search,
abort=1 abort=1
): ):
if type(info) is type(()) and len(info)==3: t,v,tb = info if type(info) is type(()) and len(info)==3: t,v,tb = info
...@@ -627,7 +625,11 @@ class HTTPResponse(BaseResponse): ...@@ -627,7 +625,11 @@ class HTTPResponse(BaseResponse):
except: pass except: pass
b=v b=v
if isinstance(b,Exception): b=str(b) if isinstance(b,Exception):
try:
b=str(b)
except:
b='<unprintable %s object>' % type(b).__name__
if fatal and t is SystemExit and v.code==0: if fatal and t is SystemExit and v.code==0:
tb=self.setBody( tb=self.setBody(
...@@ -637,7 +639,7 @@ class HTTPResponse(BaseResponse): ...@@ -637,7 +639,7 @@ class HTTPResponse(BaseResponse):
is_error=1) is_error=1)
#elif 1: self.setBody(v) #elif 1: self.setBody(v)
elif type(b) is not types.StringType or tag_search(b) < 0: elif type(b) is not types.StringType or tag_search(b) is None:
tb=self.setBody( tb=self.setBody(
(str(t), (str(t),
'Sorry, a Zope error occurred.<p>'+ 'Sorry, a Zope error occurred.<p>'+
...@@ -696,23 +698,6 @@ class HTTPResponse(BaseResponse): ...@@ -696,23 +698,6 @@ class HTTPResponse(BaseResponse):
c='text/plain' c='text/plain'
self.setHeader('content-type',c) self.setHeader('content-type',c)
# Don't try to fix user HTML!
#else:
# isHTML = split(headers.get('content-type', ''),
# ';')[0] == 'text/html'
#if isHTML and end_of_header_search(self.body) < 0:
# lhtml=html_search(body)
# if lhtml >= 0:
# lhtml=lhtml+6
# body='%s<head></head>\n%s' % (body[:lhtml],body[lhtml:])
# elif contHTML:
# body='<html><head></head>\n' + body
# else:
# body='<html><head></head>\n' + body + '\n</html>\n'
# self.setBody(body)
# body=self.body
if not headers.has_key('content-length') and \ if not headers.has_key('content-length') and \
not headers.has_key('transfer-encoding'): not headers.has_key('transfer-encoding'):
self.setHeader('content-length',len(body)) self.setHeader('content-length',len(body))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment