本文整理汇总了Python中senf.fsn2text函数的典型用法代码示例。如果您正苦于以下问题:Python fsn2text函数的具体用法?Python fsn2text怎么用?Python fsn2text使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了fsn2text函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_main
def test_main(self):
self.assertEqual(decode_value("~#foo", 0.25), u"0.25")
self.assertEqual(decode_value("~#foo", 4), u"4")
self.assertEqual(decode_value("~#foo", "bar"), u"bar")
self.assertTrue(isinstance(decode_value("~#foo", "bar"), text_type))
path = fsnative(u"/foobar")
self.assertEqual(decode_value("~filename", path), fsn2text(path))
开发者ID:Muges,项目名称:quodlibet,代码行数:7,代码来源:test_formats__audio.py
示例2: _init_gettext
def _init_gettext(no_translations=False):
"""Call before using gettext helpers"""
if no_translations:
language = u"C"
else:
language = config.gettext("settings", "language")
if not language:
language = None
i18n.init(language)
# Use the locale dir in ../build/share/locale if there is one
base_dir = get_base_dir()
localedir = os.path.dirname(base_dir)
localedir = os.path.join(localedir, "build", "share", "locale")
if not os.path.isdir(localedir) and os.name == "nt":
# py2exe case
localedir = os.path.join(
base_dir, "..", "..", "share", "locale")
i18n.register_translation("quodlibet", localedir)
debug_text = environ.get("QUODLIBET_TEST_TRANS")
if debug_text is not None:
i18n.set_debug_text(fsn2text(debug_text))
开发者ID:ZDBioHazard,项目名称:quodlibet,代码行数:25,代码来源:_init.py
示例3: print_exc
def print_exc(exc_info=None, context=None):
"""Prints the stack trace of the current exception or the passed one.
Depending on the configuration will either print a short summary or the
whole stacktrace.
"""
if exc_info is None:
exc_info = sys.exc_info()
etype, value, tb = exc_info
if const.DEBUG:
string = u"".join(format_exception(etype, value, tb))
else:
# try to get a short error message pointing at the cause of
# the exception
text = u"".join(format_exception_only(etype, value))
try:
filename, lineno, name, line = extract_tb(tb)[-1]
except IndexError:
# no stack
string = text
else:
string = u"%s:%s:%s: %s" % (
fsn2text(path2fsn(os.path.basename(filename))),
lineno, name, text)
_print_message(string, context, False, "E", "red", "errors")
开发者ID:elfalem,项目名称:quodlibet,代码行数:28,代码来源:dprint.py
示例4: sort_key
def sort_key(song):
"""Sort by path so untagged albums have a good start order. Also
take into account the directory in case it's split in different folders
by medium.
"""
return util.human_sort_key(fsn2text(song("~filename")))
开发者ID:zsau,项目名称:quodlibet,代码行数:7,代码来源:widgets.py
示例5: arg2text
def arg2text(arg):
"""Like fsn2text but is strict by default and raises CommandError"""
try:
return fsn2text(arg, strict=True)
except ValueError as e:
raise CommandError(e)
开发者ID:ZDBioHazard,项目名称:quodlibet,代码行数:7,代码来源:commands.py
示例6: get_available_languages
def get_available_languages(domain):
"""Returns a list of available translations for a given gettext domain.
Args:
domain (str)
Returns:
List[text_type]
"""
locale_dir = gettext.bindtextdomain(domain)
if locale_dir is None:
return []
try:
entries = os.listdir(locale_dir)
except OSError:
return []
langs = [u"C"]
for lang in entries:
mo_path = os.path.join(
locale_dir, lang, "LC_MESSAGES", "%s.mo" % domain)
if os.path.exists(mo_path):
langs.append(fsn2text(path2fsn(lang)))
return langs
开发者ID:elfalem,项目名称:quodlibet,代码行数:25,代码来源:i18n.py
示例7: 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
示例8: scan
def scan(self, paths, exclude=[], cofuncid=None):
def need_yield(last_yield=[0]):
current = time.time()
if abs(current - last_yield[0]) > 0.015:
last_yield[0] = current
return True
return False
def need_added(last_added=[0]):
current = time.time()
if abs(current - last_added[0]) > 1.0:
last_added[0] = current
return True
return False
# first scan each path for new files
paths_to_load = []
for scan_path in paths:
print_d("Scanning %r." % scan_path)
desc = _("Scanning %s") % (fsn2text(unexpand(scan_path)))
with Task(_("Library"), desc) as task:
if cofuncid:
task.copool(cofuncid)
for real_path in iter_paths(scan_path, exclude=exclude):
if need_yield():
task.pulse()
yield
# skip unknown file extensions
if not formats.filter(real_path):
continue
# already loaded
if self.contains_filename(real_path):
continue
paths_to_load.append(real_path)
yield
# then (try to) load all new files
with Task(_("Library"), _("Loading files")) as task:
if cofuncid:
task.copool(cofuncid)
added = []
for real_path in task.gen(paths_to_load):
item = self.add_filename(real_path, False)
if item is not None:
added.append(item)
if len(added) > 100 or need_added():
self.add(added)
added = []
yield
if added and need_yield():
yield
if added:
self.add(added)
added = []
yield True
开发者ID:LudoBike,项目名称:quodlibet,代码行数:59,代码来源:libraries.py
示例9: cdf
def cdf(column, cell, model, iter, data):
row = model[iter]
filename = fsn2text(unexpand(row[0]))
function = row[1]
line = row[2]
cell.set_property(
"markup", "<b>%s</b> line %d\n\t%s" % (
util.escape(function), line, util.escape(filename)))
开发者ID:ZDBioHazard,项目名称:quodlibet,代码行数:8,代码来源:debugwindow.py
示例10: __init__
def __init__(self, parent, song):
title = _("Unable to save song")
fn_format = "<b>%s</b>" % util.escape(fsn2text(song("~basename")))
description = _("Saving %(file-name)s failed. The file may be "
"read-only, corrupted, or you do not have "
"permission to edit it.") % {"file-name": fn_format}
super(WriteFailedError, self).__init__(
parent, title, description)
开发者ID:ZDBioHazard,项目名称:quodlibet,代码行数:10,代码来源:_editutils.py
示例11: label_path
def label_path(path):
l = Gtk.Label(label="<a href='%s'>%s</a>" % (
fsn2uri(path), escape(fsn2text(unexpand(path)))),
use_markup=True,
ellipsize=Pango.EllipsizeMode.MIDDLE,
xalign=0,
selectable=True)
l.connect("activate-link", show_uri)
return l
开发者ID:LudoBike,项目名称:quodlibet,代码行数:10,代码来源:appinfo.py
示例12: _execute
def _execute(self, options, args):
if len(args) < 3:
raise CommandError(_("Not enough arguments"))
tag = fsn2text(args[0])
value = fsn2text(args[1])
paths = args[2:]
songs = []
for path in paths:
song = self.load_song(path)
if not song.can_change(tag):
raise CommandError(_("Can not set %r") % tag)
self.log("Add %r to %r" % (value, tag))
song.add(tag, value)
songs.append(song)
self.save_songs(songs)
开发者ID:LudoBike,项目名称:quodlibet,代码行数:20,代码来源:commands.py
示例13: __init__
def __init__(self, parent, path):
title = _("File exists")
fn_format = "<b>%s</b>" % util.escape(fsn2text(path2fsn(path)))
description = _("Replace %(file-name)s?") % {"file-name": fn_format}
super(ConfirmFileReplace, self).__init__(
parent, title, description, buttons=Gtk.ButtonsType.NONE)
self.add_button(_("_Cancel"), Gtk.ResponseType.CANCEL)
self.add_icon_button(_("_Replace File"), Icons.DOCUMENT_SAVE,
self.RESPONSE_REPLACE)
self.set_default_response(Gtk.ResponseType.CANCEL)
开发者ID:ZDBioHazard,项目名称:quodlibet,代码行数:12,代码来源:msg.py
示例14: unescape_filename
def unescape_filename(s):
"""Unescape a string in a manner suitable for a filename.
Args:
filename (fsnative)
Returns:
text_type
"""
assert isinstance(s, fsnative)
return fsn2text(unquote(s))
开发者ID:elfalem,项目名称:quodlibet,代码行数:12,代码来源:path.py
示例15: __preview
def __preview(self, pattern, songs):
rows = []
for song in songs:
match = pattern.match(song)
row = [fsn2text(song("~basename"))]
for header in pattern.headers:
row.append(match.get(header, u""))
rows.append(row)
headers = [_("File")] + pattern.headers
nicks = ["file"] + pattern.headers
print_table(rows, headers, nicks, nicks)
开发者ID:LudoBike,项目名称:quodlibet,代码行数:12,代码来源:commands.py
示例16: search
def search(self, data):
for name in self._names:
val = data.get(name)
if val is None:
# filename is the only real entry that's a path
if name == "filename":
val = fsn2text(data.get("~filename", fsnative()))
else:
val = data.get("~" + name, "")
if self.res.search(unicode(val)):
return True
for name in self.__intern:
if self.res.search(unicode(data(name))):
return True
for name in self.__fs:
if self.res.search(fsn2text(data(name))):
return True
return False
开发者ID:urielz,项目名称:quodlibet,代码行数:22,代码来源:_match.py
示例17: decode_value
def decode_value(tag, value):
"""Returns a unicode representation of the passed value, based on
the type and the tag it originated from.
Not reversible.
"""
if isinstance(value, text_type):
return value
elif isinstance(value, float):
return u"%.2f" % value
elif tag in FILESYSTEM_TAGS:
return fsn2text(value)
return text_type(value)
开发者ID:urielz,项目名称:quodlibet,代码行数:14,代码来源:_audio.py
示例18: parse_m3u
def parse_m3u(filename, library=None):
plname = fsn2text(path2fsn(os.path.basename(
os.path.splitext(filename)[0])))
filenames = []
with open(filename, "rb") as h:
for line in h:
line = line.strip()
if line.startswith("#"):
continue
else:
filenames.append(line)
return __parse_playlist(plname, filename, filenames, library)
开发者ID:urielz,项目名称:quodlibet,代码行数:14,代码来源:util.py
示例19: fsdecode
def fsdecode(path, note=True):
"""Takes a native path and returns unicode for displaying it.
Can not fail and can't be reversed.
"""
if isinstance(path, text_type):
return path
# XXX: glib paths on Windows
if os.name == "nt" and isinstance(path, bytes):
path = path.decode("utf-8")
return fsn2text(path)
开发者ID:faubiguy,项目名称:quodlibet,代码行数:14,代码来源:path.py
示例20: sort_by_func
def sort_by_func(tag):
"""Returns a fast sort function for a specific tag (or pattern).
Some keys are already in the sort cache, so we can use them."""
def artist_sort(song):
return song.sort_key[1][2]
if callable(tag):
return lambda song: human(tag(song))
elif tag == "artistsort":
return artist_sort
elif tag in FILESYSTEM_TAGS:
return lambda song: fsn2text(song(tag))
elif tag.startswith("~#") and "~" not in tag[2:]:
return lambda song: song(tag)
return lambda song: human(song(tag))
开发者ID:elfalem,项目名称:quodlibet,代码行数:15,代码来源:_audio.py
注:本文中的senf.fsn2text函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论