本文整理汇总了Python中nevow.flat.flatten函数的典型用法代码示例。如果您正苦于以下问题:Python flatten函数的具体用法?Python flatten怎么用?Python flatten使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了flatten函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_normal
def test_normal(self):
"""No quoting at all happens when we are in a JavascriptContext
which is not in a single quoted string or a double quoted string.
"""
ctx = makeCtx()
self.assertEquals(flat.flatten("foo", ctx), "'foo'")
self.assertEquals(flat.flatten(livepage.js("1 < 2 & 3"), ctx), "1 < 2 & 3")
示例2: 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>')
示例3: testHTML
def testHTML(self):
t = '<a href="#"><nevow:attr name="href">href</nevow:attr>label</a>'
doc = flat.flatten(loaders.htmlstr(t).load())
self.assertEqual(doc, '<a href="href">label</a>')
t = '<a href="#"><nevow:attr name="href"><nevow:slot name="href"/></nevow:attr>label</a>'
ctx = context.WovenContext()
ctx.fillSlots('href', 'href')
precompiled = flat.precompile(loaders.htmlstr(t).load())
result = flat.flatten(precompiled, ctx)
self.assertEqual(result, '<a href="href">label</a>')
示例4: test_title
def test_title(self):
"""
The I{title} renderer should add the wrapped fragment's title
attribute, if any, or the default "Divmod".
"""
page = self.createPage(self.username)
titleTag = title()
tag = page.render_title(context.WebContext(tag=titleTag), None)
self.assertIdentical(tag, titleTag)
flattened = flatten(tag)
self.assertSubstring(flatten(getattr(page.fragment, "title", "Divmod")), flattened)
示例5: test_inAttribute
def test_inAttribute(self):
"""When inside an attribute, we must make sure to quote
double quotes.
"""
ctx = makeCtx(inAttribute=True)
self.assertEquals(flat.flatten('foo', ctx), "'foo'")
self.assertEquals(
flat.flatten(livepage.js.foo('hello"world'), ctx),
"foo('hello"world')")
self.assertEquals(
flat.flatten(livepage.js.foo("1 < 2 & 3"), ctx),
"foo('1 < 2 & 3')")
示例6: 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>')
示例7: getEditGrabberForm
def getEditGrabberForm(self, targetID):
if self.wt is None:
self.wt = self.original.privateApplication
grabber = self.wt.fromWebID(targetID)
f = liveform.LiveForm(
lambda **kwargs: self.editGrabber(grabber, **kwargs),
(liveform.Parameter('password1',
liveform.PASSWORD_INPUT,
unicode,
u'New Password'),
liveform.Parameter('password2',
liveform.PASSWORD_INPUT,
unicode,
u'Repeat Password'),
liveform.Parameter('ssl',
liveform.CHECKBOX_INPUT,
bool,
'Use SSL',
default=grabber.ssl)),
description='Edit Grabber')
grabber.grab()
f.setFragmentParent(self)
return unicode(flatten(f), 'utf-8')
示例8: test_transportRoot
def test_transportRoot(self):
"""
The transport root should always point at the '/live' transport root
provided to avoid database interaction while invoking the transport.
"""
livePage = self.makeLivePage()
self.assertEquals(flatten(livePage.transportRoot), 'http://localhost/live')
示例9: flattened
def flattened(spam):
# Join the bits to make a complete URL.
u = ''.join(bits)
# It might also be relative so resolve it against the current URL
# and flatten it again.
u = flat.flatten(URL.fromContext(ctx).click(u), ctx)
return redirectTo(u, inevow.IRequest(ctx))
示例10: formatHeader
def formatHeader(self, columns: [str]) -> bytes:
self.columns = columns
tr = tags.tr()[
[tags.th()[i] for i in self.columns]
]
self.header.children.append(tr)
return flat.flatten(tr)
示例11: test_dontQuoteJS
def test_dontQuoteJS(self):
"""We must not put js objects in single quotes, even if they
are inside another js.__call__
"""
self.assertEquals(
flat.flatten(livepage.js.foo(livepage.js.bar()), makeCtx()),
"foo(bar())")
示例12: handleWsFailure
def handleWsFailure(self,failureInst,handler,callbackURI):
"""
called in case of failure condition.
"""
failureInst.trap(error.Error)
# handle the various status codes
scode = int(failureInst.value.status)
#print 'failureInst.value is',failureInst.value,failureInst.value.status,type(failureInst.value.status)
if scode == 503:
# mark the state as retry
for req in handler.requests: self.recentTxns[req['id']].setretry()
# try again - service is temporarily unavailable.
d = defer.Deferred()
donecb = d.addCallback(self.proxyHandler.doRemoteRequest,handler,callbackURI)
donecb.addCallback(self.clearTxn,handler)
donecb.addErrback(self.handleWsFailure,handler,callbackURI)
reactor.callLater(2,d.callback,None)
else:
# return the error code back
resp = ProxyResponse([{'id':req['id'],'status':scode} for req in handler.requests],[])
fireCallbackURI(callbackURI,flat.flatten(resp.generateResponse()))
# trap all the errors here.
return None
示例13: 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')
示例14: xmlCountResults
def xmlCountResults(count):
"""a made-up format for count query results"""
return '<?xml version="1.0"?>\n' + flat.flatten(
Tag("sparql")(xmlns=RESULTS_NS, **{'xmlns:ext':EXTENDED_NS})[
Tag("results")[
Tag("ext:count")[count],
]])
示例15: visit_cmsimage_node
def visit_cmsimage_node(self, node):
maxwidth=node.attributes['maxwidth']
maxheight=node.attributes['maxheight']
if maxwidth is None or maxheight is None:
tag = T.img(src=self.systemURL.child('assets').child( node.attributes['id'] ))
else:
tag = T.img(src=self.systemURL.child('assets').child( node.attributes['id'] ).add('size','%sx%s'%(maxwidth,maxheight)))
if node.attributes['alt']:
tag = tag(alt=node.attributes['alt'])
if node.attributes['title']:
tag = tag(title=node.attributes['title'])
if node.attributes['cssclass']:
tag = tag(class_=node.attributes['cssclass'])
if node.attributes['href']:
tag = T.a(href=node.attributes['href'])[ tag ]
if node.attributes['caption']:
tag = T.div(class_='cmsimage')[tag,T.p[node.attributes['caption']]]
else:
tag = T.div(class_='cmsimage')[tag]
html = flat.flatten(tag)
self.body.append(html)