本文整理汇总了Python中genshi.input.XML类的典型用法代码示例。如果您正苦于以下问题:Python XML类的具体用法?Python XML怎么用?Python XML使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了XML类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_pickle
def test_pickle(self):
xml = XML('<li>Foo</li>')
buf = StringIO()
pickle.dump(xml, buf, 2)
buf.seek(0)
xml = pickle.load(buf)
self.assertEquals('<li>Foo</li>', xml.render())
示例2: test_pickle
def test_pickle(self):
xml = XML('<li>Foo</li>')
buf = BytesIO()
pickle.dump(xml, buf, 2)
buf.seek(0)
xml = pickle.load(buf)
self.assertEquals('<li>Foo</li>', xml.render(encoding=None))
示例3: _test
def _test(self, expected_id, result):
expected = self._expected(expected_id).render(encoding='utf-8')
result = XML(result.render(encoding='utf-8')).render(encoding='utf-8')
expected, result = expected.splitlines(), result.splitlines()
for exp, res in zip(expected, result):
self.assertEquals(exp, res)
self.assertEquals(len(expected), len(result))
示例4: list_security_issues
def list_security_issues(self):
'''
Fills in issues and topissues with security issues information.
'''
issues = glob.glob('templates/security/PMASA-*')
issues.sort(key=lambda x: int(x[24:29]) * 100 - int(x[30:]))
for issue in issues:
xmldata = XML(open(issue, 'r').read())
name = os.path.basename(issue)
self.data['issues'].append({
'name': name,
'link': '%ssecurity/%s' % (BASE_URL, self.get_outname(name)),
'fulllink': '%s%ssecurity/%s' % (
SERVER, BASE_URL, self.get_outname(name)
),
'summary': str(xmldata.select(
'def[@function="announcement_summary"]/text()'
)),
'date': helper.date.DateTime.parse(str(xmldata.select(
'def[@function="announcement_date"]/text()'
))),
'cves': str(xmldata.select(
'def[@function="announcement_cve"]/text()'
)).split(' '),
'versions': str(xmldata.select(
'def[@function="announcement_affected"]/text()'
)),
})
self.data['topissues'] = self.data['issues'][:TOP_ISSUES]
示例5: extract_href
def extract_href(fragment):
if isinstance(fragment, (Element, Fragment)):
stream = tag.body(fragment).generate()
else :
self.log.debug("Extracting href from %s", fragment)
stream = XML('<body>%s</body>' % (unicode(fragment),))
for x in stream.select('a[@href]') :
if x[0] == 'START' :
return x[1][1].get('href')
示例6: generate_sitemap
def generate_sitemap(self):
'''
Generates list of pages with titles.
'''
self.data['sitemap'] = []
self.data['sitemapxml'] = []
helper.log.dbg('Generating sitemap:')
for root, dirs, files in os.walk(TEMPLATES):
if '.svn' in dirs:
dirs.remove('.svn') # don't visit .svn directories
if '.git' in dirs:
dirs.remove('.git') # don't visit .git directories
files.sort()
root_dir = root[len(TEMPLATES):].strip('/')
if len(root_dir) > 0:
root_dir += '/'
for filename in files:
name, ext = os.path.splitext(filename)
if ext != '.tpl' and name[:6] != 'PMASA-':
continue
if name[0] in ['_', '.']:
continue
if filename in ['index.xml.tpl', 'sitemap.xml.tpl', '404.tpl']:
continue
helper.log.dbg('- %s' % filename)
xmldata = XML(open(os.path.join(root, filename), 'r').read())
title = str(xmldata.select(
'def[@function="page_title"]/text()'
))
title = title.strip()
if len(title) == 0:
title = str(xmldata.select(
'def[@function="announcement_id"]/text()'
))
title = title.strip()
if len(title) == 0:
title = 'Index'
link = root_dir + self.get_outname(name)
sitemap = {
'link': link,
'loc': '%s%s%s' % (SERVER, BASE_URL, link),
'title': title
}
if name[:6] != 'PMASA-':
self.data['sitemap'].append(sitemap)
sitemap.update(self.get_sitemap_data(root_dir + name))
self.data['sitemapxml'].append(sitemap)
for link in data.sitemap.ENTRIES:
sitemap = {
'loc': SERVER + link,
}
sitemap.update(self.get_sitemap_data(link))
self.data['sitemapxml'].append(sitemap)
示例7: test_render_unicode
def test_render_unicode(self):
xml = XML('<li>Über uns</li>')
self.assertEqual(u'<li>Über uns</li>', xml.render(encoding=None))
示例8: test_pre_whitespace
def test_pre_whitespace(self):
content = '\nHey <em>there</em>. \n\n I am indented.\n'
stream = XML('<pre>%s</pre>' % content)
output = stream.render(HTMLSerializer, encoding=None)
self.assertEqual('<pre>%s</pre>' % content, output)
示例9: test_textarea_whitespace
def test_textarea_whitespace(self):
content = '\nHey there. \n\n I am indented.\n'
stream = XML('<textarea name="foo">%s</textarea>' % content)
output = stream.render(HTMLSerializer, encoding=None)
self.assertEqual('<textarea name="foo">%s</textarea>' % content, output)
示例10: test_render_unicode
def test_render_unicode(self):
xml = XML("<li>Über uns</li>")
self.assertEqual(u"<li>Über uns</li>", xml.render())
self.assertEqual(u"<li>Über uns</li>", xml.render(encoding=None))
示例11: test_render_ascii
def test_render_ascii(self):
xml = XML("<li>Über uns</li>")
self.assertEqual(u"<li>Über uns</li>".encode("ascii"), xml.render(encoding="ascii"))
示例12: test_render_output_stream_unicode
def test_render_output_stream_unicode(self):
xml = XML('<li>Über uns</li>')
strio = StringIO()
self.assertEqual(None, xml.render(encoding=None, out=strio))
self.assertEqual(u'<li>Über uns</li>', strio.getvalue())
示例13: test_render_output_stream_utf8
def test_render_output_stream_utf8(self):
xml = XML('<li>Über uns</li>')
strio = cStringIO()
self.assertEqual(None, xml.render(out=strio))
self.assertEqual('<li>Über uns</li>', strio.getvalue())
示例14: test_render_utf8
def test_render_utf8(self):
xml = XML("<li>Über uns</li>")
self.assertEqual(u"<li>Über uns</li>".encode("utf-8"), xml.render(encoding="utf-8"))
示例15: test_render_utf8
def test_render_utf8(self):
xml = XML('<li>Über uns</li>')
self.assertEqual('<li>Über uns</li>', xml.render())