Commits

Anonymous committed d392989

Allow methods to return recursive generators

  • Participants
  • Parent commits ecdc624
  • Branches cherrypy

Comments (0)

Files changed (1)

File _cphttptools.py

     if not isinstance(body, types.GeneratorType):
         cpg.response.body = [body]
     else:
-        cpg.response.body = body
+        cpg.response.body = flattener(body)
 
     if cpg.response.sendResponse:
         sendResponse(wfile)
 
+def flattener(input):
+    for x in input:
+        if not isinstance(x, types.GeneratorType):
+            yield x
+        else:
+            for y in flattener(x):
+                yield y 
+
+
 def generateSessionId():
     s = ''
     for i in range(50):