本文整理汇总了Python中docutils.transforms.TransformError方法的典型用法代码示例。如果您正苦于以下问题:Python transforms.TransformError方法的具体用法?Python transforms.TransformError怎么用?Python transforms.TransformError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类docutils.transforms
的用法示例。
在下文中一共展示了transforms.TransformError方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: authors_from_one_paragraph
# 需要导入模块: from docutils import transforms [as 别名]
# 或者: from docutils.transforms import TransformError [as 别名]
def authors_from_one_paragraph(self, field):
"""Return list of Text nodes for ";"- or ","-separated authornames."""
# @@ keep original formatting? (e.g. ``:authors: A. Test, *et-al*``)
text = ''.join(unicode(node)
for node in field[1].traverse(nodes.Text))
if not text:
raise TransformError
for authorsep in self.language.author_separators:
# don't split at escaped `authorsep`:
pattern = '(?<!\x00)%s' % authorsep
authornames = re.split(pattern, text)
if len(authornames) > 1:
break
authornames = (name.strip() for name in authornames)
authors = [[nodes.Text(name, utils.unescape(name, True))]
for name in authornames if name]
return authors
示例2: extract_authors
# 需要导入模块: from docutils import transforms [as 别名]
# 或者: from docutils.transforms import TransformError [as 别名]
def extract_authors(self, field, name, docinfo):
try:
if len(field[1]) == 1:
if isinstance(field[1][0], nodes.paragraph):
authors = self.authors_from_one_paragraph(field)
elif isinstance(field[1][0], nodes.bullet_list):
authors = self.authors_from_bullet_list(field)
else:
raise TransformError
else:
authors = self.authors_from_paragraphs(field)
authornodes = [nodes.author('', '', *author)
for author in authors if author]
if len(authornodes) >= 1:
docinfo.append(nodes.authors('', *authornodes))
else:
raise TransformError
except TransformError:
field[-1] += self.document.reporter.warning(
'Bibliographic field "%s" incompatible with extraction: '
'it must contain either a single paragraph (with authors '
'separated by one of "%s"), multiple paragraphs (one per '
'author), or a bullet list with one paragraph (one author) '
'per item.'
% (name, ''.join(self.language.author_separators)),
base_node=field)
raise
示例3: authors_from_one_paragraph
# 需要导入模块: from docutils import transforms [as 别名]
# 或者: from docutils.transforms import TransformError [as 别名]
def authors_from_one_paragraph(self, field):
text = field[1][0].astext().strip()
if not text:
raise TransformError
for authorsep in self.language.author_separators:
authornames = text.split(authorsep)
if len(authornames) > 1:
break
authornames = [author.strip() for author in authornames]
authors = [[nodes.Text(author)] for author in authornames if author]
return authors
示例4: authors_from_bullet_list
# 需要导入模块: from docutils import transforms [as 别名]
# 或者: from docutils.transforms import TransformError [as 别名]
def authors_from_bullet_list(self, field):
authors = []
for item in field[1][0]:
if len(item) != 1 or not isinstance(item[0], nodes.paragraph):
raise TransformError
authors.append(item[0].children)
if not authors:
raise TransformError
return authors
示例5: authors_from_paragraphs
# 需要导入模块: from docutils import transforms [as 别名]
# 或者: from docutils.transforms import TransformError [as 别名]
def authors_from_paragraphs(self, field):
for item in field[1]:
if not isinstance(item, nodes.paragraph):
raise TransformError
authors = [item.children for item in field[1]]
return authors