• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python loaders.htmlfile函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中nevow.loaders.htmlfile函数的典型用法代码示例。如果您正苦于以下问题:Python htmlfile函数的具体用法?Python htmlfile怎么用?Python htmlfile使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了htmlfile函数的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_reloadAfterPrecompile

    def test_reloadAfterPrecompile(self):
        """
        """
        # Get a filename
        temp = self.mktemp()

        # Write some content
        f = file(temp, 'w')
        f.write('<p>foo</p>')
        f.close()

        # Precompile the doc
        ctx = context.WovenContext()
        doc = loaders.htmlfile(temp)
        pc = flat.precompile(flat.flatten(doc), ctx)

        before = ''.join(flat.serialize(pc, ctx))


        # Write the file with different content and make sure the
        # timestamp changes
        f = file(temp, 'w')
        f.write('<p>bar</p>')
        f.close()
        os.utime(temp, (os.path.getatime(temp), os.path.getmtime(temp)+5))

        after = ''.join(flat.serialize(pc, ctx))

        self.assertIn('foo', before)
        self.assertIn('bar', after)
        self.failIfEqual(before, after)
开发者ID:StetHD,项目名称:nevow,代码行数:31,代码来源:test_loaders.py


示例2: nevowify

def nevowify(filename, linkrel, ext, url, templ, options=None, outfileGenerator=tree.getOutputFileName):
    if options is None:
        options = {}
    pclass = options['pageclass']
    pclass = reflect.namedObject(pclass)
    page = pclass(docFactory=loaders.htmlfile(filename))
    s = page.renderString()
    s = ____wait(s)

    newFilename = outfileGenerator(filename, ext)

    if options.has_key('nolore'):
        f = open(newFilename, 'w')
        f.write(s)
        f.close()
        return

    doc = parseStringAndReport(s)
    clonedNode = templ.cloneNode(1)
    tree.munge(doc, clonedNode, linkrel, os.path.dirname(filename), filename, ext,
               url, options, outfileGenerator)
    tree.makeSureDirectoryExists(newFilename)
    f = open(newFilename, 'wb')
    clonedNode.writexml(f)
    f.close()
开发者ID:AnthonyNystrom,项目名称:YoGoMee,代码行数:25,代码来源:nevowlore.py


示例3: test_docFactoryInStanTree

    def test_docFactoryInStanTree(self):

        class Page(rend.Page):

            def __init__(self, included):
                self.included = included
                rend.Page.__init__(self)

            def render_included(self, context, data):
                return self.included
            
            docFactory = loaders.stan(div[invisible(render=directive('included'))])

        doc = '<p>fum</p>'
        temp = self.mktemp()
        f = file(temp, 'w')
        f.write(doc)
        f.close()

        result = deferredRender(Page(loaders.stan(p['fee'])))
        self.assertEquals(result, '<div><p>fee</p></div>')
        result = deferredRender(Page(loaders.htmlstr('<p>fi</p>')))
        self.assertEquals(result, '<div><p>fi</p></div>')
        result = deferredRender(Page(loaders.xmlstr('<p>fo</p>')))
        self.assertEquals(result, '<div><p>fo</p></div>')
        result = deferredRender(Page(loaders.htmlfile(temp)))
        self.assertEquals(result, '<div><p>fum</p></div>')
        result = deferredRender(Page(loaders.xmlfile(temp)))
        self.assertEquals(result, '<div><p>fum</p></div>')
开发者ID:KatiaBorges,项目名称:exeLearning,代码行数:29,代码来源:test_rend.py


示例4: test_htmlfile

 def test_htmlfile(self):
     doc = '<ul id="nav"><li>a</li><li>b</li><li>c</li></ul>'
     temp = self.mktemp()
     f = file(temp, 'w')
     f.write(doc)
     f.close()
     df = loaders.htmlfile(temp)
     self.assertEquals(df.load()[0], doc)
开发者ID:StetHD,项目名称:nevow,代码行数:8,代码来源:test_loaders.py


示例5: test_htmlfile_slots

 def test_htmlfile_slots(self):
     doc = '<nevow:slot name="foo">Hi there</nevow:slot>'
     temp = self.mktemp()
     f = file(temp, 'w')
     f.write(doc)
     f.close()
     df = loaders.htmlfile(temp)
     self.assertEquals(df.load()[0].children, ['Hi there'])
开发者ID:StetHD,项目名称:nevow,代码行数:8,代码来源:test_loaders.py


示例6: test_patterns

    def test_patterns(self):
        temp = self.mktemp()
        setContent(temp, """<span nevow:render="foo">
			<span nevow:pattern="one">ONE</span>
			<span nevow:pattern="two">TWO</span>
			<span nevow:pattern="three">THREE</span>
		</span>""")

        class Mine(rend.Page):
            def render_foo(self, context, data):
                return context.tag.allPatterns(data)

        return defer.DeferredList([
            deferredRender(Mine("one", docFactory=loaders.htmlfile(temp))).addCallback(
            lambda result: self.assertEqual(result, '<span>ONE</span>')),
            deferredRender(Mine("two", docFactory=loaders.htmlfile(temp))).addCallback(
            lambda result: self.assertEqual(result, '<span>TWO</span>')),
            deferredRender(Mine("three", docFactory=loaders.htmlfile(temp))).addCallback(
            lambda result: self.assertEqual(result, '<span>THREE</span>'))
            ], fireOnOneErrback=True)
开发者ID:perkinslr,项目名称:nevow-py3,代码行数:20,代码来源:test_disktemplate.py


示例7: test_htmlFileInStanTree

    def test_htmlFileInStanTree(self):
        """
        Like L{test_htmlStringInStanTree}, but for an htmlfile loader.
        """
        doc = '<p>fum</p>'
        temp = self.mktemp()
        f = file(temp, 'w')
        f.write(doc)
        f.close()

        return self._testDocFactoryInStanTree(
            loaders.htmlfile(temp),
            '<p>fum</p>')
开发者ID:UstadMobile,项目名称:exelearning-ustadmobile-work,代码行数:13,代码来源:test_rend.py


示例8: test_diskTemplate

    def test_diskTemplate(self):
        temp = self.mktemp()
        open(temp, 'w').write("""<html>
    <head>
        <title nevow:data="theTitle" nevow:render="string">This is some template data!</title>
    </head>
    <body>
        <h3 nevow:data="theHead" nevow:render="string">This is a header</h3>
        <span nevow:data="someDummyText" nevow:render="replaceNode">This node will be replaced entirely (including the span)</span>
    </body>
</html>""")

        class TemplateRenderer(rend.Page):
            def data_theTitle(self, context, data):
                return "THE TITLE"

            def data_theHead(self, context, data):
                return "THE HEADER"

            def data_someDummyText(self, context, data):
                return "SOME DUMMY TEXT"

            def render_string(self, context, data):
                """The rule is, whatever a renderer returns *replaces* the node that came in
                so if we want this data to *fill* the node the directive was on, we have to
                do it explicitly
                """
                ## This could also be written as:
                # return context.tag.clear()[ data ]
                ## choose your poison
                tag = context.tag.clear()
                tag.children.append(data)
                return tag

            def render_replaceNode(self, context, data):
                """Render the current node by replacing whatever was there (including the
                node itself) with the current data.
                """
                return data

        tr = TemplateRenderer(docFactory=loaders.htmlfile(temp))

        result = deferredRender(tr)
        self.assertEquals(
            result, 
            '<html><head><title>THE TITLE</title></head><body><h3>THE HEADER</h3>SOME DUMMY TEXT</body></html>'
        )
开发者ID:KatiaBorges,项目名称:exeLearning,代码行数:47,代码来源:test_disktemplate.py


示例9: test_sequence

    def test_sequence(self):
        """Test case provided by mg
        """
        temp = self.mktemp()
        setContent(temp, """<ol nevow:data="aList" nevow:render="sequence"><li nevow:pattern="item" nevow:render="string"></li></ol>""")

        class TemplateRenderer(rend.Page):
            def data_aList(self,context,data):
                return ["one","two","three"]

        tr = TemplateRenderer(docFactory=loaders.htmlfile(temp))

        return deferredRender(tr).addCallback(
            lambda result:
            self.assertEqual(
            result, '<ol><li>one</li><li>two</li><li>three</li></ol>',
            "Whoops. We didn't get what we expected!"
            ))
开发者ID:perkinslr,项目名称:nevow-py3,代码行数:18,代码来源:test_disktemplate.py


示例10: render_content

 def render_content(self, context, data):
     tag = context.tag.clear()
     tag[loaders.htmlfile(templateDir='templates', template=self.contentTemplateFile)]
     return tag
开发者ID:StetHD,项目名称:nevow,代码行数:4,代码来源:pages.py


示例11: test_diskTemplate

 def test_diskTemplate(self):
     temp = self.mktemp()
     setContent(temp, self.xhtml)
     r = rend.Page(docFactory=loaders.htmlfile(temp))
     return deferredRender(r).addCallback(
         lambda result: self.assertEqual(result, self.xhtml))
开发者ID:perkinslr,项目名称:nevow-py3,代码行数:6,代码来源:test_disktemplate.py


示例12: render_contents

    def render_contents(self, ctx, data):
	return loaders.htmlfile(self.myhtmlfile)
开发者ID:ddblue,项目名称:projectX,代码行数:2,代码来源:rootcfg.py



注:本文中的nevow.loaders.htmlfile函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python loaders.stan函数代码示例发布时间:2022-05-27
下一篇:
Python livepage.js函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap