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


Python senf.bytes2fsn函数代码示例

本文整理汇总了Python中senf.bytes2fsn函数的典型用法代码示例。如果您正苦于以下问题:Python bytes2fsn函数的具体用法?Python bytes2fsn怎么用?Python bytes2fsn使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了bytes2fsn函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_response

 def test_response(self):
     with temp_filename() as fn:
         mock = Mock(resp=bytes2fsn(b"resp", None))
         remote = QuodLibetUnixRemote(None, mock)
         remote._callback(b"\x00foo\x00" + fsn2bytes(fn, None) + b"\x00")
         self.assertEqual(mock.lines, [bytes2fsn(b"foo", None)])
         with open(fn, "rb") as h:
             self.assertEqual(h.read(), b"resp")
开发者ID:LudoBike,项目名称:quodlibet,代码行数:8,代码来源:test_remote.py

示例2: from_dump

    def from_dump(self, text):
        """Parses the text created with to_dump and adds the found tags.

        Args:
            text (bytes)
        """

        for line in text.split(b"\n"):
            if not line:
                continue
            parts = line.split(b"=")
            key = decode(parts[0])
            val = b"=".join(parts[1:])
            if key == "~format":
                pass
            elif key in FILESYSTEM_TAGS:
                self.add(key, bytes2fsn(val, "utf-8"))
            elif key.startswith("~#"):
                try:
                    self.add(key, int(val))
                except ValueError:
                    try:
                        self.add(key, float(val))
                    except ValueError:
                        pass
            else:
                self.add(key, decode(val))
开发者ID:zsau,项目名称:quodlibet,代码行数:27,代码来源:_audio.py

示例3: test_fifo

 def test_fifo(self):
     mock = Mock()
     remote = QuodLibetUnixRemote(None, mock)
     remote._callback(b"foo\n")
     remote._callback(b"bar\nbaz")
     self.assertEqual(
         mock.lines, [bytes2fsn(b, None) for b in [b"foo", b"bar", b"baz"]])
开发者ID:LudoBike,项目名称:quodlibet,代码行数:7,代码来源:test_remote.py

示例4: test_path

    def test_path(self):
        try:
            path = bytes2fsn(b"\xff\xff", "utf-8")
        except ValueError:
            return

        assert decode_value("~filename", path) == fsn2text(path)
开发者ID:Muges,项目名称:quodlibet,代码行数:7,代码来源:test_formats__audio.py

示例5: parse_xdg_user_dirs

def parse_xdg_user_dirs(data):
    """Parses xdg-user-dirs and returns a dict of keys and paths.

    The paths depend on the content of environ while calling this function.
    See http://www.freedesktop.org/wiki/Software/xdg-user-dirs/

    Args:
        data (bytes)

    Can't fail (but might return garbage).
    """

    assert isinstance(data, bytes)

    paths = {}
    for line in data.splitlines():
        if line.startswith(b"#"):
            continue
        parts = line.split(b"=", 1)
        if len(parts) <= 1:
            continue
        key = parts[0]
        try:
            values = shlex.split(bytes2fsn(parts[1], "utf-8"))
        except ValueError:
            continue
        if len(values) != 1:
            continue
        paths[key] = os.path.normpath(expandvars(values[0]))

    return paths
开发者ID:elfalem,项目名称:quodlibet,代码行数:31,代码来源:path.py

示例6: _callback

    def _callback(self, data):
        try:
            messages = list(fifo.split_message(data))
        except ValueError:
            print_w("invalid message: %r" % data)
            return

        for command, path in messages:
            command = bytes2fsn(command, None)
            response = self._cmd_registry.handle_line(self._app, command)
            if path is not None:
                path = bytes2fsn(path, None)
                with open(path, "wb") as h:
                    if response is not None:
                        assert isinstance(response, fsnative)
                        h.write(fsn2bytes(response, None))
开发者ID:LudoBike,项目名称:quodlibet,代码行数:16,代码来源:remote.py

示例7: glib2fsn

def glib2fsn(path):
    """Takes a glib filename and returns a fsnative path"""

    if PY2:
        return bytes2fsn(path, "utf-8")
    else:
        return path
