本文整理汇总了Python中babel.messages.extract.extract_python方法的典型用法代码示例。如果您正苦于以下问题:Python extract.extract_python方法的具体用法?Python extract.extract_python怎么用?Python extract.extract_python使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类babel.messages.extract
的用法示例。
在下文中一共展示了extract.extract_python方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: process_python
# 需要导入模块: from babel.messages import extract [as 别名]
# 或者: from babel.messages.extract import extract_python [as 别名]
def process_python(self, code, code_lineno, translator_strings):
comment_tags = self.config["comment-tags"]
for (
lineno,
funcname,
messages,
python_translator_comments,
) in extract_python(code, self.keywords, comment_tags, self.options):
yield (
code_lineno + (lineno - 1),
funcname,
messages,
translator_strings + python_translator_comments,
)
示例2: process_python
# 需要导入模块: from babel.messages import extract [as 别名]
# 或者: from babel.messages.extract import extract_python [as 别名]
def process_python(self, code, code_lineno, translator_strings):
comment_tags = self.config['comment-tags']
for lineno, funcname, messages, python_translator_comments \
in extract_python(code,
self.keywords, comment_tags, self.options):
yield (code_lineno + (lineno - 1), funcname, messages,
translator_strings + python_translator_comments)
示例3: process_python
# 需要导入模块: from babel.messages import extract [as 别名]
# 或者: from babel.messages.extract import extract_python [as 别名]
def process_python(self, code, code_lineno, translator_strings):
comment_tags = self.config['comment-tags']
for lineno, funcname, messages, python_translator_comments \
in extract_python(code,
self.keywords, comment_tags, self.options):
yield (code_lineno + (lineno - 1), funcname, messages,
translator_strings + python_translator_comments)
示例4: extract_model_messages
# 需要导入模块: from babel.messages import extract [as 别名]
# 或者: from babel.messages.extract import extract_python [as 别名]
def extract_model_messages(fileobj, keywords, comment_tags, options):
"""Extract messages from python model container-files.
:param fileobj: the file-like object the messages should be extracted
from
:param keywords: a list of keywords (i.e. function names) that should
be recognized as translation functions
:param comment_tags: a list of translator tags to search for and
include in the results
:param options: a dictionary of additional options (optional)
:return: an iterator over ``(lineno, funcname, message, comments)``
tuples
:rtype: ``iterator``
"""
def extract_model():
import ast
fileobj.seek(0)
node = ast.parse(fileobj.read())
classes = [n for n in node.body if isinstance(n, ast.ClassDef)]
def has_model(class_def):
for base in class_def.bases:
from appkernel import Model
if base.id == Model.__name__:
return True
return False
def is_parameter(body_elem):
if not hasattr(body_elem, 'value') or not hasattr(body_elem.value, 'func'):
return False
return body_elem.value.func.id == 'Parameter'
for class_ in classes:
if has_model(class_):
for param in [p for p in class_.body if isinstance(p, ast.Assign) and is_parameter(p)]:
clazz_name = class_.name
parameter_name = param.targets[0].id
yield (param.lineno, '', '{}.{}'.format(clazz_name, parameter_name),
['Parameter "{}" on "{}"'.format(parameter_name, clazz_name)])
from babel.messages.extract import extract_python
return itertools.chain(extract_python(fileobj, keywords, comment_tags, options), extract_model())