Пример #1
0
def frame_from_fsnative(arg):
    """Takes item from argv and returns ascii native str
    or raises ValueError.
    """

    assert isinstance(arg, fsnative)

    text = fsn2text(arg, strict=True)
    return text.encode("ascii").decode("ascii")
Пример #2
0
def frame_from_fsnative(arg):
    """Takes item from argv and returns ascii native str
    or raises ValueError.
    """

    assert isinstance(arg, fsnative)

    text = fsn2text(arg, strict=True)
    if PY2:
        return text.encode("ascii")
    else:
        return text.encode("ascii").decode("ascii")
Пример #3
0
def frame_from_fsnative(arg):
    """Takes item from argv and returns ascii native str
    or raises ValueError.
    """

    assert isinstance(arg, fsnative)

    text = fsn2text(arg)
    if arg != text2fsn(text):
        raise ValueError("%r can't be decoded" % arg)
    if PY2:
        return text.encode("ascii")
    else:
        return text.encode("ascii").decode("ascii")
def value_from_fsnative(arg, escape):
    """Takes an item from argv and returns a text_type value without
    surrogate escapes or raises ValueError.
    """

    assert isinstance(arg, fsnative)

    if escape:
        bytes_ = fsn2bytes(arg, "utf-8")
        if PY2:
            bytes_ = bytes_.decode("string_escape")
        else:
            bytes_ = codecs.escape_decode(bytes_)[0]
        arg = bytes2fsn(bytes_, "utf-8")

    text = fsn2text(arg, strict=True)
    return text
Пример #5
0
def value_from_fsnative(arg, escape):
    """Takes an item from argv and returns a text_type value without
    surrogate escapes or raises ValueError.
    """

    assert isinstance(arg, fsnative)

    if escape:
        bytes_ = fsn2bytes(arg, "utf-8")
        if PY2:
            bytes_ = bytes_.decode("string_escape")
        else:
            bytes_ = codecs.escape_decode(bytes_)[0]
        arg = bytes2fsn(bytes_, "utf-8")

    text = fsn2text(arg, strict=True)
    return text
Пример #6
0
def value_from_fsnative(arg, escape):
    """Takes an item from argv and returns a str value without
    surrogate escapes or raises ValueError.
    """

    assert isinstance(arg, fsnative)

    if escape:
        bytes_ = fsn2bytes(arg)
        # With py3.7 this has started to warn for invalid escapes, but we
        # don't control the input so ignore it.
        with warnings.catch_warnings():
            warnings.simplefilter("ignore")
            bytes_ = codecs.escape_decode(bytes_)[0]
        arg = bytes2fsn(bytes_)

    text = fsn2text(arg, strict=True)
    return text
Пример #7
0
def value_from_fsnative(arg, escape):
    """Takes an item from argv and returns a text_type value without
    surrogate escapes or raises ValueError.
    """

    assert isinstance(arg, fsnative)

    if escape:
        bytes_ = fsn2bytes(arg, "utf-8")
        if PY2:
            bytes_ = bytes_.decode("string_escape")
        else:
            bytes_ = codecs.escape_decode(bytes_)[0]
        arg = bytes2fsn(bytes_, "utf-8")

    text = fsn2text(arg)
    # only allow values which can be converted back
    if arg != text2fsn(text):
        raise ValueError("%r can't be decoded" % arg)
    return text
Пример #8
0
def value_from_fsnative(arg, escape):
    """Takes an item from argv and returns a text_type value without
    surrogate escapes or raises ValueError.
    """

    assert isinstance(arg, fsnative)

    if escape:
        bytes_ = fsn2bytes(arg)
        if PY2:
            bytes_ = bytes_.decode("string_escape")
        else:
            # With py3.7 this has started to warn for invalid escapes, but we
            # don't control the input so ignore it.
            with warnings.catch_warnings():
                warnings.simplefilter("ignore")
                bytes_ = codecs.escape_decode(bytes_)[0]
        arg = bytes2fsn(bytes_)

    text = fsn2text(arg, strict=True)
    return text
Пример #9
0
import shutil
from unittest import TestCase as BaseTestCase

try:
    import pytest
except ImportError:
    raise SystemExit("pytest missing: sudo apt-get install python-pytest")

from mutagen._compat import PY3
from mutagen._senf import text2fsn, fsn2text, path2fsn, mkstemp, fsnative

DATA_DIR = os.path.join(os.path.dirname(os.path.realpath(path2fsn(__file__))),
                        "data")
assert isinstance(DATA_DIR, fsnative)

if fsn2text(text2fsn(u"öäü")) != u"öäü":
    raise RuntimeError("This test suite needs a unicode locale encoding. "
                       "Try setting LANG=C.UTF-8")

# Make sure we see all deprecation warnings so we either have to avoid them
# or capture them in the test suite
warnings.simplefilter("always")
warnings.simplefilter("ignore", PendingDeprecationWarning)


def get_temp_copy(path):
    """Returns a copy of the file with the same extension"""

    ext = os.path.splitext(path)[-1]
    fd, filename = mkstemp(suffix=ext)
    os.close(fd)
Пример #10
0
try:
    import pytest
except ImportError:
    raise SystemExit("pytest missing: sudo apt-get install python-pytest")

from mutagen._compat import PY3, StringIO
from mutagen._senf import text2fsn, fsn2text, path2fsn, mkstemp, fsnative


DATA_DIR = os.path.join(
    os.path.dirname(os.path.realpath(path2fsn(__file__))), "data")
assert isinstance(DATA_DIR, fsnative)


if fsn2text(text2fsn(u"öäü")) != u"öäü":
    raise RuntimeError("This test suite needs a unicode locale encoding. "
                       "Try setting LANG=C.UTF-8")


def get_temp_copy(path):
    """Returns a copy of the file with the same extension"""

    ext = os.path.splitext(path)[-1]
    fd, filename = mkstemp(suffix=ext)
    os.close(fd)
    shutil.copy(path, filename)
    return filename


def get_temp_empty(ext=""):