当前位置: 首页>>代码示例>>Python>>正文


Python etree.tounicode方法代码示例

本文整理汇总了Python中lxml.etree.tounicode方法的典型用法代码示例。如果您正苦于以下问题:Python etree.tounicode方法的具体用法?Python etree.tounicode怎么用?Python etree.tounicode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在lxml.etree的用法示例。


在下文中一共展示了etree.tounicode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_do_undo_element_double_format

# 需要导入模块: from lxml import etree [as 别名]
# 或者: from lxml.etree import tounicode [as 别名]
def test_do_undo_element_double_format(self):
        replacer = formatting.PlaceholderMaker(['p'], ['b', 'u'])

        # Formatting tags get replaced, and the content remains
        text = u'<p>This is <u>doubly <b>formatted</b></u> text.</p>'
        element = etree.fromstring(text)
        replacer.do_element(element)

        self.assertEqual(
            element.text,
            u'This is \ue006doubly \ue008formatted\ue007'
            u'\ue005 text.')

        replacer.undo_element(element)
        result = etree.tounicode(element)
        self.assertEqual(result, text) 
开发者ID:Shoobx,项目名称:xmldiff,代码行数:18,代码来源:test_formatting.py

示例2: _le_xml

# 需要导入模块: from lxml import etree [as 别名]
# 或者: from lxml.etree import tounicode [as 别名]
def _le_xml(self, arquivo):
        if arquivo is None:
            return False

        if not isinstance(arquivo, basestring):
            arquivo = etree.tounicode(arquivo)

        if arquivo is not None:
            if isinstance(arquivo, basestring): 
                if NAMESPACE_NFSE in arquivo:
                    arquivo = por_acentos(arquivo)
                if u'<' in arquivo:
                    self._xml = etree.fromstring(tira_abertura(arquivo))
                else:
                    arq = open(arquivo)
                    txt = ''.join(arq.readlines())
                    txt = tira_abertura(txt)
                    arq.close()
                    self._xml = etree.fromstring(txt)
            else:
                self._xml = etree.parse(arquivo)
            return True

        return False 
开发者ID:thiagopena,项目名称:PySIGNFe,代码行数:26,代码来源:base.py

示例3: execute

# 需要导入模块: from lxml import etree [as 别名]
# 或者: from lxml.etree import tounicode [as 别名]
def execute(url):

    html = etree.parse(url)
    #print(etree.tounicode(html))

    root = html.getroot()
    #print(root)

    for tag in root:
        #print('tag:', tag.tag)

        #for subtag in tag:
        #    print('subtag:', subtag.tag, '=', subtag.text)

        if tag.tag == 'pozycja':
            print( [subtag.text for subtag in tag if tag.tag == 'pozycja'] )

        #print('-----') 
开发者ID:furas,项目名称:python-examples,代码行数:20,代码来源:main.py

示例4: store

# 需要导入模块: from lxml import etree [as 别名]
# 或者: from lxml.etree import tounicode [as 别名]
def store(self, extension):
        if self._last_page_id:
            self._store_page(extension, self._last_page_id)
            self._last_page_id = None
        else:
            for xml, page in tqdm(zip(self.xmlfiles, self.pages), desc="Writing PageXML files", total=len(self.xmlfiles)):
                with open(split_all_ext(xml)[0] + extension, 'w') as f:
                    f.write(etree.tounicode(page.getroottree())) 
开发者ID:Calamari-OCR,项目名称:calamari,代码行数:10,代码来源:dataset.py

示例5: _store_page

# 需要导入模块: from lxml import etree [as 别名]
# 或者: from lxml.etree import tounicode [as 别名]
def _store_page(self, extension, page_id):
        page = self.pages[self.xmlfiles.index(page_id)]
        with open(split_all_ext(page_id)[0] + extension, 'w') as f:
            f.write(etree.tounicode(page.getroottree())) 
开发者ID:Calamari-OCR,项目名称:calamari,代码行数:6,代码来源:dataset.py

示例6: clean_steps

