Did I find the right examples for you? yes no      Crawl my project      Python Jobs

All Samples(475)  |  Call(441)  |  Derive(0)  |  Import(34)
Extract messages from Python source code.

It returns an iterator yielding tuples in the following form ``(lineno,
funcname, message, comments)``.

:param fileobj: the seekable, 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(more...)

        def extract_python(fileobj, keywords, comment_tags, options):
    """Extract messages from Python source code.

    It returns an iterator yielding tuples in the following form ``(lineno,
    funcname, message, comments)``.

    :param fileobj: the seekable, 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)
    :rtype: ``iterator``
    """
    funcname = lineno = message_lineno = None
    call_stack = -1
    buf = []
    messages = []
    translator_comments = []
    in_def = in_translator_comments = False
    comment_tag = None

    encoding = parse_encoding(fileobj) or options.get('encoding', 'iso-8859-1')

    if PY2:
        next_line = fileobj.readline
    else:
        next_line = lambda: fileobj.readline().decode(encoding)

    tokens = generate_tokens(next_line)
    for tok, value, (lineno, _), _, _ in tokens:
        if call_stack == -1 and tok == NAME and value in ('def', 'class'):
            in_def = True
        elif tok == OP and value == '(':
            if in_def:
                # Avoid false positives for declarations such as:
                # def gettext(arg='message'):
                in_def = False
                continue
            if funcname:
                message_lineno = lineno
                call_stack += 1
        elif in_def and tok == OP and value == ':':
            # End of a class definition without parens
            in_def = False
            continue
        elif call_stack == -1 and tok == COMMENT:
            # Strip the comment token from the line
            if PY2:
                value = value.decode(encoding)
            value = value[1:].strip()
            if in_translator_comments and \
                    translator_comments[-1][0] == lineno - 1:
                # We're already inside a translator comment, continue appending
                translator_comments.append((lineno, value))
                continue
            # If execution reaches this point, let's see if comment line
            # starts with one of the comment tags
            for comment_tag in comment_tags:
                if value.startswith(comment_tag):
                    in_translator_comments = True
                    translator_comments.append((lineno, value))
                    break
        elif funcname and call_stack == 0:
            if tok == OP and value == ')':
                if buf:
                    messages.append(''.join(buf))
                    del buf[:]
                else:
                    messages.append(None)

                if len(messages) > 1:
                    messages = tuple(messages)
                else:
                    messages = messages[0]
                # Comments don't apply unless they immediately preceed the
                # message
                if translator_comments and \
                        translator_comments[-1][0] < message_lineno - 1:
                    translator_comments = []

                yield (message_lineno, funcname, messages,
                       [comment[1] for comment in translator_comments])

                funcname = lineno = message_lineno = None
                call_stack = -1
                messages = []
                translator_comments = []
                in_translator_comments = False
            elif tok == STRING:
                # Unwrap quotes in a safe manner, maintaining the string's
                # encoding
                # https://sourceforge.net/tracker/?func=detail&atid=355470&
                # aid=617979&group_id=5470
                value = eval('# coding=%s\n%s' % (str(encoding), value),
                             {'__builtins__':{}}, {})
                if PY2 and not isinstance(value, text_type):
                    value = value.decode(encoding)
                buf.append(value)
            elif tok == OP and value == ',':
                if buf:
                    messages.append(''.join(buf))
                    del buf[:]
                else:
                    messages.append(None)
                if translator_comments:
                    # We have translator comments, and since we're on a
                    # comma(,) user is allowed to break into a new line
                    # Let's increase the last comment's lineno in order
                    # for the comment to still be a valid one
                    old_lineno, old_comment = translator_comments.pop()
                    translator_comments.append((old_lineno+1, old_comment))
        elif call_stack > 0 and tok == OP and value == ')':
            call_stack -= 1
        elif funcname and call_stack == -1:
            funcname = None
        elif tok == NAME and value in keywords:
            funcname = value
        


src/b/a/baepython_sdk-HEAD/examples/weibotest/0/mako/ext/babelplugin.py   baepython_sdk(Download)
from StringIO import StringIO
 
from babel.messages.extract import extract_python
 
from mako import lexer, parsetree
        code = StringIO(code)
        for lineno, funcname, messages, python_translator_comments \
                in extract_python(code, keywords, comment_tags, options):
            yield (node.lineno + (lineno - 1), funcname, messages,
                   translator_comments + python_translator_comments)

