Package toon :: Module rst
[hide private]
[frames] | no frames]

Source Code for Module toon.rst

 1  #!/usr/bin/env python 
 2  # 
 3  # Toonloop for Python 
 4  # 
 5  # Copyright 2008 Alexandre Quessy & Tristan Matthews 
 6  # http://toonloop.com 
 7  #  
 8  # Original idea by Alexandre Quessy 
 9  # http://alexandre.quessy.net 
10  # 
11  # Toonloop is free software: you can redistribute it and/or modify 
12  # it under the terms of the GNU General Public License as published by 
13  # the Free Software Foundation, either version 3 of the License, or 
14  # (at your option) any later version. 
15  # 
16  # Toonloop is distributed in the hope that it will be useful, 
17  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
18  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
19  # GNU General Public License for more details. 
20  # 
21  # You should have received a copy of the gnu general public license 
22  # along with Toonloop.  If not, see <http://www.gnu.org/licenses/>. 
23  # 
24  from twisted.web.resource import Resource 
25  from twisted.web import server 
26  from twisted.web import static 
27  from twisted.internet import reactor 
28   
29  from docutils.core import publish_string                                                                   
30   
31 -class ReStructured(Resource):
32 - def __init__(self, filename, *a):
33 self.rst = open(filename).read()
34
35 - def render(self, request):
36 return publish_string(self.rst, writer_name = 'html')
37 38 if __name__ == '__main__': 39 PORT = 8080 40 PATH = '.' 41 EXTENSION = '.rst' 42 resource = static.File(PATH) 43 resource.processors = {EXTENSION: ReStructured} 44 resource.indexNames = ['index' + EXTENSION] 45 reactor.listenTCP(PORT, server.Site(resource)) 46 reactor.run() 47