本文整理汇总了Python中nevow.loaders.xmlstr函数的典型用法代码示例。如果您正苦于以下问题:Python xmlstr函数的具体用法?Python xmlstr怎么用?Python xmlstr使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了xmlstr函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testXML
def testXML(self):
t = '<a xmlns:n="http://nevow.com/ns/nevow/0.1" href="#"><n:attr name="href">href</n:attr>label</a>'
result = flat.flatten(loaders.xmlstr(t).load())
self.assertEqual(result, '<a href="href">label</a>')
t = '<a xmlns:n="http://nevow.com/ns/nevow/0.1" href="#"><n:attr name="href"><n:slot name="href"/></n:attr>label</a>'
ctx = context.WovenContext()
ctx.fillSlots('href', 'href')
result = flat.flatten(flat.precompile(loaders.xmlstr(t).load()), ctx)
self.assertEqual(result, '<a href="href">label</a>')
示例2: test_reusedDocFactory
def test_reusedDocFactory(self):
"""
Test that a docFactory which is used more than once behaves properly
both times.
"""
class Page(rend.Page):
docFactory = loaders.stan(div[invisible(render=directive('included'))])
def __init__(self, included):
self.included = included
rend.Page.__init__(self)
def render_included(self, context, data):
return self.included
p1 = Page(loaders.stan('first'))
p2 = Page(loaders.xmlstr('<p>second</p>'))
d = deferredRender(p1)
def rendered(result):
self.assertEqual(result, '<div>first</div>')
return deferredRender(p2)
d.addCallback(rendered)
def renderedAgain(result):
self.assertEqual(result, '<div><p>second</p></div>')
d.addCallback(renderedAgain)
return d
示例3: _xml2ReSTFragment
def _xml2ReSTFragment(xml):
XML_TEMPLATE = """<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<div xmlns:n="http://nevow.com/ns/nevow/0.1" >%(xml)s</div>"""
xml = XML_TEMPLATE%{'xml':xml}
return ReSTFragment(docFactory=loaders.xmlstr( xml, ignoreDocType=True))
示例4: 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>')
示例5: test_xmlStringInStanTree
def test_xmlStringInStanTree(self):
"""
Like L{test_htmlStringInStanTree}, but for an xmlstr loader.
"""
return self._testDocFactoryInStanTree(
loaders.xmlstr('<p>fo</p>'),
'<p>fo</p>')
示例6: test_simpleXHTMLRendering
def test_simpleXHTMLRendering(self):
"""
Test that a Element with a simple, static xhtml document factory
renders correctly.
"""
f = Element(docFactory=xmlstr("<p>Hello, world.</p>"))
return self._render(f).addCallback(
self.assertEqual, "<p>Hello, world.</p>")
示例7: test_xmlstrPreprocessors
def test_xmlstrPreprocessors(self):
"""
Test that the xmlstr loader properly passes uncompiled documents to
preprocessors it is given.
"""
factory = loaders.xmlstr(
'<div><span>Hello</span><span>world</span></div>')
return self._preprocessorTest(factory)
示例8: test_missingSpace
def test_missingSpace(self):
doc = '<p xmlns:nevow="http://nevow.com/ns/nevow/0.1"><nevow:slot name="foo"/> <nevow:slot name="foo"/></p>'
## This used to say htmlstr, and this test failed because microdom ignores whitespace;
## This test passes fine using xmlstr. I am not going to fix this because microdom is too
## hard to fix. If you need this, switch to xmlstr.
result = loaders.xmlstr(doc).load()
# There should be a space between the two slots
self.assertEquals(result[2], ' ')
示例9: test_urlXmlAttrSlot
def test_urlXmlAttrSlot(self):
u = url.URL.fromString("http://localhost/").child(r"<c:\foo\bar&>")
tag = tags.invisible[
loaders.xmlstr(
'<img xmlns:n="http://nevow.com/ns/nevow/0.1" src="#"><n:attr name="src"><n:slot name="src"/></n:attr></img>'
)
]
tag.fillSlots("src", u)
self.assertEqual(flatten(tag), '<img src="http://localhost/%3Cc%3A%5Cfoo%5Cbar%26%3E" />')
示例10: __init__
def __init__(self, album_info, template_info):
self.album_info = album_info
self.template_info = template_info
self.image_count = album_info['per_page']
print "="*80
print "markup: \n%s" % self.template_info['markup']
print "="*80
self.markup = ""
self.docFactory = loaders.xmlstr(self.template_info['markup'])
self.data_images = []
示例11: test_urlintagwithmultipleamps
def test_urlintagwithmultipleamps(self):
"""
Test the serialization of an URL with an ampersand in it as an
attribute value.
The ampersand must be quoted for the attribute to be valid.
"""
tag = tags.invisible[tags.a(href=url.URL.fromString('http://localhost/').add('foo', 'bar').add('baz', 'spam'))]
self.assertEquals(flatten(tag), '<a href="http://localhost/?foo=bar&baz=spam"></a>')
tag = tags.invisible[loaders.xmlstr('<a xmlns:n="http://nevow.com/ns/nevow/0.1" href="#"><n:attr name="href"><n:slot name="href"/></n:attr></a>')]
tag.fillSlots('href', url.URL.fromString('http://localhost/').add('foo', 'bar').add('baz', 'spam'))
self.assertEquals(flatten(tag), '<a href="http://localhost/?foo=bar&baz=spam"></a>')
示例12: test_xmlSlotDefault
def test_xmlSlotDefault(self):
"""
An I{nevow:slot} tag in an XML template may have a I{default}
attribute specifying a value for the slot if it is not otherwise
given one.
"""
slotsdoc = '''
<div xmlns:nevow="http://nevow.com/ns/nevow/0.1">
<nevow:slot name="1" />
<nevow:slot name="2" default="3" />
</div>
'''
loader = loaders.xmlstr(slotsdoc)
loaded = loader.load()
self.assertEquals(loaded[1].default, None)
self.assertEquals(loaded[3].default, "3")
示例13:
FORM_LAYOUT = loaders.xmlstr(
"""<?xml version="1.0"?>
<form xmlns:n="http://nevow.com/ns/nevow/0.1" n:pattern="freeform-form">
<!-- Replace/fill the form attributes -->
<n:attr name="action"><n:slot name="form-action"/></n:attr>
<n:attr name="id"><n:slot name="form-id"/></n:attr>
<n:attr name="name"><n:slot name="form-name"/></n:attr>
<!-- General form information -->
<p><strong><n:slot name="form-label"/></strong></p>
<p><em><n:slot name="form-description"/></em></p>
<p><strong><em><n:slot name="form-error"/></em></strong></p>
<!-- Start of the form layout table -->
<table style="background: #eee; border: 1px solid #bbb; padding: 1em;" >
<!-- Mark location arguments will be added -->
<n:slot name="form-arguments"/>
<!-- General argument layout pattern -->
<n:invisible n:pattern="argument" n:render="remove">
<tr>
<th><n:slot name="label"/>:</th>
<td><n:slot name="input"/><span class="freeform-error"><n:slot name="error"/></span></td>
</tr>
<tr>
<th></th>
<td><n:slot name="description"/></td>
</tr>
</n:invisible>
<!-- Argument layout, just for fum -->
<n:invisible n:pattern="argument!!fo" n:render="remove">
<tr>
<th><n:slot name="label"/>:</th>
<td>
<textarea cols="40" rows="5"><n:attr name="id"><n:slot name="id"/></n:attr><n:attr name="name"><n:slot name="name"/></n:attr><n:slot name="value"/></textarea>
<span class="freeform-error"><n:slot name="error"/></span></td>
</tr>
<tr>
<th></th>
<td><n:slot name="description"/></td>
</tr>
</n:invisible>
<!-- Button row -->
<tr>
<td colspan="2">
<n:slot name="form-button"/>
</td>
</tr>
</table>
</form>
""").load()
示例14: test_xmlstr
def test_xmlstr(self):
doc = '<p>hello</p>'
self._withAndWithout(loaders.xmlstr(doc))
示例15: test_ignoreComment
def test_ignoreComment(self):
doc = '<!-- skip this --><p>Hello.</p>'
df = loaders.xmlstr(doc, ignoreComment=True)
self.assertEquals(flat.flatten(df), '<p>Hello.</p>')