本文整理汇总了Python中nevow.tags.slot函数的典型用法代码示例。如果您正苦于以下问题:Python slot函数的具体用法?Python slot怎么用?Python slot使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了slot函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: render
def render(self, ctx, key, args, errors):
if errors:
value = args.get(key,[None])[0]
else:
if args is not None:
value = iforms.IStringConvertible(self.original).fromType(args.get(key))
def render_node(ctx, data):
tag = ctx.tag
data = self.nodeInterface(data)
tag.fillSlots('value',data.value)
tag.fillSlots('label',data.label)
if str(data.value) == str(value):
tag = tag(checked='checked')
return tag
template = T.div()[
T.input(pattern='item', render=render_node, type='radio', name=key,
value=T.slot('value'))[
T.slot('label')
],
T.input(pattern='itemdisabled', render=render_node,
disabled="disabled", type='radio', name=key,
value=T.slot('value'))[
T.slot('label')
]
]
return T.invisible(data=self.tree, render=tree.render)[template]
示例2: test_blogsRenderer
def test_blogsRenderer(self):
"""
Test that L{hyperbola_view.BlogListFragment.blogs} renders a list of blogs.
"""
site = self.siteStore.findUnique(SiteConfiguration)
site.hostname = u'blogs.renderer'
blog1 = self._shareAndGetProxy(self._makeBlurb(FLAVOR.BLOG))
blog2 = self._shareAndGetProxy(self._makeBlurb(FLAVOR.BLOG))
blf = hyperbola_view.BlogListFragment(
athena.LivePage(), self.publicPresence)
blf.docFactory = loaders.stan(
tags.div(pattern='blog')[
tags.span[tags.slot('title')],
tags.span[tags.slot('link')],
tags.span[tags.slot('post-url')]])
tag = tags.invisible
markup = flat.flatten(tags.div[blf.blogs(None, tag)])
doc = minidom.parseString(markup)
blogNodes = doc.firstChild.getElementsByTagName('div')
self.assertEqual(len(blogNodes), 2)
for (blogNode, blog) in zip(blogNodes, (blog1, blog2)):
(title, blogURL, postURL) = blogNode.getElementsByTagName('span')
blogURL = blogURL.firstChild.nodeValue
expectedBlogURL = str(websharing.linkTo(blog))
self.assertEqual(blogURL, expectedBlogURL)
postURL = postURL.firstChild.nodeValue
self.assertEqual(
postURL, 'https://blogs.renderer' + expectedBlogURL + '/post')
示例3: test_precompiledSlotFilledWithSlot
def test_precompiledSlotFilledWithSlot(self):
"""
A L{_PrecompiledSlot} slot which is filled with another slot is
replaced with the value the other slot is filled with.
"""
tag = invisible[oldPrecompile(div[slot("foo")])]
tag.fillSlots("foo", slot("bar"))
tag.fillSlots("bar", '"&<>')
self.assertStringEqual(self.flatten(tag), '<div>"&<></div>')
示例4: test_deeplyNestedSlot
def test_deeplyNestedSlot(self):
"""
Flattening succeeds for an object with a level of slot nesting
significantly greater than the Python maximum recursion limit.
"""
tag = div()[slot("foo-0")]
for i in xrange(1000):
tag.fillSlots("foo-" + str(i), slot("foo-" + str(i + 1)))
tag.fillSlots("foo-1000", "bar")
self._nestingTest(tag, "<div>bar</div>")
示例5: _render
def _render(self, ctx, key, args, errors, value, tag):
def data_facets(ctx, data):
storeSession = util.getStoreSession(ctx)
avatar = util.getAvatar(ctx)
@defer.deferredGenerator
def loadCategories(facets):
d = defer.waitForDeferred(avatar.getCategoryManager(storeSession))
yield d
categories = d.getResult()
rv = []
for f in facets:
facetData = FacetData()
facetData.label = f[2]
facetData.textid = f[1]
rv.append(facetData)
d = defer.waitForDeferred(categories.loadCategories(facetData.textid))
yield d
facetData.tree = d.getResult().children
yield rv
d = avatar.getCategoryManager(storeSession)
d.addCallback(lambda categories: categories.loadFacets())
d.addCallback(loadCategories)
return d
def render_facet(ctx, data):
tag = ctx.tag
tag.fillSlots("facetlabel", data.label)
return tag
def render_node(ctx, data):
tag = ctx.tag
tag.fillSlots("value", data.path)
tag.fillSlots("label", data.label)
if data.path in value:
tag.children[0] = tag.children[0](checked="checked")
else:
tag.children[0](checked=None)
return tag
template = T.div(class_="categorieswidget")[
T.p(class_="opener")["click to open/close"],
T.ul(class_="panel", data=data_facets, render=rend.sequence)[
T.li(pattern="item", render=render_facet)[
T.slot("facetlabel"),
T.div(data=T.directive("tree"), render=tree.render)[
T.invisible(pattern="item", render=render_node)[tag, T.slot("label")]
],
]
],
]
return T.invisible()[template]
示例6: test_reusedDeferredSupport
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>')
示例7: test_slots
def test_slots(self):
tag = tags.html[
tags.body[
tags.table(data={'one': 1, 'two': 2}, render=rend.mapping)[
tags.tr[tags.td["Header one."], tags.td["Header two."]],
tags.tr[
tags.td["One: ", tags.slot("one")],
tags.td["Two: ", tags.slot("two")]
]
]
]
]
self.assertEqual(self.render(tag), "<html><body><table><tr><td>Header one.</td><td>Header two.</td></tr><tr><td>One: 1</td><td>Two: 2</td></tr></table></body></html>")
示例8: test_unfilledPrecompiledSlot
def test_unfilledPrecompiledSlot(self):
"""
Flattening a L{_PrecompiledSlot} for which no value has been supplied
results in an L{FlattenerError} exception.
"""
tag = oldPrecompile(div[slot("foo")])
self.assertRaises(FlattenerError, self.flatten, tag)
示例9: test_unfilledSlotDeferredResult
def test_unfilledSlotDeferredResult(self):
"""
Flattening a L{Deferred} which results in an unfilled L{slot} results
in a L{FlattenerError} failure.
"""
return self.assertFailure(
self.deferflatten(succeed(slot("foo"))),
FlattenerError)
示例10: test_unfilledSlot
def test_unfilledSlot(self):
"""
Flattening a slot which has no known value results in an
L{FlattenerError} exception which has an L{UnfilledSlot} exception
in its arguments.
"""
exc = self.assertRaises(FlattenerError, self.flatten, slot("foo"))
self.assertTrue(isinstance(exc.args[0], UnfilledSlot))
示例11: test_filledSlotTagChildEscaping
def test_filledSlotTagChildEscaping(self):
"""
Flattening a slot as a child of a L{Tag} which has been given a string
value results in that string value being XML escaped in the output.
"""
tag = div[slot("foo")]
tag.fillSlots("foo", '"&<>')
self.assertStringEqual(self.flatten(tag), '<div>"&<></div>')
示例12: test_precompiledSlot
def test_precompiledSlot(self):
"""
A L{_PrecompiledSlot} is replaced with the value of that slot when
flattened.
"""
tag = invisible[oldPrecompile(div[slot("foo")])]
tag.fillSlots("foo", '"&<>')
self.assertStringEqual(self.flatten(tag), '<div>"&<></div>')
示例13: test_precompiledSlotTagAttribute
def test_precompiledSlotTagAttribute(self):
"""
A L{_PrecompiledSlot} which is the value of an attribute is replaced
with the value of the slot with XML attribute quoting applied.
"""
tag = invisible[oldPrecompile(div(foo=slot("foo")))]
tag.fillSlots("foo", '"&<>')
self.assertStringEqual(self.flatten(tag), '<div foo=""&<>"></div>')
示例14: test_slotFilledWithProto
def test_slotFilledWithProto(self):
"""
Filling a slot with a L{Proto} results in the slot being replaced with
the serialized form of the tag in the output.
"""
tag = div[slot("foo")]
tag.fillSlots("foo", br)
self.assertStringEqual(self.flatten(tag), "<div><br /></div>")
示例15: test_precompileSlotData
def test_precompileSlotData(self):
"""Test that tags with slotData are not precompiled out of the
stan tree.
"""
tag = tags.p[tags.slot('foo')]
tag.fillSlots('foo', 'bar')
precompiled = self.render(tag, precompile=True)
self.assertEqual(self.render(precompiled), '<p>bar</p>')