File: examples.tac

package info (click to toggle)
nevow 0.9.31-3
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 2,804 kB
  • ctags: 4,921
  • sloc: python: 19,639; ansic: 136; sh: 53; xml: 42; makefile: 25; sql: 5
file content (189 lines) | stat: -rw-r--r-- 6,481 bytes parent folder | download | duplicates (2)
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
try:
    import zope.interface
except ImportError:
    print """ Please install ZopeInterface product from
    http://www.zope.org/Products/ZopeInterface/
to run Nevow """
    import sys
    sys.exit(1)


from twisted.python import components
import warnings
warnings.filterwarnings(
    'ignore',
    category=components.ComponentsDeprecationWarning)

from twisted.application import service, strports
from twisted.python import util

from nevow import inevow, rend, loaders, url, tags, appserver, static, guard, athena

import sys

try:
    from advanced_manualform import advanced_manualform
    from customform import customform
    from disktemplates import disktemplates
    from disktemplates import disktemplates_stan
    from simple import simple
    from simple import simplehtml
    from tree import tree
    from formpost import formpost2
    from formpost import formpost
    from children import children
    from children import childrenhtml
    from table import tablehtml
    from irenderer import irenderer
    from irenderer import simple_irenderer
    from formbuilder import formbuilder
    from db import db
    from hello import hellohtml
    from hello import hellostan
    from canvas import canvas
    from manualform import manualform
    from guarded import guarded
    from guarded import guarded2
    from xul import xul_nevow
    from liveanimal import liveanimal
    from most_basic import most_basic
    from http_auth import http_auth
    from logout_guard import logout_guard
    from logout_guard import logout_guard2
    from objcontainer import objcontainer
    from nestedsequence import nestedsequence
    from fragments import fragments
    from macros import macros
    from chatola import chatola
    from i18n import i18n, xmli18n
    from cal import cal
    from tabbed import tabbed
    from progress import progress
    from tests import testformless, testexamples
    from nevow import livetest

    from athenademo import calculator
    from athenademo import typeahead
    from athenademo import widgets
    from athenademo import benchmark
except ImportError, e:
    if str(e).find('No module named') != -1:
        msg = """
Original error message:
%s
=======================================
Please check the following things:
* You are not root
* You are running examples.tac from examples directory or examples
    directory is in the PYTHONPATH

A possible fix could be to run examples.tac with the following
command:
    PYTHONPATH=/path/to/examples/ twistd -noy examples.tac
=======================================
""" % str(e)
        raise Exception(msg)
    raise e
except AttributeError, e:
    if str(e).find("'module' object has no attribute") != -1:
        msg = """
Original error message:
%s
============================
Please check that nevow and formless are correctly installed
============================
""" % str(e)
        raise Exception(msg)
    raise e

class Sources(rend.Page):
    def __init__(self, path, _):
        rend.Page.__init__(self, path)

    def render_htmlizer(self, ctx, path):
        from twisted.python import htmlizer
        from StringIO import StringIO
        output = StringIO()
        try:
            htmlizer.filter(open(path), output, writer=htmlizer.SmallerHTMLWriter)
        except AttributeError:
            output = StringIO("""Starting after Nevow 0.4.1 Twisted
2.0 is a required dependency. Please install it""")
        return tags.xml(output.getvalue())

    docFactory = loaders.stan(
    tags.html[
        tags.head[
            tags.title["Python source file: ", str],
            tags.link(type='text/css', rel='stylesheet', href='/cssfile')],
        tags.body[
            render_htmlizer]])

import os
class Examples(rend.Page):
    addSlash = True ## This is a directory-like resource
    docFactory = loaders.xmlfile(os.path.abspath('.')+'/index.html')
    child_sources = static.File('.', defaultType='text/plain')
    child_sources.processors['.py'] = Sources
    child_sources.contentTypes = {}
    child_cssfile = static.File('index.css')
    children = dict(
        customform=customform.Root(),
        disktemplates=disktemplates.Mine(),
        disktemplates_stan=disktemplates_stan.Mine(),
        simple=simple.Simple(),
        simplehtml=simplehtml.Simple(),
        tree=tree.Tree('base', 'base'),
        formpost2=formpost2.FormPage(formpost2.Implementation()),
        formpost=formpost.FormPage(),
        children=children.RootPage(),
        childrenhtml=childrenhtml.RootPage(),
        tablehtml=tablehtml.Table(),
        irenderer=irenderer.Page(),
        simple_irenderer=simple_irenderer.Page(),
        formbuilder=formbuilder.FormBuilder(),
        db=db.DBBrowser(),
        hellohtml=hellohtml.Page(),
        hellostan=hellostan.Page(),
        canvas=canvas.createResource(),
        manualform=manualform.Page(),
        guarded=guarded.createResource(),
        guarded2=guarded2.createResource(),
        xul_nevow=xul_nevow.createResource(),
        advanced_manualform=advanced_manualform.Page(),
        liveanimal=liveanimal.createResource(),
        chatola=chatola.createResource(),
        http_auth=http_auth.AuthorizationRequired(),
        most_basic=most_basic.root,
        logout_guard=logout_guard.createResource(),
        logout_guard2=logout_guard2.createResource(),
        objcontainer=objcontainer.createResource(),
        nestedsequence=nestedsequence.Root(),
        i18n=i18n.createResource(),
        xmli18n=xmli18n.createResource(),
        calendar=cal.Calendar(),
        tabbed=tabbed.TabbedPage(),
        progress=progress.createResource(),
        tests=testexamples.createResource(),
        livetests=testexamples.createLiveSuite(),
        testtests=livetest.createResource(),
        testformless=testformless.NameWizard(),
        formless_redirector=testformless.Redirector(),
        formless_tests=testformless.formless_tests,
        fragments=fragments.Root(),
        macros=macros.Root(),
        typeahead=typeahead.DataEntry(),
        )

    def child_calculator(self, ctx):
        return calculator.CalculatorResource(calculator.ICalculator, calculator.Calculator())

    def child_widgets(self, ctx):
        return widgets.WidgetPage(None, None)

    def child_benchmark(self, ctx):
        return benchmark.Benchmark(400, 20)


application = service.Application("examples")
strports.service("8080", appserver.NevowSite(Examples())).setServiceParent(application)