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


Python extract.extract_python方法代码示例

本文整理汇总了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,
            ) 
开发者ID:remg427,项目名称:misp42splunk,代码行数:16,代码来源:babelplugin.py

示例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) 
开发者ID:jpush,项目名称:jbox,代码行数:9,代码来源:babelplugin.py

示例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) 
开发者ID:fboender,项目名称:ansible-cmdb,代码行数:9,代码来源:babelplugin.py

示例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()) 
开发者ID:accelero-cloud,项目名称:appkernel,代码行数:45,代码来源:util.py


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