本文整理汇总了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")
示例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))
示例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"]])
示例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)
示例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
示例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))
示例7: glib2fsn
def glib2fsn(path):
"""Takes a glib filename and returns a fsnative path"""
if PY2:
return bytes2fsn(path, "utf-8")
else:
return path
示例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))
示例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]
示例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)]
示例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"))
示例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]
示例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)
示例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")
示例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")