File: simplehtml.tac

package info (click to toggle)
nevow 0.3.0-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 940 kB
  • ctags: 2,089
  • sloc: python: 8,635; makefile: 15
file content (32 lines) | stat: -rw-r--r-- 1,008 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from twisted.application import service
from twisted.application import internet

from nevow import appserver
from nevow import inevow
from nevow import loaders
from nevow import rend
from nevow.stan import directive

class Simple(rend.Page):    

    docFactory = loaders.xmlfile('simplehtml.html')

    def render_theTitle(self, context, data):
        return context.tag["Welcome to Nevow world"]
    
    def render_sample(self, context, data):
        request = inevow.IRequest(context)
        session = inevow.ISession(context)
        count = getattr(session, 'count', 1)
        session.count = count + 1
        greeting = ["Welcome, person from ", request.client[1], "! You are using ", 
                        request.getHeader('user-agent'), " and have been here ", str(count), " times."]
        return context.tag[''.join(greeting)]
    
application = service.Application("simple")
internet.TCPServer(
    8080, 
    appserver.NevowSite(
        Simple()
    )
).setServiceParent(application)