开发者ID:elfalem,项目名称:quodlibet,代码行数:7,代码来源:path.py

示例8: test_file_encoding

    def test_file_encoding(self):
        if os.name == "nt":
            return

        f = self.add_file(bytes2fsn(b"\xff\xff\xff\xff - cover.jpg", None))
        self.assertTrue(isinstance(self.song("album"), text_type))
        h = self._find_cover(self.song)
        self.assertEqual(h.name, normalize_path(f))
开发者ID:ZDBioHazard,项目名称:quodlibet,代码行数:8,代码来源:test_util_cover.py

示例9: get_exclude_dirs

def get_exclude_dirs():
    """Returns a list of paths which should be ignored during scanning

    Returns:
        list
    """

    paths = split_scan_dirs(bytes2fsn(config.getbytes("library", "exclude"), "utf-8"))
    return [expanduser(p) for p in paths]
开发者ID:piotrdrag,项目名称:quodlibet,代码行数:9,代码来源:library.py

示例10: get_scan_dirs

def get_scan_dirs():
    """Returns a list of paths which should be scanned

    Returns:
        list
    """

    joined_paths = bytes2fsn(config.getbytes("settings", "scan"), "utf-8")
    return [expanduser(p) for p in split_scan_dirs(joined_paths)]
开发者ID:piotrdrag,项目名称:quodlibet,代码行数:9,代码来源:library.py

示例11: restore

 def restore(self):
     data = config.getbytes("browsers", "filesystem", b"")
     try:
         paths = bytes2fsn(data, "utf-8")
     except ValueError:
         return
     if not paths:
         return
     self.__select_paths(paths.split("\n"))
开发者ID:LudoBike,项目名称:quodlibet,代码行数:9,代码来源:filesystem.py

示例12: selection_get_filenames

def selection_get_filenames(selection_data):
    """Extracts the filenames of songs set with selection_set_songs()
    from a Gtk.SelectionData.
    """

    data_type = selection_data.get_data_type()
    assert data_type.name() == "text/x-quodlibet-songs"

    items = selection_data.get_data().split(b"\x00")
    return [bytes2fsn(i, "utf-8") for i in items]
开发者ID:elfalem,项目名称:quodlibet,代码行数:10,代码来源:__init__.py

示例13: test_main

    def test_main(self):
        v = fsnative(u"foo")
        self.assertTrue(isinstance(v, fsnative))

        v2 = glib2fsn(fsn2glib(v))
        self.assertTrue(isinstance(v2, fsnative))
        self.assertEqual(v, v2)

        v3 = bytes2fsn(fsn2bytes(v, "utf-8"), "utf-8")
        self.assertTrue(isinstance(v3, fsnative))
        self.assertEqual(v, v3)
开发者ID:Muges,项目名称:quodlibet,代码行数:11,代码来源:test_util.py

示例14: escape_filename

def escape_filename(s):
    """Escape a string in a manner suitable for a filename.

    Args:
        s (text_type)
    Returns:
        fsnative
    """

    s = text_type(s)
    s = quote(s.encode("utf-8"), safe=b"")
    if isinstance(s, text_type):
        s = s.encode("ascii")
    return bytes2fsn(s, "utf-8")
开发者ID:elfalem,项目名称:quodlibet,代码行数:14,代码来源:path.py

示例15: test_uri

    def test_uri(self):
        # On windows where we have unicode paths (windows encoding is utf-16)
        # we need to encode to utf-8 first, then escape.
        # On linux we take the byte stream and escape it.
        # see g_filename_to_uri

        if os.name == "nt":
            f = AudioFile({"~filename": u"/\xf6\xe4.mp3", "title": "win"})
            self.failUnlessEqual(f("~uri"), "file:///%C3%B6%C3%A4.mp3")
        else:
            f = AudioFile({
                "~filename": bytes2fsn(b"/\x87\x12.mp3", None),
                "title": "linux",
            })
            self.failUnlessEqual(f("~uri"), "file:///%87%12.mp3")
开发者ID:Muges,项目名称:quodlibet,代码行数:15,代码来源:test_formats__audio.py


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