Example #1
0
 def test_emptyPostPath(self):
     """
     If more path segments are consumed than remain in the request's
     I{postpath}, L{NevowSite.handleSegment} should silently not update
     I{prepath}.
     """
     request = FakeRequest(currentSegments=('',))
     context = RequestContext(tag=request)
     rootResource = Page()
     childResource = Page()
     site = NevowSite(rootResource)
     result = site.handleSegment(
         (childResource, ()), request, ('foo', 'bar'), context)
     self.assertEqual(request.prepath, [''])
     self.assertEqual(request.postpath, [])
Example #2
0
 def test_emptyPostPath(self):
     """
     If more path segments are consumed than remain in the request's
     I{postpath}, L{NevowSite.handleSegment} should silently not update
     I{prepath}.
     """
     request = FakeRequest(currentSegments=('', ))
     context = RequestContext(tag=request)
     rootResource = Page()
     childResource = Page()
     site = NevowSite(rootResource)
     result = site.handleSegment((childResource, ()), request,
                                 ('foo', 'bar'), context)
     self.assertEqual(request.prepath, [''])
     self.assertEqual(request.postpath, [])
Example #3
0
def makeService(options):
    """
    @type options: C{dict}

    @param options: Configuration for the NevowSite to start.  Required
    keys are::

        C{'element'}: a LiveElement or LiveFragment instance.

        C{'port'}: an C{int} giving the port number to which to bind.

    """
    element = options['element']
    page = WidgetPluginRoot(element)
    return TCPServer(options['port'], NevowSite(page))
Example #4
0
def run():
    """
    Parse nit options from the command line and start a nit server.
    """
    config = NitOptions()
    try:
        config.parseOptions()
    except UsageError as ue:
        raise SystemExit("%s: %s" % (sys.argv[0], ue))
    else:
        if not config['testmodules']:
            raise SystemExit("Specify at least one module name to test")
        startLogging(sys.stdout)
        suite = _getSuite(config['testmodules'])
        site = NevowSite(TestFrameworkRoot(suite))
        reactor.listenTCP(config['port'], site)
        reactor.run()
Example #5
0
def _getSuite(modules):
    """
    Given an iterable of Python modules, return a nit test suite which
    contains all the tests in those modules.
    """
    loader = TestLoader()
    suite = TestSuite('root')
    for module in modules:
        suite.addTest(loader.loadByName(module, True))
    return suite


def run():
    """
    Parse nit options from the command line and start a nit server.
    """
    config = NitOptions()
    try:
        config.parseOptions()
    except UsageError, ue:
        raise SystemExit("%s: %s" % (sys.argv[0], ue))
    else:
        if not config['testmodules']:
            raise SystemExit("Specify at least one module name to test")
        startLogging(sys.stdout)
        suite = _getSuite(config['testmodules'])
        site = NevowSite(TestFrameworkRoot(suite))
        reactor.listenTCP(config['port'], site)
        reactor.run()
Example #6
0
 def __init__(self, store, *a, **kw):
     NevowSite.__init__(self, *a, **kw)
     self.store = store
     self.requestFactory = lambda *a, **kw: AxiomRequest(self.store, *a, **kw)
Example #7
0
        else:
            self.client.send(
                livepage.set('status', "%d%% — %s" % (percent, summary)))


# This only properly works with one client (the last one to load the
# page). To work with multiples, we'd have to track all clients so
# sending async updates to them worked properly.
top_level = TorPage()

# minimal Tor configuration
config = txtorcon.TorConfig()
config.OrPort = 1234
config.SocksPort = 9999

# launch a Tor based on the above config; the callback will trigger
# when the TorControlProtocol and TorState instances are up and
# running (i.e. Tor process is launched, and we connected to it via
# control protocol and bootstrapped our notion of its state).
d = txtorcon.launch_tor(config, reactor, progress_updates=top_level.tor_update)
d.addCallback(top_level.set_tor_state)
d.addErrback(setup_failed)

print "Launching Tor and providing a Web interface on: \nhttp://localhost:8080\n"

