<br><br><div><span class="gmail_quote">On 2/22/06, <b class="gmail_sendername">Matt Helm</b> &lt;<a href="mailto:code.name.eric@gmail.com">code.name.eric@gmail.com</a>&gt; wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
On 2/21/06, Graeme Glass wrote:<br>&gt; Would you mind posting some sample code, for refrence?<br>&gt; Many thanks.<br><br>class Resource(resource.Resource):<br><br>&nbsp;&nbsp; def render(self, request):<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; def cheeto(r):
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; request.write(r.__str__())<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; request.finish()<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; def cherr(r):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; request.write(&quot;Bang!&quot;)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; request.write(str(r))<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; request.finish()<br><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; d_cheeto = threads.deferToThread(Template, file=&quot;alf.tmpl&quot;, searchList =<br> slist)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; d_cheeto.addCallback(cheeto)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; d_cheeto.addErrback(cherr)<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return server.NOT_DONE_YET<br>
<br>resource = Resource()<br><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">
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web</a><br></blockquote></div>webexp.py<br>
--------------------------------------------<br>
from twisted.application import internet, service<br>
from twisted.web import static, server, script<br>
import CheetahMapper<br>
<br>
root = static.File(&quot;./&quot;)<br>
root.indexNames=['index.cht']<br>
root.ignoreExt(&quot;.cht&quot;)<br>
root.processors = {'.cht': CheetahMapper.CheetahResource}<br>
application = service.Application('web')<br>
sc = service.IServiceCollection(application)<br>
site = server.Site(root)<br>
i = internet.TCPServer(8888, site)<br>
i.setServiceParent(sc)<br>
<br>
CheetahMapper.py<br>
------------------------------------------------<br>
from twisted.web import resource, server<br>
from Cheetah.Template import Template<br>
<br>
<br>
class CheetahResource(resource.Resource):<br>
&nbsp;&nbsp;&nbsp; isLeaf = 1<br>
<br>
&nbsp;&nbsp;&nbsp; def __init__(self, filename, registry):<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.filename = filename<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.registry = registry<br>
<br>
&nbsp;&nbsp;&nbsp; def render(self, request):<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; tmplt = Template.compile(file=self.filename)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; inst=tmplt()<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; request.write(str(inst))<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; request.finish()<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return server.NOT_DONE_YET<br>
<br>
time.cht<br>
------------------------------------------------------<br>
#import time<br>
&lt;html&gt;<br>
&lt;head&gt;<br>
&lt;title&gt;Time Example&lt;/title&gt;<br>
&lt;/head&gt;<br>
&lt;body&gt;<br>
It is $time.strftime(&quot;%I:%M %p&quot;).<br>
&lt;br&gt;<br>
Date is $time.strftime(&quot;%A, %B %D, %Y&quot;).<br>
&lt;/body&gt;<br>
&lt;/html&gt;<br>
-----------------------------------------------------------------------<br>
Not the best code in the world, but it has been useful for me for just throwing together quick pages and experimenting.<br>
<br>
ToddB<br>