Fixed stringwrap iteration bug.
authorFredrik Tolf <fredrik@dolda2000.com>
Sun, 2 Mar 2014 04:12:14 +0000 (05:12 +0100)
committerFredrik Tolf <fredrik@dolda2000.com>
Sun, 2 Mar 2014 04:12:14 +0000 (05:12 +0100)
wrw/util.py

index 8eed5a0..7c42eae 100644 (file)
@@ -7,16 +7,6 @@ def wsgiwrap(callable):
     wrapper.__wrapped__ = callable
     return wrapper
 
-def stringwrap(charset):
-    def dec(callable):
-        def wrapper(*args, **kwargs):
-            bk = callable(*args, **kwargs)
-            for string in bk:
-                yield string.encode(charset)
-        wrapper.__wrapped__ = callable
-        return wrapper
-    return dec
-
 def formparams(callable):
     spec = inspect.getargspec(callable)
     def wrapper(req):
@@ -120,6 +110,16 @@ def pregen(callable):
     wrapper.__wrapped__ = callable
     return wrapper
 
+def stringwrap(charset):
+    def dec(callable):
+        @pregen
+        def wrapper(*args, **kwargs):
+            for string in callable(*args, **kwargs):
+                yield string.encode(charset)
+        wrapper.__wrapped__ = callable
+        return wrapper
+    return dec
+
 class sessiondata(object):
     @classmethod
     def get(cls, req, create=True):