# 需要导入模块: from lxml import etree [as 别名]
# 或者: from lxml.etree import tounicode [as 别名]
def clean_steps(self, nodes):
        # HTML tag <p/>
        re_p = re.compile('</?p[^>]*>')
        # HTML tag <br/>
        re_br = re.compile('<br\s*?/?>')
        steps = [{
            'step': idx + 1,
            'desc': re_br.sub('\n', re_p.sub('', etree.tounicode(node.find('p')).strip())).strip(),
            'img': node.find('img').get('src') if node.find('img') is not None else ''
        } for idx, node in enumerate(nodes)]
        return steps 
开发者ID:ruter,项目名称:xiachufang-api,代码行数:13,代码来源:content.py

示例7: patch_text

# 需要导入模块: from lxml import etree [as 别名]
# 或者: from lxml.etree import tounicode [as 别名]
def patch_text(actions, tree):
    """Takes a string with XML and a string with actions"""
    tree = etree.fromstring(tree)
    actions = patch.DiffParser().parse(actions)
    tree = patch_tree(actions, tree)
    return etree.tounicode(tree) 
开发者ID:Shoobx,项目名称:xmldiff,代码行数:8,代码来源:main.py

示例8: patch_file

# 需要导入模块: from lxml import etree [as 别名]
# 或者: from lxml.etree import tounicode [as 别名]
def patch_file(actions, tree):
    """Takes two filenames or streams, one with XML the other a diff"""
    tree = etree.parse(tree)

    if isinstance(actions, six.string_types):
        # It's a string, so it's a filename
        with open(actions) as f:
            actions = f.read()
    else:
        # We assume it's a stream
        actions = actions.read()

    actions = patch.DiffParser().parse(actions)
    tree = patch_tree(actions, tree)
    return etree.tounicode(tree) 
开发者ID:Shoobx,项目名称:xmldiff,代码行数:17,代码来源:main.py

示例9: get_placeholder

# 需要导入模块: from lxml import etree [as 别名]
# 或者: from lxml.etree import tounicode [as 别名]
def get_placeholder(self, element, ttype, close_ph):
        tag = etree.tounicode(element)
        ph = self.tag2placeholder.get((tag, ttype, close_ph))
        if ph is not None:
            return ph

        self.placeholder += 1
        ph = six.unichr(self.placeholder)
        self.placeholder2tag[ph] = PlaceholderEntry(element, ttype, close_ph)
        self.tag2placeholder[tag, ttype, close_ph] = ph
        return ph 
开发者ID:Shoobx,项目名称:xmldiff,代码行数:13,代码来源:formatting.py

示例10: render

# 需要导入模块: from lxml import etree [as 别名]
# 或者: from lxml.etree import tounicode [as 别名]
def render(self, result):
        return etree.tounicode(result, pretty_print=self.pretty_print) 
开发者ID:Shoobx,项目名称:xmldiff,代码行数:4,代码来源:formatting.py

示例11: test_do_element

# 需要导入模块: from lxml import etree [as 别名]
# 或者: from lxml.etree import tounicode [as 别名]
def test_do_element(self):
        replacer = formatting.PlaceholderMaker(['p'], ['b'])

        # Formatting tags get replaced, and the content remains
        text = u'<p>This is a tag with <b>formatted</b> text.</p>'
        element = etree.fromstring(text)
        replacer.do_element(element)

        self.assertEqual(
            etree.tounicode(element),
            u'<p>This is a tag with \ue006formatted\ue005 text.</p>')

        replacer.undo_element(element)
        self.assertEqual(etree.tounicode(element), text)

        # Non formatting tags get replaced with content
        text = u'<p>This is a tag with <foo>formatted</foo> text.</p>'
        element = etree.fromstring(text)
        replacer.do_element(element)
        result = etree.tounicode(element)
        self.assertEqual(
            result,
            u'<p>This is a tag with \ue007 text.</p>')

        # Single formatting tags still get two placeholders.
        text = u'<p>This is a <b/> with <foo/> text.</p>'
        element = etree.fromstring(text)
        replacer.do_element(element)
        result = etree.tounicode(element)
        self.assertEqual(
            result,
            u'<p>This is a \ue009\ue008 with \ue00a text.</p>') 
开发者ID:Shoobx,项目名称:xmldiff,代码行数:34,代码来源:test_formatting.py

示例12: _test

# 需要导入模块: from lxml import etree [as 别名]
# 或者: from lxml.etree import tounicode [as 别名]
def _test(self, start, action, end):
        tree = etree.fromstring(start)
        self.patcher.handle_action(action, tree)
        self.assertEqual(etree.tounicode(tree), end) 
