本文整理汇总了Python中genshi.input.XML.select方法的典型用法代码示例。如果您正苦于以下问题:Python XML.select方法的具体用法?Python XML.select怎么用?Python XML.select使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类genshi.input.XML
的用法示例。
在下文中一共展示了XML.select方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: list_security_issues
# 需要导入模块: from genshi.input import XML [as 别名]
# 或者: from genshi.input.XML import select [as 别名]
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]
示例2: generate_sitemap
# 需要导入模块: from genshi.input import XML [as 别名]
# 或者: from genshi.input.XML import select [as 别名]
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)
示例3: extract_href
# 需要导入模块: from genshi.input import XML [as 别名]
# 或者: from genshi.input.XML import select [as 别名]
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')