Hi David, I've been trying to the same thing :-)<div>although keeping the Resource part, which I like (especially because it automatically handles routing to children),</div><div>amongst many things.</div><div><br></div>
<div>Hope you'll like it too:</div><div><meta http-equiv="content-type" content="text/html; charset=utf-8"><a href="https://github.com/jacek99/corepost">https://github.com/jacek99/corepost</a></div><div><br></div><div>
Cheers,</div><div>Jacek<br><br><div class="gmail_quote">On Sun, Oct 2, 2011 at 4:49 PM, David J W <span dir="ltr"><<a href="mailto:twistedwebmailinglist@ominian.net">twistedwebmailinglist@ominian.net</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">Hello,<div> I've been using Twisted on and off now for about four years, mostly for personal projects and some R&D work for a few startups. I've been a semi-professional Python programmer for four years as well, unfortunately it only makes up about 15-20% of my annual income. That said for Python web development I was rather fond of Pylons and then moved from it to CherryPy. With those two frameworks influencing me, I wanted a similar interface for Twisted.Web and after a lot of trial and error I've got an alpha version proof of concept that is simply called txWeb. <a href="https://github.com/devdave/txWeb" target="_blank">https://github.com/devdave/txWeb</a></div>
<div><br></div><div>Very briefly using an example from JCalderone's wonderful collection of tutorial/examples:</div><div><a href="http://jcalderone.livejournal.com/49707.html" target="_blank">http://jcalderone.livejournal.com/49707.html</a></div>
<div><br></div><div>Instead of doing </div><div><br></div>from twisted.web.server import Site<br>from twisted.web.resource import Resource<br>from twisted.internet import reactor<div><br><div>class FormPage(Resource):</div>
<div> def render_GET(self, request)</div><div> return '<html><body><form method="POST"><input name="the-field" type="text" /></form></body></html>'</div>
<br> def render_POST(self, request):<br> return '<html><body>You submitted: %s</body></html>' % (cgi.escape(request.args["the-field"][0]),)<div><span style="font-family:monospace;font-size:12px;line-height:13px;white-space:pre-wrap;background-color:rgb(255, 255, 255)"><br>
</span></div><div><font face="monospace"><span style="font-size:12px;line-height:13px;white-space:pre-wrap"><br></span></font></div><div>root = Resource()</div><div>root.putChild("form", FormPage() )</div>
factory = Site(root)<br>reactor.listenTCP(8880, factory)<br>reactor.run()<div><br></div><div><br></div></div><div>the alternative would be: </div><div><br></div><div><div>from txweb.core import Site</div><div>#from twisted.web.resource import Resource</div>
<div>from twisted.internet import reactor</div><div>import cgi</div><div><br></div><div>class Root(object):</div><div> </div><div> </div><div> </div><div> def form(self, request):</div><div> return '<html><body><form action="/process" method="POST"><input name="the-field" type="text" /></form></body></html>' </div>
<div> form.exposed = True</div><div> </div><div> index = form</div><div> </div><div> def process(self, request):</div><div> return '<html><body>You submitted: %s</body></html>' % (cgi.escape(request.args["the-field"][0]),)</div>
<div> process.exposed = True</div><div><br></div><div>reactor.listenTCP(8880, Site(Root()))</div><div>reactor.run()</div></div><div><br></div><div><br></div><div>A cleaner version of the example above is available @ <a href="https://gist.github.com/1257921" target="_blank">https://gist.github.com/1257921</a></div>
<div><br></div><div>My goals with txWeb isn't to replace the twisted.web Resource mechanism but instead provide an alternative that friendlier towards those with experience with Pylons/CherryPy/Django while avoiding duplicating anything that twisted.web provides ( ex. File resources can be class attributes )</div>
<div><br></div><div><br></div><div>That all said, any critique's or constructive input is very much welcome. So far I know the unit-tests need to be cleaned up, inside the routing routeRequest method the wrapper OneTimeResource is created, used, and thrown away which is somewhat wasteful as its a mostly stateless object. But I'm not sure if I'm missing something big that could make txWeb unviable for production use without some sort of major refactoring.</div>
<div><br></div><div><br></div><div>Thanks,</div><div> David W.</div><font color="#888888"><div><br></div><div><br></div><div><br></div><div><br></div>
</font><br>_______________________________________________<br>
Twisted-web mailing list<br>
<a href="mailto:Twisted-web@twistedmatrix.com">Twisted-web@twistedmatrix.com</a><br>
<a href="http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web" target="_blank">http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web</a><br>
<br></blockquote></div><br></div>