added pli.structdoc experimental module for reference and as a starting point.
[p2pB.git] / pli-structdoc / test_srv.py
blob92faba99673dcfa536c2b58735ec75a95ed23aa8
1 #=======================================================================
3 __version__ = '''0.0.01'''
4 __sub_version__ = '''20080307035538'''
5 __copyright__ = '''(c) Alex A. Naanou 2008'''
8 #-----------------------------------------------------------------------
10 from twisted.web import server, resource
11 from twisted.internet import reactor
13 from test_page import root
16 #-----------------------------------------------------------------------
18 # NOTE: set this to None to disable caching...
19 cache = {}
21 class Fetcher(resource.Resource):
22 isLeaf = True
24 def render_GET(self, request):
25 path = request.postpath[:]
26 format = 'html'
27 if path[-1] == 'general.css':
28 return file('test/general.css', 'r').read()
29 if path[-1].split('.')[-1] in ('html', 'rst', 'rawhtml'):
30 path[-1], format = path[-1].split('.')
31 cur = root
32 for p in path:
33 if p == '':
34 continue
35 cur = cur[p]
36 # do some caching...
37 # XXX this caching is brain-dead :)
38 if cache != None:
39 if (cur, format) in cache:
40 return cache[(cur, format)]
41 res = cache[(cur, format)] = getattr(cur, format)
42 return res
43 else:
44 return getattr(cur, format)
47 #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
49 site = server.Site(Fetcher())
50 reactor.listenTCP(8080, site)
51 reactor.run()
55 #=======================================================================
56 # vim:set ts=4 sw=4 nowrap :