开发者ID:Shoobx,项目名称:xmldiff,代码行数:6,代码来源:test_patch.py

示例13: test_all_feed_with_one_item

# 需要导入模块: from lxml import etree [as 别名]
# 或者: from lxml.etree import tounicode [as 别名]
def test_all_feed_with_one_item(self):
        response = self.app.get('/results/all.atom')
        root = etree.XML(response.content)
        xml_pretty = etree.tounicode(root, pretty_print=True)

        result_event = ResultEvent.objects.first()
        expected = '''<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-gb">
  <title>Election results from example.com (with extra data)</title>
  <link href="http://example.com/" rel="alternate"/>
  <link href="http://example.com/results/all.atom" rel="self"/>
  <id>http://example.com/</id>
  <updated>{updated}</updated>
  <entry>
    <title>Tessa Jowell (Labour Party) won in Member of Parliament for Dulwich and West Norwood</title>
    <link href="http://example.com/#{item_id}" rel="alternate"/>
    <published>{updated}</published>
    <updated>{updated}</updated>
    <author>
      <name>john</name>
    </author>
    <id>http://example.com/#{item_id}</id>
    <summary type="html">A example.com volunteer recorded at {space_separated} that Tessa Jowell (Labour Party) won the ballot in Member of Parliament for Dulwich and West Norwood, quoting the source 'Seen on the BBC news').</summary>
    <post_id>65808</post_id>
    <winner_person_id>4322</winner_person_id>
    <winner_person_name>Tessa Jowell</winner_person_name>
    <winner_party_id>party:53</winner_party_id>
    <winner_party_name>Labour Party</winner_party_name>
    <user_id>{user_id}</user_id>
    <post_name>Member of Parliament for Dulwich and West Norwood</post_name>
    <information_source>Seen on the BBC news</information_source>
    <parlparse_id>uk.org.publicwhip/person/123456</parlparse_id>
  </entry>
</feed>
'''.format(
    updated=rfc3339_date(result_event.created),
    space_separated=result_event.created.strftime("%Y-%m-%d %H:%M:%S"),
    item_id=result_event.id,
    user_id=self.user.id,
)
        self.compare_xml(expected, xml_pretty) 
开发者ID:mysociety,项目名称:yournextrepresentative,代码行数:42,代码来源:tests.py

示例14: test_all_basic_feed_with_one_item

# 需要导入模块: from lxml import etree [as 别名]
# 或者: from lxml.etree import tounicode [as 别名]
def test_all_basic_feed_with_one_item(self):
        response = self.app.get('/results/all-basic.atom')
        root = etree.XML(response.content)
        xml_pretty = etree.tounicode(root, pretty_print=True)

        result_event = ResultEvent.objects.first()
        expected = '''<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-gb">
  <title>Election results from example.com</title>
  <link href="http://example.com/" rel="alternate"/>
  <link href="http://example.com/results/all-basic.atom" rel="self"/>
  <id>http://example.com/</id>
  <updated>{updated}</updated>
  <entry>
    <title>Tessa Jowell (Labour Party) won in Member of Parliament for Dulwich and West Norwood</title>
    <link href="http://example.com/#{item_id}" rel="alternate"/>
    <published>{updated}</published>
    <updated>{updated}</updated>
    <author>
      <name>john</name>
    </author>
    <id>http://example.com/#{item_id}</id>
    <summary type="html">A example.com volunteer recorded at {space_separated} that Tessa Jowell (Labour Party) won the ballot in Member of Parliament for Dulwich and West Norwood, quoting the source 'Seen on the BBC news').</summary>
  </entry>
</feed>
'''.format(
    updated=rfc3339_date(result_event.created),
    space_separated=result_event.created.strftime("%Y-%m-%d %H:%M:%S"),
    item_id=result_event.id,
)
        self.compare_xml(expected, xml_pretty) 
开发者ID:mysociety,项目名称:yournextrepresentative,代码行数:32,代码来源:tests.py

示例15: get_xml_reply

# 需要导入模块: from lxml import etree [as 别名]
# 或者: from lxml.etree import tounicode [as 别名]
def get_xml_reply(self):
        return etree.tounicode(self.reply) 
开发者ID:opencord,项目名称:voltha,代码行数:4,代码来源:error.py


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