[Twisted-Python] Newbie Q on 0.99 release

All: I have just started playing with twisted and have a few q: 1. What is the difference between web widgets and the DOM templates? 2. The 0.99 release notes indicates that ssh protocol is supported. Where can I find it? 3. The documentation says that the twisted.web can serve up rpy, html, cgi and php. Is there a PHP interpreter in twisted. thanks prabhakar

Prabhakar Chaganti wrote:
1. What is the difference between web widgets and the DOM templates?
DOMTemplate lets you do templating on a HTML file. Widgets generate HTML. Something like that :)
2. The 0.99 release notes indicates that ssh protocol is supported. Where can I find it?
twisted.conch.
3. The documentation says that the twisted.web can serve up rpy, html, cgi and php. Is there a PHP interpreter in twisted.
No, you need to have a PHP command-line interpreter installed (e.g. /usr/bin/php). In debian apt-get install php4-cgi.

On Thursday, August 22, 2002, at 06:57 AM, Prabhakar Chaganti wrote:
I'll spend a bit of time answering this since I wrote them :-) DOMTemplate is a class that parses an XHTML document looking for nodes with "view", "controller", "class", or "id" attributes. When it finds one, it looks for a "factory_foo" method to handle that node. (e.g. when it encounters the node <div id="coolStuff" />, the method factory_coolStuff would be called.) This method gets passed the request object and the current node object (as a DOM Node object). The return value of this method is then used to replace the node that was there before. Here is an example: from twisted.web.domtemplate import DOMTemplate from twisted.web import domwidgets class Foo(DOMTemplate): template = '<html><div id="foo" /> <div id="bar" /> <div id="baz" /></html>' def factory_foo(self, request, node): # I have been passed a DOM Node instance, I can mutate it and return it. # The main DOM Document instance (where the DOM factories are) # has been set to self.d node.appendChild(self.d.createTextNode("Hello world!")) return node def factory_bar(self, request, node): # Or, if I wish, I may simply return a string. It will be parsed into XML and # will replace the incoming node. return "<b>Hey, how are you doing?</b>" def factory_baz(self, request, node): # However, I may wish to use a higher level API that involves manipulating # Python objects instead of HTML. By using widgets, I can construct objects # to represent common HTML fragments, and never have to write any HTML # again! (Ok, so you'll have to write some eventually... but less) return domwidgets.Text("Hey, this is a very simple widget that knows how to turn itself into DOM text nodes using createTextNode") So you can see that DOMWidgets builds upon DOMTemplate by allowing you to use higher-level APIs in your DOMTemplate. Donovan

Prabhakar Chaganti wrote:
1. What is the difference between web widgets and the DOM templates?
DOMTemplate lets you do templating on a HTML file. Widgets generate HTML. Something like that :)
2. The 0.99 release notes indicates that ssh protocol is supported. Where can I find it?
twisted.conch.
3. The documentation says that the twisted.web can serve up rpy, html, cgi and php. Is there a PHP interpreter in twisted.
No, you need to have a PHP command-line interpreter installed (e.g. /usr/bin/php). In debian apt-get install php4-cgi.

On Thursday, August 22, 2002, at 06:57 AM, Prabhakar Chaganti wrote:
I'll spend a bit of time answering this since I wrote them :-) DOMTemplate is a class that parses an XHTML document looking for nodes with "view", "controller", "class", or "id" attributes. When it finds one, it looks for a "factory_foo" method to handle that node. (e.g. when it encounters the node <div id="coolStuff" />, the method factory_coolStuff would be called.) This method gets passed the request object and the current node object (as a DOM Node object). The return value of this method is then used to replace the node that was there before. Here is an example: from twisted.web.domtemplate import DOMTemplate from twisted.web import domwidgets class Foo(DOMTemplate): template = '<html><div id="foo" /> <div id="bar" /> <div id="baz" /></html>' def factory_foo(self, request, node): # I have been passed a DOM Node instance, I can mutate it and return it. # The main DOM Document instance (where the DOM factories are) # has been set to self.d node.appendChild(self.d.createTextNode("Hello world!")) return node def factory_bar(self, request, node): # Or, if I wish, I may simply return a string. It will be parsed into XML and # will replace the incoming node. return "<b>Hey, how are you doing?</b>" def factory_baz(self, request, node): # However, I may wish to use a higher level API that involves manipulating # Python objects instead of HTML. By using widgets, I can construct objects # to represent common HTML fragments, and never have to write any HTML # again! (Ok, so you'll have to write some eventually... but less) return domwidgets.Text("Hey, this is a very simple widget that knows how to turn itself into DOM text nodes using createTextNode") So you can see that DOMWidgets builds upon DOMTemplate by allowing you to use higher-level APIs in your DOMTemplate. Donovan
participants (3)
-
Donovan Preston
-
Itamar Shtull-Trauring
-
Prabhakar Chaganti