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

All Samples(58)  |  Call(29)  |  Derive(0)  |  Import(29)
Deduce the encoding of a source file from magic comment.

It does this in the same way as the `Python interpreter`__

.. __: http://docs.python.org/ref/encodings.html

The ``fp`` argument should be a seekable file object.

(From Jeff Dairiki)

        def parse_encoding(fp):
    """Deduce the encoding of a source file from magic comment.

    It does this in the same way as the `Python interpreter`__

    .. __: http://docs.python.org/ref/encodings.html

    The ``fp`` argument should be a seekable file object.

    (From Jeff Dairiki)
    """
    pos = fp.tell()
    fp.seek(0)
    try:
        line1 = fp.readline()
        has_bom = line1.startswith(codecs.BOM_UTF8)
        if has_bom:
            line1 = line1[len(codecs.BOM_UTF8):]

        m = PYTHON_MAGIC_COMMENT_re.match(line1)
        if not m:
            try:
                import parser
                parser.suite(line1.decode('latin-1'))
            except (ImportError, SyntaxError):
                # Either it's a real syntax error, in which case the source is
                # not valid python source, or line2 is a continuation of line1,
                # in which case we don't want to scan line2 for a magic
                # comment.
                pass
            else:
                line2 = fp.readline()
                m = PYTHON_MAGIC_COMMENT_re.match(line2)

        if has_bom:
            if m:
                raise SyntaxError(
                    "python refuses to compile code with both a UTF8 "
                    "byte-order-mark and a magic encoding comment")
            return 'utf_8'
        elif m:
            return m.group(1).decode('latin-1')
        else:
            return None
    finally:
        fp.seek(pos)
        


src/k/u/kuma-lib-HEAD/packages/Babel/babel/messages/extract.py   kuma-lib(Download)
from tokenize import generate_tokens, COMMENT, NAME, OP, STRING
 
from babel.util import parse_encoding, pathmatch, relpath
from textwrap import dedent
 
    comment_tag = None
 
    encoding = parse_encoding(fileobj) or options.get('encoding', 'iso-8859-1')
 
    tokens = generate_tokens(fileobj.readline)

src/i/n/input-lib-HEAD/packages/Babel/babel/messages/extract.py   input-lib(Download)
from tokenize import generate_tokens, COMMENT, NAME, OP, STRING
 
from babel.util import parse_encoding, pathmatch, relpath
from textwrap import dedent
 
    comment_tag = None
 
    encoding = parse_encoding(fileobj) or options.get('encoding', 'iso-8859-1')
 
    tokens = generate_tokens(fileobj.readline)

src/p/l/playdoh-lib-HEAD/lib/python/babel/messages/extract.py   playdoh-lib(Download)
from tokenize import generate_tokens, COMMENT, NAME, OP, STRING
 
from babel.util import parse_encoding, pathmatch, relpath
from textwrap import dedent
 
    comment_tag = None
 
    encoding = parse_encoding(fileobj) or options.get('encoding', 'iso-8859-1')
 
    tokens = generate_tokens(fileobj.readline)

src/b/a/Babel-1.3/babel/messages/extract.py   Babel(Download)
from tokenize import generate_tokens, COMMENT, NAME, OP, STRING
 
from babel.util import parse_encoding, pathmatch, relpath
from babel._compat import PY2, text_type
from textwrap import dedent
    comment_tag = None
 
    encoding = parse_encoding(fileobj) or options.get('encoding', 'iso-8859-1')
 
    if PY2:

src/b/a/Babel-CLDR-HEAD/babel/messages/extract.py   Babel-CLDR(Download)
from tokenize import generate_tokens, COMMENT, NAME, OP, STRING
 
from babel.util import parse_encoding, pathmatch, relpath
from textwrap import dedent
 
    comment_tag = None
 
    encoding = parse_encoding(fileobj) or options.get('encoding', 'iso-8859-1')
 
    tokens = generate_tokens(fileobj.readline)

src/p/r/proofofexistence-HEAD/babel/messages/extract.py   proofofexistence(Download)
from tokenize import generate_tokens, COMMENT, NAME, OP, STRING
 
from babel.util import parse_encoding, pathmatch, relpath
from babel._compat import PY2, text_type
from textwrap import dedent
    comment_tag = None
 
    encoding = parse_encoding(fileobj) or options.get('encoding', 'iso-8859-1')
 
    if PY2:

src/b/l/bloodhound-HEAD/trac/trac/dist.py   bloodhound(Download)
    from babel.messages.pofile import read_po
    from babel.support import Translations
    from babel.util import parse_encoding
 
    _GENSHI_MARKUP_SEARCH = re.compile(r'\[[0-9]+:').search
        comment_tag = None
 
        encoding = parse_encoding(fileobj) \
                   or options.get('encoding', 'iso-8859-1')
        kwargs_maps = _DEFAULT_KWARGS_MAPS.copy()

src/t/r/Trac-1.0.1/trac/dist.py   Trac(Download)
    from babel.messages.pofile import read_po
    from babel.support import Translations
    from babel.util import parse_encoding
 
    _GENSHI_MARKUP_SEARCH = re.compile(r'\[[0-9]+:').search
        comment_tag = None
 
        encoding = parse_encoding(fileobj) \
                   or options.get('encoding', 'iso-8859-1')
        kwargs_maps = _DEFAULT_KWARGS_MAPS.copy()

src/t/r/trac-HEAD/trac/dist.py   trac(Download)
    from babel.messages.pofile import read_po
    from babel.support import Translations
    from babel.util import parse_encoding
 
    _GENSHI_MARKUP_SEARCH = re.compile(r'\[[0-9]+:').search
        comment_tag = None
 
        encoding = str(parse_encoding(fileobj) or
                       options.get('encoding', 'iso-8859-1'))
        kwargs_maps = _DEFAULT_KWARGS_MAPS.copy()

Previous  1 | 2 | 3