Esempio n. 1
0
 def test_realDeferredSupport(self):
     doc = tags.html[tags.slot('foo'), tags.slot('foo')]
     doc.fillSlots('foo', defer.succeed(tags.span['Foo!!!']))
     self.r = rend.Page(docFactory=loaders.stan(doc))
     req = self.renderIt()
     self.assertEquals(
         req.v, '<html><span>Foo!!!</span><span>Foo!!!</span></html>')
Esempio n. 2
0
 def setUp(self):
     self.d = Deferred()
     self.d2 = Deferred()
     self.r = rend.Page(docFactory=loaders.stan(
         tags.html(data=self.data_later)[
             'Hello ', str, ' and '
             'goodbye ',str,
             tags.span(data=self.data_later2, render=str)]))
Esempio n. 3
0
 def setUp(self):
     self.d = Deferred()
     self.d2 = Deferred()
     self.r = rend.Page(docFactory=loaders.stan(
         html(
             data=self)['Hello ',
                        invisible[invisible[invisible[invisible[deferit]]]],
                        deferdot, ]))
Esempio n. 4
0
 def test_reusedDeferredSupport(self):
     """
     Two occurrences of a particular slot are each replaced with the
     result of the Deferred which is used to fill that slot.
     """
     doc = tags.html[
         tags.slot('foo'), tags.slot('foo')]
     doc.fillSlots('foo', defer.succeed(tags.span['Foo!!!']))
     self.r = rend.Page(docFactory=loaders.stan(doc))
     req = self.renderIt()
     self.assertEqual(req.v, '<html><span>Foo!!!</span><span>Foo!!!</span></html>')
Esempio n. 5
0
    def test_deferredProperty(self):
        class IDeferredProperty(formless.TypedInterface):
            d = formless.String()

        from nevow import util
        deferred = util.Deferred()
        deferred.callback('the default value')
        class Implementation(object):
            implements(IDeferredProperty)
            d = deferred

        return deferredRender(rend.Page(Implementation(), docFactory=loaders.stan(html[freeform.renderForms('original')]))).addCallback(
            lambda result: self.assertIn('value="the default value"', result))
Esempio n. 6
0
    def makePage(self, content):
        _ = i18n.Translator(translator=mockTranslator)
        page = rend.Page(
            docFactory=loaders.stan(tags.invisible(render=tags.directive('i18n'))[content]))
        page.render_i18n = i18n.render(_)
        doc = page.docFactory.load()
        ctx = context.WovenContext(context.PageContext(tag=page),
                                   tags.invisible[doc])
        page.rememberStuff(ctx)

        io = StringIO()
        writer = io.write

        def finisher(result):
            return io.getvalue()

        return page.flattenFactory(doc, ctx, writer, finisher)
Esempio n. 7
0
    def test_peopleMessageListRendering(self):
        mlister = MessageLister(store=self.substore)
        installOn(mlister, self.substore)

        p = Person(store=self.substore, name=u'Bob')

        EmailAddress(store=self.substore, person=p, address=u'bob@internet')

        for i in xrange(5):
            testMessageFactory(store=self.substore,
                               subject=unicode(str(i)),
                               receivedWhen=Time(),
                               spam=False,
                               sender=u'bob@internet')

        self.assertEqual(len(list(mlister.mostRecentMessages(p))), 5)
        return renderPage(
            rend.Page(docFactory=loaders.stan(MessageList(mlister, p))))
Esempio n. 8
0
 def test_diskTemplate(self):
     temp = self.mktemp()
     open(temp, 'w').write(self.xhtml)
     r = rend.Page(docFactory=loaders.htmlfile(temp))
     return deferredRender(r).addCallback(
         lambda result: self.assertEquals(result, self.xhtml))
Esempio n. 9
0
 def test_stringTemplate(self):
     r = rend.Page(docFactory=loaders.htmlstr(self.xhtml))
     return deferredRender(r).addCallback(
         lambda result: self.assertEquals(result, self.xhtml))
Esempio n. 10
0
 def test_diskTemplate(self):
     temp = self.mktemp()
     open(temp, 'w').write(self.xhtml)
     r = rend.Page(docFactory=loaders.htmlfile(temp))
     result = deferredRender(r)
     self.assertEquals(result, self.xhtml)
Esempio n. 11
0
    def test_simple(self):

        doc = div[p['foo'], p['bar']]
        result = rend.Page(docFactory=loaders.stan(doc)).renderSynchronously()
        self.assertEqual(result, '<div><p>foo</p><p>bar</p></div>')
Esempio n. 12
0
 def test_simple(self):
     doc = div[p['foo'], p['bar']]
     return rend.Page(docFactory=loaders.stan(
         doc)).renderString().addCallback(lambda result: self.assertEqual(
             result, '<div><p>foo</p><p>bar</p></div>'))