# Start up the Web server
site = NevowSite(top_level)
reactor.listenTCP(8080, site)
reactor.run()
Example #8
0
def main():
    log.startLogging(sys.stdout)
    site = NevowSite(CalculatorParentPage(calc=Calculator()))
    reactor.listenTCP(8080, site)
    reactor.run()
Example #9
0

class GraphPage(rend.Page):
    addSlash = True
    docFactory = loaders.xmlfile("templates/graph.html")

    def render_graphs(self, ctx, data):
        for uri, label, filename in sorted(subgraphs(literalToday()),
                                           key=lambda (u, l, f): l):
            filename = filename[len("graph/"):]
            yield T.li[T.a(href=filename)[label], " ",
                       T.a(href=[filename, "?type=n3"])[T.code["[N3/text]"]]]

    def locateChild(self, ctx, segments):
        if segments == ('all', ):
            g = allGraphs(literalToday())
            return RdfXMLPage(g.serialize(format='xml')), []

        print segments
        # limiting to today's data only because it was easier to code quickly
        if len(segments) == 2 and segments[0] == str(
                literalToday()) and segments[1].isalnum():
            return RdfXMLPage(readSubgraphXML("graph/%s/%s" %
                                              segments[:2])), []
        return rend.Page.locateChild(self, ctx, segments)


tlog.startLogging(sys.stdout)
reactor.listenTCP(8008, NevowSite(Main()))
reactor.run()
Example #10
0
        self.fragment = fragment
        self.element = element

    def child_fragment(self, ctx):
        return Page(docFactory=stan(self.fragment))

    def child_element(self, ctx):
        return Page(docFactory=stan(self.element))


class Root(Page):
    def child_static(self, ctx):
        return Compare(StaticFragment(), StaticElement())

    def child_tiny(self, ctx):
        return Compare(TinyFragment(), TinyElement())

    def child_huge(self, ctx):
        return Compare(HugeFragment(), HugeElement())

    def child_nested(self, ctx):
        return Compare(NestedFragment(), NestedElement())

    def child_deferred(self, ctx):
        return Compare(DeferredFragment(), DeferredElement())


if __name__ == '__main__':
    reactor.listenTCP(8080, NevowSite(Root()))
    reactor.run()
Example #11
0
                            end=formatdate(t2),
                            isDuration='true',
                            title='hi')['heater on for %.1f min' %
                                        ((t2 - t1) / 60)]

            docFactory = loaders.stan(T.Tag('data')[render_events])

        return Ret()

    def child_tempchart(self, ctx):
        return static.File("tempchart")

    def child_flot(self, ctx):
        return static.File("flot")

    def child_www(self, ctx):
        return static.File("www")

    def child_dpms(self, ctx):
        import report.dpms
        reload(report.dpms)
        return report.dpms.Report()


twisted.python.log.startLogging(sys.stdout)
reactor.listenTCP(8007 + (len(sys.argv) > 1), NevowSite(Main()))

dispatcher.connect(dataIn, 'temps')

reactor.run()
Example #12
0
from tsload.web import webappPath
from tsload.web.main import MainPage, AboutPage
from tsload.web.login import LoginPage, LogoutPage
from tsload.web.agent import AgentPage
from tsload.web.profile import ProfilePage

main = MainPage()

# Static directories
main.putChild('bootstrap', File(webappPath('bootstrap')))
main.putChild('css', File(webappPath('css')))
main.putChild('js', File(webappPath('js')))
main.putChild('images', File(webappPath('images')))

# Pages
main.putChild('about', AboutPage())
main.putChild('login', LoginPage())
main.putChild('logout', LogoutPage())

main.putChild('agent', AgentPage())
main.putChild('profile', ProfilePage())

site = NevowSite(main, logPath=config.get('logging', 'logaccess'))

port = config.getInt('tsweb', 'port')
logging.getLogger('__main__').info(
    'Starting TSLoad Web Console instance at http port %d...' % port)

reactor.listenTCP(port, site)
reactor.run()