Re: How to handle interrupted responses in nevow?
"Peter Westlake" <[email protected]>
| Newsgroups | gmane.comp.python.twisted.web |
|---|---|
| Message-ID | <[email protected]> |
On Fri, 15 Oct 2010 19:03 +0000, [email protected] wrote: > On 04:52 pm, [email protected] wrote: > >A quick question about Python style: > > > >nevow.Request is a subclass of twisted.web.server.Request, > >which is a subclass of http.Request, which has an attribute > >_disconnected. Since the name begins with an underscore, it > >isn't intended to be part of the public API, and I think > >that means I can't refer to it in nevow.Request. > > > >There are two options: > > > >1) use notifyFinish() to set a new attribute in nevow.Request, > > which would end up duplicating _disconnected; > > > >2) use it anyway, and file a request for _disconnected to > > become part of the published interface. > > > >Both approaches work, and I have a unit test to prove it! > >Which would you like me to do? > > A combination of the two sounds best to me. Use `notifyFinish` for now, > and file a ticket asking for a public version of `_disconnected`. When > that's done and has been released for long enough, Nevow can switch (if > anyone cares enough to do it - presumably the only reason anyone would > care is that using `notifyFinish` might add a miniscule additional > amount of per-request overhead). In that case, I have a patch (attached). You also mentioned that handleSegment would need fixing: under what circumstances does that go wrong? Peter. _______________________________________________ Twisted-web mailing list [email protected] http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web
avoid-request-finish-error.patch
(application/octet-stream, 2.1 KB)
Index: nevow/test/test_appserver.py
===================================================================
--- nevow/test/test_appserver.py (revision 18026)
+++ nevow/test/test_appserver.py (working copy)
@@ -94,6 +94,7 @@
lambda : self.fail(),
asserterr)
+from twisted.internet import defer
class TestSiteAndRequest(testutil.TestCase):
def renderResource(self, resource, path):
@@ -130,6 +131,19 @@
return self.renderResource(Res1(), 'bar').addCallback(
lambda result: self.assertEquals(result, 'world'))
+ def test_connectionLost(self):
+ d = defer.Deferred()
+ class Res(Render):
+ def renderHTTP(self, ctx):
+ return d
+ s = appserver.NevowSite(Res())
+ r = appserver.NevowRequest(testutil.FakeChannel(s), True)
+ r.path = 'boo'
+ r.process()
+ r.connectionLost(Exception('Just Testing'))
+ d.callback('finished')
+
+
from twisted.internet import protocol, address
class FakeTransport(protocol.FileWrapper):
Index: nevow/appserver.py
===================================================================
--- nevow/appserver.py (revision 18026)
+++ nevow/appserver.py (working copy)
@@ -120,7 +120,13 @@
def __init__(self, *args, **kw):
server.Request.__init__(self, *args, **kw)
tpc.Componentized.__init__(self)
+ self._lostConnection = False
+ def flagLostConnection(err):
+ self._lostConnection = True
+
+ self.notifyFinish().addErrback(flagLostConnection)
+
def process(self):
# extra request parsing
if self.method == 'POST':
@@ -173,10 +179,13 @@
self.deferred.callback("")
def finishRequest( self, success ):
- server.Request.finish(self)
+ if not self._lostConnection:
+ server.Request.finish(self)
def _cbFinishRender(self, html, ctx):
- if isinstance(html, str):
+ if self._lostConnection:
+ pass
+ elif isinstance(html, str):
self.write(html)
self.finishRequest( True )
elif html is errorMarker: