本文整理汇总了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)
示例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()
示例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>')
示例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)
示例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'])
示例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)
示例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>')
示例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>'
)
示例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!"
))
示例10: render_content
def render_content(self, context, data):
tag = context.tag.clear()
tag[loaders.htmlfile(templateDir='templates', template=self.contentTemplateFile)]
return tag
示例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))
示例12: render_contents
def render_contents(self, ctx, data):
return loaders.htmlfile(self.myhtmlfile)