diff options
author | pjenvey <devnull@localhost> | 2006-09-04 20:20:55 +0000 |
---|---|---|
committer | pjenvey <devnull@localhost> | 2006-09-04 20:20:55 +0000 |
commit | b106c5c17d18755ce7c2c32d831d1773a0f97835 (patch) | |
tree | 2412806b83dd09194f836bacc964ae7aa0adbef9 /paste/wsgiwrappers.py | |
parent | 54f6af6bfb71e393cc3a74f812338149f9ad2fdd (diff) | |
download | paste-b106c5c17d18755ce7c2c32d831d1773a0f97835.tar.gz |
o fixed WSGIResponse to determine the correct encoding after the Content-Type
header was changed
o defaulting the WSGIResponse charset to iso-8859-1 as per RFC2616
o fixed HeaderDict's get and setdefault to be case insensitive
Diffstat (limited to 'paste/wsgiwrappers.py')
-rw-r--r-- | paste/wsgiwrappers.py | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/paste/wsgiwrappers.py b/paste/wsgiwrappers.py index 1063988..ab33098 100644 --- a/paste/wsgiwrappers.py +++ b/paste/wsgiwrappers.py @@ -140,13 +140,9 @@ class WSGIResponse(object): self.headers = HeaderDict() self.cookies = SimpleCookie() self.status_code = code - self.encoding = settings['charset'] if not mimetype: - mimetype = "%s; charset=%s" % (settings['content_type'], settings['charset']) - else: - charset_match = _CHARSET_RE.match(mimetype) - if charset_match: - self.encoding = charset_match.group(1) + mimetype = "%s; charset=%s" % (settings['content_type'], + settings['charset']) self.headers['Content-Type'] = mimetype if 'encoding_errors' in settings: @@ -168,6 +164,17 @@ class WSGIResponse(object): return '\n'.join(['%s: %s' % (key, value) for key, value in self.headers.headeritems()]) \ + '\n\n' + content + + def determine_encoding(self): + """ + Determine the encoding as specified by the Content-Type's charset + parameter, if one is set + """ + charset_match = _CHARSET_RE.match(self.headers.get('Content-Type', '')) + if charset_match: + return charset_match.group(1) + # No charset specified, default to iso-8859-1 as per RFC2616 + return 'iso-8859-1' def has_header(self, header): """ @@ -224,7 +231,7 @@ class WSGIResponse(object): Returns the content as an iterable of strings, encoding each element of the iterator from a Unicode object if necessary. """ - return encode_unicode_app_iter(self.content, self.encoding, + return encode_unicode_app_iter(self.content, self.determine_encoding(), self.encoding_errors) def wsgi_response(self): |