Commit dc182855 authored by Andreas Jung's avatar Andreas Jung

some cleanup

parent 219b69c6
...@@ -249,6 +249,7 @@ class HTTPResponse(BaseResponse): ...@@ -249,6 +249,7 @@ class HTTPResponse(BaseResponse):
literal flag is true, the case of the header name is preserved, literal flag is true, the case of the header name is preserved,
otherwise word-capitalization will be performed on the header otherwise word-capitalization will be performed on the header
name on output.''' name on output.'''
name = str(name) name = str(name)
value = str(value) value = str(value)
key = name.lower() key = name.lower()
...@@ -458,21 +459,20 @@ class HTTPResponse(BaseResponse): ...@@ -458,21 +459,20 @@ class HTTPResponse(BaseResponse):
# Encode the Unicode data as requested # Encode the Unicode data as requested
if self.headers.has_key('content-type'): ct = self.headers.get('content-type')
match = charset_re.match(self.headers['content-type']) if ct:
match = charset_re.match(ct)
if match: if match:
encoding = match.group(1) encoding = match.group(1)
body = body.encode(encoding) body = body.encode(encoding)
body = fix_xml_preamble(body, encoding) body = fix_xml_preamble(body, encoding)
return body return body
else: else:
ct = self.headers['content-type']
if ct.startswith('text/') or ct.startswith('application/'): if ct.startswith('text/') or ct.startswith('application/'):
self.headers['content-type'] = '%s; charset=%s' % (ct, default_encoding) self.headers['content-type'] = '%s; charset=%s' % (ct, default_encoding)
# Use the default character encoding # Use the default character encoding
body = body.encode(default_encoding,'replace') body = body.encode(default_encoding, 'replace')
body = fix_xml_preamble(body, default_encoding) body = fix_xml_preamble(body, default_encoding)
return body return 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