當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。