本文整理汇总了Python中nevow.loaders.xmlfile函数的典型用法代码示例。如果您正苦于以下问题:Python xmlfile函数的具体用法?Python xmlfile怎么用?Python xmlfile使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了xmlfile函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: template
def template(templatename, pattern=None):
"""
Load XML template
"""
return loaders.xmlfile(templatename,
templateDir=config.TEMPLATE_PATH,
pattern=pattern)
示例2: __init__
def __init__(self, original, ctx, factory):
self.factory = factory
self.user = self.factory.getUser(original)
rend.Page.__init__(self, original)
r = manager.ResourceManager()
UserAdmin.docFactory = loaders.xmlfile( r["resources"]["web"]["user_admin.html"] )
示例3: render_content
def render_content(self, ctx, data):
role = self.getRole(ctx)
if role == 0:
return self.renderAlert('You are not authorized')
return loaders.xmlfile(webappPath('agent/index.html'))
示例4: getDocFactory
def getDocFactory(self, fragmentName, default=None):
"""
For a given fragment, return a loaded Nevow template.
@param fragmentName: the name of the template (can include relative
paths).
@param default: a default loader; only used if provided and the
given fragment name cannot be resolved.
@return: A loaded Nevow template.
@type return: L{nevow.loaders.xmlfile}
"""
if fragmentName in self.cachedLoaders:
return self.cachedLoaders[fragmentName]
segments = fragmentName.split('/')
segments[-1] += '.html'
file = self.directory
for segment in segments:
file = file.child(segment)
if file.exists():
loader = xmlfile(file.path)
self.cachedLoaders[fragmentName] = loader
return loader
return default
示例5: 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>')
示例6: macro_content
def macro_content(self, ctx):
return t.invisible[
t.p["This macro has been called ",
next(counter2)+1,
" time(s)"],
loaders.xmlfile(util.sibpath(__file__,'child_macro.html'), ignoreDocType=True).load()
]
示例7: __init__
def __init__(self, parent, package=None, webServer=None, name=None):
"""
Pass me a 'parent' rendering component,
a 'package' that I'm rendering for
and a 'webServer' instance reference (from webServer.py)
If you don't pass 'webServer' and 'package' I'll
get them from 'parent'
'name' is a identifier to distuniguish us from the other children of our
parent
"""
self.parent = parent # This is the same for both blocks and pages
if name:
self.name = name
elif not self.name:
raise AssertionError('Element of class "%s" created with no name.' %
self.__class__.__name__)
# Make pylint happy. These attributes will be gotten from
# self.application
self.config = Unset
self.ideviceStore = Unset
self.packageStore = Unset
# Overwrite old instances with same name
if parent:
parent.renderChildren[self.name] = self
self.renderChildren = {}
if package:
self.package = package
elif parent:
self.package = parent.package
else:
self.package = None
if webServer:
self.webServer = webServer
elif parent:
self.webServer = parent.webServer
else:
self.webServer = None
if self._templateFileName:
if hasattr(self, 'config') and self.config:
pth = self.config.webDir/'templates'/self._templateFileName
self.docFactory = loaders.xmlfile(pth)
else:
# Assume directory is included in the filename
self.docFactory = loaders.xmlfile(self._templateFileName)
示例8: test_xmlfile
def test_xmlfile(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.xmlfile(temp)
self.assertEquals(df.load()[0], doc)
示例9: __init__
def __init__(self, original, options=None, otherOption=None):
self.original = original
if options is not None:
self.options = options
if otherOption is not None:
self.otherOption = otherOption
if self.template is None:
self.template = loaders.xmlfile(util.resource_filename('formal',
'html/SelectOtherChoice.html'))
示例10: __init__
def __init__(self, *args, **kwargs):
zoto_base_page.__init__(self, *args, **kwargs)
self.album_id = -1
self.offset = 0
self.username = args[0]
self.album_id = args[1]
self.can_view = False
self.docFactory = loaders.xmlfile(os.path.join(self.tpl_path, "album_template.xml"))
self.template_path = "%s/album_templates" % aztk_config.setup.get("paths", "web")
示例11: test_xmlfilePreprocessors
def test_xmlfilePreprocessors(self):
"""
Test that the xmlstr loader properly passes uncompiled documents to
preprocessors it is given.
"""
xmlFile = self.mktemp()
f = file(xmlFile, 'w')
f.write('<div><span>Hello</span><span>world</span></div>')
f.close()
factory = loaders.xmlfile(xmlFile)
return self._preprocessorTest(factory)
示例12: run
def run(self):
kwargs = {}
template = self.get('template', None)
if template is not None:
kwargs['docFactory'] = loaders.xmlfile(template)
feed = readFeed(self.path)
a = Atom(feed, **kwargs)
d = a.renderString()
d.addCallback(self._print)
return d
示例13: getfiles
def getfiles(self,nodes):
for node in nodes:
if len(node) == 4:
self.getfiles(node[3])
try:
newpage = rend.Page()
newpage.docFactory = loaders.xmlfile(node[2],templateDir='apidoc')
except Exception,e:
pass
else:
self.children[node[1]] = newpage
示例14: getHtml
def getHtml(yamlfile, countItems, template):
ydata = list(yaml.loadFile(yamlfile))[0]
Page.docFactory = loaders.xmlfile(template)
d = Page(ydata, countItems).renderString()
output = []
d.addCallback(cb, output)
d.addErrback(eb)
reactor.run()
return output[0]
示例15: test_xmlFileInStanTree
def test_xmlFileInStanTree(self):
"""
Like L{test_htmlStringInStanTree}, but for an xmlfile loader.
"""
doc = '<p>I</p>'
temp = self.mktemp()
f = file(temp, 'w')
f.write(doc)
f.close()
return self._testDocFactoryInStanTree(
loaders.xmlfile(temp),
'<p>I</p>')