summaryrefslogtreecommitdiff
path: root/paste/wsgilib.py
diff options
context:
space:
mode:
authorpjenvey <devnull@localhost>2006-09-04 00:08:51 +0000
committerpjenvey <devnull@localhost>2006-09-04 00:08:51 +0000
commit949016497f710e5cbccf7388a90896d1452906c7 (patch)
treea34e1c3e8afe622ac9adae8200b817b9da56d96d /paste/wsgilib.py
parentc2f10a7f75bc6728c52af4dde97c509b55c060ed (diff)
downloadpaste-949016497f710e5cbccf7388a90896d1452906c7.tar.gz
o WSGIResponse changes:0.9.8
- properly encoding any unicode content according to the response's charset - handling generator/iterator content more cleanly - fixed delete_cookie. also now takes optional path and domain args o added wsgilib.encode_unicode_app_iter: encodes an app_iterable's unicode responses as strings
Diffstat (limited to 'paste/wsgilib.py')
-rw-r--r--paste/wsgilib.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/paste/wsgilib.py b/paste/wsgilib.py
index b2e8c68..eb3b157 100644
--- a/paste/wsgilib.py
+++ b/paste/wsgilib.py
@@ -147,6 +147,31 @@ class chained_app_iters:
"WSGI request. finalization function %s not called"
% self.close_func)
+class encode_unicode_app_iter:
+ """
+ Encodes an app_iterable's unicode responses as strings
+ """
+
+ def __init__(self, app_iterable, encoding=sys.getdefaultencoding(),
+ errors='strict'):
+ self.app_iterable = app_iterable
+ self.app_iter = iter(app_iterable)
+ self.encoding = encoding
+ self.errors = errors
+
+ def __iter__(self):
+ return self
+
+ def next(self):
+ content = self.app_iter.next()
+ if isinstance(content, unicode):
+ content = content.encode(self.encoding, self.errors)
+ return content
+
+ def close(self):
+ if hasattr(self.app_iterable, 'close'):
+ self.app_iterable.close()
+
def catch_errors(application, environ, start_response, error_callback,
ok_callback=None):
"""