Esempio n. 13
0
 def speed(self, speed):
     return rend.Page(docFactory=loaders.stan(tags.html[tags.body(
         id='body')["Thanks for taking our survey! You said: %r %r %r" %
                    (self.original[0], self.original[1], speed)]]))
Esempio n. 14
0
 def render_inner(self, context, data):
     return rend.Page(docFactory=loaders.stan(div(id='inner')))
Esempio n. 15
0
 def child_refresh(self, ctx):
     self.collector.startExploration()
     p = rend.Page(docFactory=loaders.stan(T.p["Refresh started..."]))
     p.addSlash = True
     return p
Esempio n. 16
0
    def test_simple(self):

        doc = div[p['foo'], p['bar']]
        result = unittest.deferredResult(
            rend.Page(docFactory=loaders.stan(doc)).renderString())
        self.assertEquals(result, '<div><p>foo</p><p>bar</p></div>')
Esempio n. 17
0
def main(args):
    import cPickle
    options, args = parse_args(args)

    exitcode = 0

    if options.configfile:
        readConfigFile(options)

    try:
        # step 1: make/find the system
        if options.systemclass:
            systemclass = findClassFromDottedName(options.systemclass,
                                                  '--system-class')
            if not issubclass(systemclass, model.System):
                msg = "%s is not a subclass of model.System"
                error(msg, systemclass)
        else:
            systemclass = zopeinterface.ZopeInterfaceSystem

        if options.inputpickle:
            system = cPickle.load(open(options.inputpickle, 'rb'))
            if options.systemclass:
                if type(system) is not systemclass:
                    cls = type(system)
                    msg = ("loaded pickle has class %s.%s, differing "
                           "from explicitly requested %s")
                    error(msg, cls.__module__, cls.__name__,
                          options.systemclass)
        else:
            system = systemclass()

        system.options = options

        system.urlprefix = ''
        if options.moresystems:
            moresystems = []
            for fnamepref in options.moresystems:
                fname, prefix = fnamepref.split(':', 1)
                moresystems.append(cPickle.load(open(fname, 'rb')))
                moresystems[-1].urlprefix = prefix
                moresystems[-1].options = system.options
                moresystems[-1].subsystems.append(system)
            system.moresystems = moresystems
        system.sourcebase = options.htmlsourcebase

        if options.abbrevmapping:
            for thing in options.abbrevmapping.split(','):
                k, v = thing.split('=')
                system.abbrevmapping[k] = v

        # step 1.5: check that we're actually going to accomplish something here

        if options.auto:
            options.server = True
            options.edit = True
            for fn in os.listdir('.'):
                if os.path.isdir(fn) and \
                   os.path.exists(os.path.join(fn, '__init__.py')):
                    options.packages.append(fn)
                elif fn.endswith('.py') and fn != 'setup.py':
                    options.modules.append(fn)

        args = list(args) + options.modules + options.packages

        if options.makehtml == MAKE_HTML_DEFAULT:
            if not options.outputpickle and not options.testing \
                   and not options.server:
                options.makehtml = True
            else:
                options.makehtml = False

        # step 2: add any packages and modules

        if args:
            prependedpackage = None
            if options.prependedpackage:
                for m in options.prependedpackage.split('.'):
                    prependedpackage = system.Package(system, m, None,
                                                      prependedpackage)
                    system.addObject(prependedpackage)
                    initmodule = system.Module(system, '__init__', None,
                                               prependedpackage)
                    system.addObject(initmodule)
            for path in args:
                path = os.path.abspath(path)
                if path in system.packages:
                    continue
                if os.path.isdir(path):
                    system.msg('addPackage', 'adding directory ' + path)
                    system.addPackage(path, prependedpackage)
                else:
                    system.msg('addModuleFromPath', 'adding module ' + path)
                    system.addModuleFromPath(prependedpackage, path)
                system.packages.append(path)

        # step 3: move the system to the desired state

        if not system.packages:
            error("The system does not contain any code, did you "
                  "forget an --add-package?")

        system.process()

        if system.options.livecheck:
            error("write this")

        if system.options.projectname is None:
            name = '/'.join([ro.name for ro in system.rootobjects])
            system.msg('warning',
                       'WARNING: guessing ' + name + ' for project name',
                       thresh=-1)
            system.guessedprojectname = name

        # step 4: save the system, if desired

        if options.outputpickle:
            system.msg('', 'saving output pickle to ' + options.outputpickle)
            del system.options  # don't persist the options
            f = open(options.outputpickle, 'wb')
            cPickle.dump(system, f, cPickle.HIGHEST_PROTOCOL)
            f.close()
            system.options = options

        # step 5: make html, if desired

        if options.makehtml:
            if options.htmlwriter:
                writerclass = findClassFromDottedName(options.htmlwriter,
                                                      '--html-writer')
            else:
                from pydoctor import nevowhtml
                writerclass = nevowhtml.NevowWriter

            system.msg(
                'html', 'writing html to %s using %s.%s' %
                (options.htmloutput, writerclass.__module__,
                 writerclass.__name__))

            writer = writerclass(options.htmloutput)
            writer.system = system
            writer.prepOutputDirectory()

            system.epytextproblems = []

            if options.htmlsubjects:
                subjects = []
                for fn in options.htmlsubjects:
                    subjects.append(system.allobjects[fn])
            elif options.htmlsummarypages:
                writer.writeModuleIndex(system)
                subjects = []
            else:
                writer.writeModuleIndex(system)
                subjects = system.rootobjects
            writer.writeIndividualFiles(subjects, options.htmlfunctionpages)
            if system.epytextproblems:

                def p(msg):
                    system.msg(('epytext', 'epytext-summary'),
                               msg,
                               thresh=-1,
                               topthresh=1)

                p("these %s objects' docstrings are not proper epytext:" %
                  (len(system.epytextproblems), ))
                exitcode = 2
                for fn in system.epytextproblems:
                    p('    ' + fn)
            if options.outputpickle:
                system.msg('',
                           'saving output pickle to ' + options.outputpickle)
                # save again, with epytextproblems
                del system.options  # don't persist the options
                f = open(options.outputpickle, 'wb')
                cPickle.dump(system, f, cPickle.HIGHEST_PROTOCOL)
                f.close()
                system.options = options

        # Finally, if we should serve html, lets serve some html.
        if options.server:
            from pydoctor.server import (EditingPyDoctorResource,
                                         PyDoctorResource)
            from pydoctor.epydoc2stan import doc2html
            from nevow import appserver
            from twisted.internet import reactor
            if options.edit:
                if not options.nocheck:
                    system.msg("server", "Checking formatting of docstrings.")
                    included_obs = [
                        ob for ob in system.orderedallobjects if ob.isVisible
                    ]
                    for i, ob in enumerate(included_obs):
                        system.progress(
                            "server", i + 1, len(included_obs),
                            "docstrings checked, found %s problems" %
                            (len(system.epytextproblems)))
                        doc2html(ob, docstring=ob.docstring)
                root = EditingPyDoctorResource(system)
            else:
                root = PyDoctorResource(system)
            if options.facing_path:
                options.local_only = True
                from nevow import rend, vhost
                realroot = rend.Page()
                cur = realroot
                realroot.putChild('vhost', vhost.VHostMonsterResource())
                segments = options.facing_path.split('/')
                for segment in segments[:-1]:
                    next = rend.Page()
                    cur.putChild(segment, next)
                    cur = next
                cur.putChild(segments[-1], root)
                root = realroot
            system.msg(
                "server", "Setting up server at http://localhost:%d/" %
                options.server_port)
            if options.auto:

                def wb_open():
                    import webbrowser
                    webbrowser.open('http://localhost:%d/' %
                                    options.server_port)

                reactor.callWhenRunning(wb_open)
            from twisted.python import log
            log.startLogging(sys.stdout)
            site = appserver.NevowSite(root)
            if options.local_only:
                interface = 'localhost'
            else:
                interface = ''
            reactor.listenTCP(options.server_port, site, interface=interface)
            reactor.run()
    except:
        if options.pdb:
            import pdb
            pdb.post_mortem(sys.exc_traceback)
        raise
    return exitcode
Esempio n. 18
0
 def test_stringTemplate(self):
     r = rend.Page(docFactory=loaders.htmlstr(self.xhtml))
     result = deferredRender(r)
     self.assertEquals(result, self.xhtml)
Esempio n. 19
0
 def test_simple(self):
     xhtml = '<ul id="nav"><li>one</li><li>two</li><li>three</li></ul>'
     r = rend.Page(docFactory=loaders.htmlstr(xhtml))
     return deferredRender(r).addCallback(
         lambda result: self.assertEqual(result, xhtml))
Esempio n. 20
0
 def test_simple(self):
     xhtml = '<ul id="nav"><li>one</li><li>two</li><li>three</li></ul>'
     r = rend.Page(docFactory=loaders.htmlstr(xhtml))
     result = deferredRender(r)
     self.assertEquals(result, xhtml)
Esempio n. 21
0
 def child_postTarget(self, ctx):
     return rend.Page(
         docFactory=loaders.stan(
             tags.html[tags.body(id="body")[str(ctx.arg('blah'))]]))