src/h/u/hue-HEAD/desktop/core/ext-py/Mako-0.8.1/mako/ext/babelplugin.py   hue(Download)
 
"""gettext message extraction via Babel: http://babel.edgewall.org/"""
from babel.messages.extract import extract_python
from mako.compat import StringIO
from mako import compat
        code = StringIO(code)
        for lineno, funcname, messages, python_translator_comments \
                in extract_python(code, keywords, comment_tags, options):
            yield (node.lineno + (lineno - 1), funcname, messages,
                   translator_comments + python_translator_comments)

src/h/o/hortonworks-sandbox-HEAD/desktop/core/ext-py/Mako-0.7.2/mako/ext/babelplugin.py   hortonworks-sandbox(Download)
from StringIO import StringIO
 
from babel.messages.extract import extract_python
 
from mako import lexer, parsetree
        code = StringIO(code)
        for lineno, funcname, messages, python_translator_comments \
                in extract_python(code, keywords, comment_tags, options):
            yield (node.lineno + (lineno - 1), funcname, messages,
                   translator_comments + python_translator_comments)

src/o/p/openlibrary-HEAD/openlibrary/i18n/__init__.py   openlibrary(Download)
from babel.messages.pofile import read_po, write_po
from babel.messages.mofile import write_mo
from babel.messages.extract import extract_from_dir, extract_python
 
root = os.path.dirname(__file__)
        print >> web.debug, fileobj.name + ':', str(e)
        return []
    return extract_python(f, keywords, comment_tags, options)    
 
def extract_messages(dirs):

src/w/e/webapp-improved-HEAD/lib/Mako-0.4.1/mako/ext/babelplugin.py   webapp-improved(Download)
from StringIO import StringIO
 
from babel.messages.extract import extract_python
 
from mako import lexer, parsetree
        code = StringIO(code)
        for lineno, funcname, messages, python_translator_comments \
                in extract_python(code, keywords, comment_tags, options):
            yield (node.lineno + (lineno - 1), funcname, messages,
                   translator_comments + python_translator_comments)

src/s/o/socorro-HEAD/webapp-django/vendor/src/tower/tower/__init__.py   socorro(Download)
                                      ungettext as django_nugettext)
 
from babel.messages.extract import extract_python
from jinja2 import ext
 
def extract_tower_python(fileobj, keywords, comment_tags, options):
    for lineno, funcname, message, comments in \
            list(extract_python(fileobj, keywords, comment_tags, options)):
 
        message = tweak_message(message)

src/m/e/me-HEAD/libs/mako/ext/babelplugin.py   me(Download)
from StringIO import StringIO
 
from babel.messages.extract import extract_python
 
from mako import lexer, parsetree, util
        code = StringIO(code)
        for lineno, funcname, messages, python_translator_comments \
                in extract_python(code, keywords, comment_tags, options):
            yield (node.lineno + (lineno - 1), funcname, messages,
                   translator_comments + python_translator_comments)

src/t/o/tower-0.4.1/tower/__init__.py   tower(Download)
                                      ungettext as django_nugettext)
 
from babel.messages.extract import extract_python
from jinja2 import ext
 
def extract_tower_python(fileobj, keywords, comment_tags, options):
    for lineno, funcname, message, comments in \
            list(extract_python(fileobj, keywords, comment_tags, options)):
 
        message = tweak_message(message)

src/g/a/gae-skeleton-HEAD/demo/lib/mako/ext/babelplugin.py   gae-skeleton(Download)
from StringIO import StringIO
 
from babel.messages.extract import extract_python
 
from mako import lexer, parsetree
        code = StringIO(code)
        for lineno, funcname, messages, python_translator_comments \
                in extract_python(code, keywords, comment_tags, options):
            yield (node.lineno + (lineno - 1), funcname, messages,
                   translator_comments + python_translator_comments)

src/t/o/tower-HEAD/tower/__init__.py   tower(Download)
                                      ungettext as django_nugettext)
 
from babel.messages.extract import extract_python
from jinja2 import ext
 
def extract_tower_python(fileobj, keywords, comment_tags, options):
    for lineno, funcname, message, comments in \
            list(extract_python(fileobj, keywords, comment_tags, options)):
 
        message = tweak_message(message)

  1 | 2 | 3 | 4 | 5 | 6  Next