|
List Info
Thread: nested yield() calls not working with 3.0.2
|
|
| nested yield() calls not working with
3.0.2 |
  United States |
2007-09-27 09:05:55 |
I have some older code that I was previously running under
3.0.1.
After setting up a system last night with 3.0.2, I found
that I cannot
run the same code. It does streaming (for good or bad), and
thus
makes use of yield() calls. In many cases, I am making a
yield() call
to a method on another object, which feeds back data by its
own calls
to yield(). It seems that the WSGI code doesn't fully
unwrap the
resulting generator.
Here is sample code that demonstrates the error:
import cherrypy
cherrypy.lowercase_api = True
from time import sleep
class TestClass:
# this works fine
def works(self):
for i in xrange(10):
sleep(1)
if (i != 0):
(yield ("<script
type="text/javascript">
ndocument.body.removeChild(document.getElementById("f
oo%d"));n</
script>n" % (i-1)))
(yield ("<div id='foo%d'>Please
wait %d</p></div>n" %
(i, i)))
works.exposed = True
# calling this results in
# Traceback (most recent call last):
# File
"c:python25Libsite-packagescherrypy_cpwsgi.py"
;, line
175, in next
# chunk = chunk.encode("ISO-8859-1")
# AttributeError: 'generator' object has no attribute
'encode'
def nested(self):
yield self.works()
nested.exposed = True
# this works fine
def nested2(self):
return self.works()
nested2.exposed = True
TestClass._cp_config = {'response.stream': True}
if __name__ == '__main__':
cherrypy.config.update({'server.socket_port': 8080,
'response.stream': True, 'log.screen': True})
cherrypy.tree.mount(TestClass(), "/")
cherrypy.server.quickstart()
cherrypy.engine.start()
Advice or fixes appreciated.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "cherrypy-users" group.
To post to this group, send email to cherrypy-users googlegroups.com
To unsubscribe from this group, send email to
cherrypy-users-unsubscribe googlegroups.com
For more options, visit this group at h
ttp://groups.google.com/group/cherrypy-users?hl=en
-~----------~----~----~----~------~----~------~--~---
|
|
| Re: nested yield() calls not working
with 3.0.2 |
  United States |
2007-09-27 10:30:39 |
At first glance, I *think* you want:
def nested(self):
return self.works()
nested.exposed = True
Robert Brewer
fumanchu aminus.org
-----Original Message-----
From: cherrypy-users googlegroups.com on behalf of Knockin
Sent: Thu 9/27/2007 7:05 AM
To: cherrypy-users
Subject: [cherrypy-users] nested yield() calls not working
with 3.0.2
I have some older code that I was previously running under
3.0.1.
After setting up a system last night with 3.0.2, I found
that I cannot
run the same code. It does streaming (for good or bad), and
thus
makes use of yield() calls. In many cases, I am making a
yield() call
to a method on another object, which feeds back data by its
own calls
to yield(). It seems that the WSGI code doesn't fully
unwrap the
resulting generator.
Here is sample code that demonstrates the error:
import cherrypy
cherrypy.lowercase_api = True
from time import sleep
class TestClass:
# this works fine
def works(self):
for i in xrange(10):
sleep(1)
if (i != 0):
(yield ("<script
type="text/javascript">
ndocument.body.removeChild(document.getElementById("f
oo%d"));n</
script>n" % (i-1)))
(yield ("<div id='foo%d'>Please
wait %d</p></div>n" %
(i, i)))
works.exposed = True
# calling this results in
# Traceback (most recent call last):
# File
"c:python25Libsite-packagescherrypy_cpwsgi.py"
;, line
175, in next
# chunk = chunk.encode("ISO-8859-1")
# AttributeError: 'generator' object has no attribute
'encode'
def nested(self):
yield self.works()
nested.exposed = True
# this works fine
def nested2(self):
return self.works()
nested2.exposed = True
TestClass._cp_config = {'response.stream': True}
if __name__ == '__main__':
cherrypy.config.update({'server.socket_port': 8080,
'response.stream': True, 'log.screen': True})
cherrypy.tree.mount(TestClass(), "/")
cherrypy.server.quickstart()
cherrypy.engine.start()
Advice or fixes appreciated.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "cherrypy-users" group.
To post to this group, send email to cherrypy-users googlegroups.com
To unsubscribe from this group, send email to
cherrypy-users-unsubscribe googlegroups.com
For more options, visit this group at h
ttp://groups.google.com/group/cherrypy-users?hl=en
-~----------~----~----~----~------~----~------~--~---
|
|
|
| Re: nested yield() calls not working
with 3.0.2 |
  United States |
2007-09-27 11:16:55 |
I only gave a simplified code sample that demonstrates the
problem.
The actual code does something more along the lines of
def nested(self):
yield "some output"
yield obj.processData()
yield "other output"
yield obj.otherData()
On Sep 27, 11:30 am, "Robert Brewer"
<fuman... aminus.org> wrote:
> At first glance, I *think* you want:
>
> def nested(self):
> return self.works()
> nested.exposed = True
>
> Robert Brewer
> fuman... aminus.org
>
> -----Original Message-----
> From: cherrypy-users googlegroups.com on behalf
of Knockin
> Sent: Thu 9/27/2007 7:05 AM
> To: cherrypy-users
> Subject: [cherrypy-users] nested yield() calls not
working with 3.0.2
>
> I have some older code that I was previously running
under 3.0.1.
> After setting up a system last night with 3.0.2, I
found that I cannot
> run the same code. It does streaming (for good or
bad), and thus
> makes use of yield() calls. In many cases, I am making
a yield() call
> to a method on another object, which feeds back data by
its own calls
> to yield(). It seems that the WSGI code doesn't fully
unwrap the
> resulting generator.
>
> Here is sample code that demonstrates the error:
>
> import cherrypy
> cherrypy.lowercase_api = True
> from time import sleep
>
> class TestClass:
> # this works fine
> def works(self):
> for i in xrange(10):
> sleep(1)
> if (i != 0):
> (yield ("<script
type="text/javascript">
>
ndocument.body.removeChild(document.getElementById("f
oo%d"));n</
> script>n" % (i-1)))
> (yield ("<div
id='foo%d'>Please wait %d</p></div>n"
%
> (i, i)))
> works.exposed = True
>
> # calling this results in
> # Traceback (most recent call last):
> # File
"c:python25Libsite-packagescherrypy_cpwsgi.py"
;, line
> 175, in next
> # chunk = chunk.encode("ISO-8859-1")
> # AttributeError: 'generator' object has no
attribute 'encode'
> def nested(self):
> yield self.works()
> nested.exposed = True
>
> # this works fine
> def nested2(self):
> return self.works()
> nested2.exposed = True
>
> TestClass._cp_config = {'response.stream': True}
>
> if __name__ == '__main__':
> cherrypy.config.update({'server.socket_port':
8080,
> 'response.stream': True, 'log.screen': True})
> cherrypy.tree.mount(TestClass(), "/")
> cherrypy.server.quickstart()
> cherrypy.engine.start()
>
> Advice or fixes appreciated.
>
>
>
> winmail.dat
> 5KDownload
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "cherrypy-users" group.
To post to this group, send email to cherrypy-users googlegroups.com
To unsubscribe from this group, send email to
cherrypy-users-unsubscribe googlegroups.com
For more options, visit this group at h
ttp://groups.google.com/group/cherrypy-users?hl=en
-~----------~----~----~----~------~----~------~--~---
|
|
[1-3]
|
|
|
about | contact Other archives ( Real Estate discussion Medical topics )
|