• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python loaders.xmlstr函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中nevow.loaders.xmlstr函数的典型用法代码示例。如果您正苦于以下问题:Python xmlstr函数的具体用法?Python xmlstr怎么用?Python xmlstr使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了xmlstr函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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>')
开发者ID:KatiaBorges,项目名称:exeLearning,代码行数:9,代码来源:test_disktemplate.py


示例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
开发者ID:UstadMobile,项目名称:exelearning-ustadmobile-work,代码行数:29,代码来源:test_rend.py


示例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))
开发者ID:timparkin,项目名称:into-the-light,代码行数:7,代码来源:rest.py


示例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>')
开发者ID:KatiaBorges,项目名称:exeLearning,代码行数:29,代码来源:test_rend.py


示例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>')
开发者ID:UstadMobile,项目名称:exelearning-ustadmobile-work,代码行数:7,代码来源:test_rend.py


示例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>")
开发者ID:perkinslr,项目名称:nevow-py3,代码行数:8,代码来源:test_element.py


示例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)
开发者ID:StetHD,项目名称:nevow,代码行数:8,代码来源:test_loaders.py


示例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], ' ')
开发者ID:StetHD,项目名称:nevow,代码行数:8,代码来源:test_loaders.py


示例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" />')
开发者ID:perkinslr,项目名称:nevow-py3,代码行数:9,代码来源:test_url.py


示例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 = []
开发者ID:BGCX261,项目名称:zoto-server-svn-to-git,代码行数:10,代码来源:user_albums.py


示例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&amp;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&amp;baz=spam"></a>')
开发者ID:StetHD,项目名称:nevow,代码行数:13,代码来源:test_url.py


示例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")
开发者ID:StetHD,项目名称:nevow,代码行数:16,代码来源:test_loaders.py


示例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()
开发者ID:StetHD,项目名称:nevow,代码行数:51,代码来源:customform.py


示例14: test_xmlstr

 def test_xmlstr(self):
     doc = '<p>hello</p>'
     self._withAndWithout(loaders.xmlstr(doc))
开发者ID:StetHD,项目名称:nevow,代码行数:3,代码来源:test_loaders.py


示例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>')
开发者ID:StetHD,项目名称:nevow,代码行数:4,代码来源:test_loaders.py


示例16: test_ignoreDocType

 def test_ignoreDocType(self):
     doc = '''<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">\n<html><body><p>Hello.</p></body></html>'''
     df = loaders.xmlstr(doc, ignoreDocType=True)
     self.assertEquals(flat.flatten(df), '<html><body><p>Hello.</p></body></html>')
开发者ID:StetHD,项目名称:nevow,代码行数:4,代码来源:test_loaders.py


示例17: test_slotWithCharacterData

 def test_slotWithCharacterData(self):
     """Test that xml templates with slots that contain content can be
     loaded"""
     template = '<p xmlns:nevow="http://nevow.com/ns/nevow/0.1"><nevow:slot name="foo">stuff</nevow:slot></p>'
     doc = loaders.xmlstr(template).load()
开发者ID:KatiaBorges,项目名称:exeLearning,代码行数:5,代码来源:test_disktemplate.py


示例18: __init__

 def __init__(self,xml):
     rend.Fragment.__init__(self, docFactory=loaders.xmlstr(self.XML_TEMPLATE%xml, ignoreDocType=True))
开发者ID:timparkin,项目名称:into-the-light,代码行数:2,代码来源:common.py


示例19: MantissaThemeTests

        """
        return self._defaultThemedRendering(ThemedElement)



class MantissaThemeTests(XHTMLDirectoryThemeTestsMixin, TestCase):
    """
    Stock L{XHTMLDirectoryTheme} tests applied to L{baseOffering} and its
    theme.
    """
    offering = baseOffering
    theme = offering.themes[0]



CUSTOM_MSG = xmlstr('<div>Athena unsupported here</div>')
BASE_MSG =  file(sibpath(__file__,
                         "../themes/base/athena-unsupported.html")
                 ).read().strip()



class StubThemeProvider(Item):
    """
    Trivial implementation of a theme provider, for testing that custom
    Athena-unsupported pages can be used.
    """
    _attribute = integer(doc="exists to pacify Axiom's hunger for attributes")
    implements(ITemplateNameResolver)
    powerupInterfaces = (ITemplateNameResolver,)
    def getDocFactory(self, name):
开发者ID:fusionapp,项目名称:mantissa,代码行数:31,代码来源:test_theme.py


示例20: asDOM


#.........这里部分代码省略.........
        generator=False,

        # TODO file insertion should really be disabled
        # but can't do that now, as that would make the
        # original include directive fail.. also can't
        # just temporarily enable it to kludge, as that
        # would mean the included file sees it as fully
        # enabled.. will have to reimplement include.

#         file_insertion_enabled=0,

        # TODO ponder disabling raw; it allows content creators to
        # attack the site

#         raw_enabled=0,

        _disable_config=1,
        roast_operation=operation,
        )

    if flavor == 's5':
        writer = s5_html.Writer()
        assert template is None
        assert s5_theme_url is not None
        settings.update(dict(
                theme=None,
                theme_url=s5_theme_url,
                current_slide=True,
                ))
    elif flavor == 'html':
        writer = html4css1.Writer()
    else:
        raise 'Unknown RST flavor: %r' % flavor

    # Docutils stores default `foo` role in global state that persists
    # from one parser to another. Parsing directive "default-role"
    # sets that, usually from s5defs.txt. To avoid infecting all
    # latter runs (`foo` will create <span
    # class="incremental">foo</span> instead of <cite>foo</cite>), we
    # try to contain the damage, and restore the default role to
    # original settings before every run.
    try:
        del roles._roles['']
    except KeyError:
        pass

    html, publisher = publish_programmatically(
        source_class=io.StringInput,
        source=text,
        source_path=source_path,
        destination_class=io.StringOutput,
        destination=None,
        destination_path=None,
        reader=None,
        reader_name='standalone',
        parser=None,
        parser_name='restructuredtext',
        writer=writer,
        writer_name=None,
        settings=None,
        settings_spec=None,
        settings_overrides=settings,
        config_section=None,
        enable_exit_status=None)

    tree = minidom.parseString(html)
    title = htmlutil.getTitle(tree)
    title = htmlutil.getNodeContentsAsText(title)

    # kill generator meta tag
    htmlutil.killGeneratorMetaTags(tree)

    # kill stylesheet
    htmlutil.killLinkedStylesheet(tree)

    if flavor == 'html':
        body = htmlutil.getOnlyElementByTagName(tree, 'body')

        docs = htmlutil.getElementsByClass(body, 'document')
        if len(docs) == 1:
            body = docs[0]

        # remove the headings rst promoted to top level,
        # the template will take care of that
        for h1 in body.getElementsByTagName('h1'):
            if htmlutil.elementHasClass(h1, 'title'):
                h1.parentNode.removeChild(h1)
                break

        if template is not None:
            template = Template(original=body,
                                docFactory=loaders.xmlstr(template),
                                title=title,
                                navigation=navigation,
                                )
            html = flat.flatten(template)
            tree = minidom.parseString(html)

    htmlutil.fixXMLTags(tree)
    return tree
开发者ID:mchubby,项目名称:roast,代码行数:101,代码来源:rst.py



注:本文中的nevow.loaders.xmlstr函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python stan.xml函数代码示例发布时间:2022-05-27
下一篇:
Python loaders.xmlfile函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap