本文整理汇总了Python中quodlibet.pattern.Pattern类的典型用法代码示例。如果您正苦于以下问题:Python Pattern类的具体用法?Python Pattern怎么用?Python Pattern使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Pattern类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_sort_combine
def test_sort_combine(s):
pat = Pattern('<album> <artist>')
s.failUnlessEqual(pat.format_list(s.h),
{(u'Album5 Artist1', u'SortAlbum5 SortA1'),
(u'Album5 ', u'SortAlbum5 SortA2'),
(u'Album5 Artist3', u'SortAlbum5 Artist3')})
pat = Pattern('x <artist> <album>')
s.failUnlessEqual(pat.format_list(s.h),
{(u'x Artist1 Album5', u'x SortA1 SortAlbum5'),
(u'x Album5', u'x SortA2 SortAlbum5'),
(u'x Artist3 Album5', u'x Artist3 SortAlbum5')})
pat = Pattern(' <artist> <album> xx')
s.failUnlessEqual(pat.format_list(s.h),
{(u' Artist1 Album5 xx', u' SortA1 SortAlbum5 xx'),
(u' Album5 xx', u' SortA2 SortAlbum5 xx'),
(u' Artist3 Album5 xx', u' Artist3 SortAlbum5 xx')})
pat = Pattern('<album> <tracknumber> <artist>')
s.failUnlessEqual(pat.format_list(s.h),
{(u'Album5 7/8 Artist1', u'SortAlbum5 7/8 SortA1'),
(u'Album5 7/8 ', u'SortAlbum5 7/8 SortA2'),
(u'Album5 7/8 Artist3', u'SortAlbum5 7/8 Artist3')})
pat = Pattern('<tracknumber> <album> <artist>')
s.failUnlessEqual(pat.format_list(s.h),
{(u'7/8 Album5 Artist1', u'7/8 SortAlbum5 SortA1'),
(u'7/8 Album5 ', u'7/8 SortAlbum5 SortA2'),
(u'7/8 Album5 Artist3', u'7/8 SortAlbum5 Artist3')})
开发者ID:LudoBike,项目名称:quodlibet,代码行数:26,代码来源:test_pattern.py
示例2: test_same2
def test_same2(s):
fpat = FileFromPattern('<~filename>')
pat = Pattern('<~filename>')
s.assertEquals(fpat.format_list(s.a),
{(fpat.format(s.a), fpat.format(s.a))})
s.assertEquals(pat.format_list(s.a),
{(pat.format(s.a), pat.format(s.a))})
开发者ID:LudoBike,项目名称:quodlibet,代码行数:7,代码来源:test_pattern.py
示例3: plugin_on_song_started
def plugin_on_song_started(self, song):
self.song = song
pat_str = self.config_get(*Config.PAT_PLAYING)
pattern = Pattern(pat_str)
status = (pattern.format(song) if song
else self.config_get(Config.STATUS_SONGLESS, ""))
self._set_status(status)
开发者ID:Muges,项目名称:quodlibet,代码行数:7,代码来源:mqtt.py
示例4: plugin_songs
def plugin_songs(self, songs):
# Check this is a launch, not a configure
if self.chosen_site:
url_pat = self.get_url_pattern(self.chosen_site)
pat = Pattern(url_pat)
urls = set()
for song in songs:
# Generate a sanitised AudioFile; allow through most tags
subs = AudioFile()
for k in (USER_TAGS + MACHINE_TAGS):
vals = song.comma(k)
if vals:
try:
encoded = unicode(vals).encode('utf-8')
subs[k] = (encoded if k == 'website'
else quote_plus(encoded))
# Dodgy unicode problems
except KeyError:
print_d("Problem with %s tag values: %r"
% (k, vals))
url = str(pat.format(subs))
if not url:
print_w("Couldn't build URL using \"%s\"."
"Check your pattern?" % url_pat)
return
# Grr, set.add() should return boolean...
if url not in urls:
urls.add(url)
website(url)
开发者ID:urielz,项目名称:quodlibet,代码行数:29,代码来源:website_search.py
示例5: test_escape_slash
def test_escape_slash(s):
fpat = s._create('<~filename>')
pat = Pattern('<~filename>')
wpat = s._create(r'\\<artist>\\ "<title>')
s.assertTrue(fpat.format(s.a).startswith("_path_to_a.mp3"))
s.assertTrue(pat.format(s.a).startswith("/path/to/a"))
if os.name != "nt":
s.assertTrue(wpat.format(s.a).startswith("\\Artist\\ \"Title5"))
else:
# FIXME..
pass
开发者ID:SimonLarsen,项目名称:quodlibet,代码行数:11,代码来源:test_pattern.py
示例6: test_sort_multiply
def test_sort_multiply(s):
pat = Pattern('<artist> <artist>')
s.failUnlessEqual(pat.format_list(s.h),
{(u'Artist1 Artist1', u'SortA1 SortA1'),
(u' Artist1', u'SortA2 SortA1'),
(u'Artist3 Artist1', u'Artist3 SortA1'),
(u'Artist1 ', u'SortA1 SortA2'),
(u' ', u'SortA2 SortA2'),
(u'Artist3 ', u'Artist3 SortA2'),
(u'Artist1 Artist3', u'SortA1 Artist3'),
(u' Artist3', u'SortA2 Artist3'),
(u'Artist3 Artist3', u'Artist3 Artist3')})
开发者ID:LudoBike,项目名称:quodlibet,代码行数:12,代码来源:test_pattern.py
示例7: test_same
def test_same(s):
pat = Pattern('<~basename> <title>')
s.failUnlessEqual(pat.format_list(s.a),
{(pat.format(s.a), pat.format(s.a))})
pat = Pattern('/a<genre|/<genre>>/<title>')
s.failUnlessEqual(pat.format_list(s.a),
{(pat.format(s.a), pat.format(s.a))})
开发者ID:LudoBike,项目名称:quodlibet,代码行数:7,代码来源:test_pattern.py
示例8: __init__
def __init__(self, name=None, command=None, pattern="<~filename>",
unique=False, parameter=None, max_args=10000,
warn_threshold=100):
JSONObject.__init__(self, name)
self.command = str(command or "")
self.pattern = str(pattern)
self.unique = bool(unique)
self.max_args = max_args
self.parameter = str(parameter or "")
self.__pat = Pattern(self.pattern)
self.warn_threshold = warn_threshold
开发者ID:Konzertheld,项目名称:quodlibet,代码行数:11,代码来源:custom_commands.py
示例9: test_tag_query_regex
def test_tag_query_regex(s):
pat = Pattern("<album=/'only'/|matched|not matched>")
s.assertEquals(pat.format(s.g), 'matched')
pat = Pattern("<album=/The .+ way/|matched|not matched>")
s.assertEquals(pat.format(s.g), 'matched')
pat = Pattern("</The .+ way/|matched|not matched>")
s.assertEquals(pat.format(s.g), 'not matched')
开发者ID:SimonLarsen,项目名称:quodlibet,代码行数:7,代码来源:test_pattern.py
示例10: test_tag_query_escaped_pipe
def test_tag_query_escaped_pipe(s):
pat = Pattern(r'<albumartist=/Lee\|Bob/|matched|not matched>')
s.assertEquals(pat.format(s.g), 'matched')
pat = Pattern(r'<albumartist=\||matched|not matched>')
s.assertEquals(pat.format(s.g), 'not matched')
pat = Pattern(r'<comment=/Trouble\|Strife/|matched|not matched>')
s.assertEquals(pat.format(s.g), 'matched')
开发者ID:SimonLarsen,项目名称:quodlibet,代码行数:7,代码来源:test_pattern.py
示例11: test_space
def test_space(self):
pat = Pattern("a ")
self.assertEqual(pat.format(self.a), "a ")
pat = Pattern(" a")
self.assertEqual(pat.format(self.a), " a")
pat = Pattern("a\n\n")
self.assertEqual(pat.format(self.a), "a\n\n")
开发者ID:LudoBike,项目名称:quodlibet,代码行数:7,代码来源:test_pattern.py
示例12: test_sort
def test_sort(s):
pat = Pattern('<album>')
s.failUnlessEqual(pat.format_list(s.f),
{(u'Best Of', u'Best Of')})
pat = Pattern('<album>')
s.failUnlessEqual(pat.format_list(s.h), {(u'Album5', u'SortAlbum5')})
pat = Pattern('<artist>')
s.failUnlessEqual(pat.format_list(s.h), {(u'Artist1', u'SortA1'),
(u'', u'SortA2'),
(u'Artist3', u'Artist3')})
pat = Pattern('<artist> x')
s.failUnlessEqual(pat.format_list(s.h), {(u'Artist1 x', u'SortA1 x'),
(u' x', u'SortA2 x'),
(u'Artist3 x', u'Artist3 x')})
开发者ID:LudoBike,项目名称:quodlibet,代码行数:14,代码来源:test_pattern.py
示例13: test_tag_internal
def test_tag_internal(self):
if os.name != "nt":
pat = Pattern("<~filename='/path/to/a.mp3'|matched|not matched>")
self.assertEquals(pat.format(self.a), 'matched')
pat = Pattern(
"<~filename=/\\/path\\/to\\/a.mp3/|matched|not matched>")
self.assertEquals(pat.format(self.a), 'matched')
else:
pat = Pattern(
r"<~filename='C:\\\path\\\to\\\a.mp3'|matched|not matched>")
self.assertEquals(pat.format(self.a), 'matched')
开发者ID:LudoBike,项目名称:quodlibet,代码行数:11,代码来源:test_pattern.py
示例14: website_for
def website_for(pat: Pattern, song: AudioFile) -> Optional[str]:
"""Gets a utf-8 encoded string for a website from the given pattern"""
# Generate a sanitised AudioFile; allow through most tags
subs = AudioFile()
# See issue 2762
for k in (USER_TAGS + MACHINE_TAGS + ['~filename']):
vals = song.comma(k)
if vals:
try:
# Escaping ~filename stops ~dirname ~basename etc working
# But not escaping means ? % & will cause problems.
# Who knows what user wants to do with /, seems better raw.
subs[k] = (vals if k in ['website', '~filename']
else quote_plus(vals))
except KeyError:
print_d("Problem with %s tag values: %r" % (k, vals))
return pat.format(subs) or None
开发者ID:LudoBike,项目名称:quodlibet,代码行数:18,代码来源:website_search.py
示例15: test_sort_tied
def test_sort_tied(s):
pat = Pattern('<~artist~album>')
s.failUnlessEqual(pat.format_list(s.h), {(u'Artist1', u'SortA1'),
(u'', u'SortA2'),
(u'Artist3', u'Artist3'),
(u'Album5', u'SortAlbum5')})
pat = Pattern('<~album~artist>')
s.failUnlessEqual(pat.format_list(s.h), {(u'Artist1', u'SortA1'),
(u'', u'SortA2'),
(u'Artist3', u'Artist3'),
(u'Album5', u'SortAlbum5')})
pat = Pattern('<~artist~artist>')
s.failUnlessEqual(pat.format_list(s.h), {(u'Artist1', u'SortA1'),
(u'', u'SortA2'),
(u'Artist3', u'Artist3')})
开发者ID:LudoBike,项目名称:quodlibet,代码行数:15,代码来源:test_pattern.py
示例16: plugin_on_paused
def plugin_on_paused(self):
pat_str = self.config_get(*Config.PAT_PAUSED)
pattern = Pattern(pat_str)
self.status = pattern.format(self.song) if self.song else ""
self._set_status(self.status)
开发者ID:Muges,项目名称:quodlibet,代码行数:5,代码来源:mqtt.py
示例17: test_number_dot_title_dot
def test_number_dot_title_dot(s):
pat = Pattern('<tracknumber>. <title>.')
s.assertEquals(pat.format(s.a), '5/6. Title5.')
s.assertEquals(pat.format(s.b), '6. Title6.')
s.assertEquals(pat.format(s.c), '. test/subdir.')
开发者ID:SimonLarsen,项目名称:quodlibet,代码行数:5,代码来源:test_pattern.py
示例18: Command
class Command(JSONObject):
"""
Wraps an arbitrary shell command and its argument pattern.
Serialises as JSON for some editability
"""
NAME = _("Command")
FIELDS = {
"name": Field(_("name"), _("The name of this command")),
"command": Field(_("command"), _("The shell command syntax to run")),
"parameter": Field(_("parameter"),
_("If specified, a parameter whose occurrences in "
"the command will be substituted with a "
"user-supplied value, e.g. by using 'PARAM' "
"all instances of '{PARAM}' in your command will "
"have the value prompted for when run")),
"pattern": Field(_("pattern"),
_("The QL pattern, e.g. <~filename>, to use to "
"compute a value for the command. For playlists, "
"this also supports virtual tags <~playlistname> "
"and <~#playlistindex>.")),
"unique": Field(_("unique"),
_("If set, this will remove duplicate computed values "
"of the pattern")),
"max_args": Field(_("max args"),
_("The maximum number of argument to pass to the "
"command at one time (like xargs)")),
}
def __init__(self, name=None, command=None, pattern="<~filename>",
unique=False, parameter=None, max_args=10000,
warn_threshold=50):
JSONObject.__init__(self, name)
self.command = str(command or "")
self.pattern = str(pattern)
self.unique = bool(unique)
self.max_args = max_args
self.parameter = str(parameter or "")
self.__pat = Pattern(self.pattern)
self.warn_threshold = warn_threshold
def run(self, songs, playlist_name=None):
"""
Runs this command on `songs`,
splitting into multiple calls if necessary.
`playlist_name` if populated contains the Playlist's name.
"""
args = []
template_vars = {}
if self.parameter:
value = GetStringDialog(None, _("Input value"),
_("Value for %s?") % self.parameter).run()
template_vars[self.parameter] = value
if playlist_name:
print_d("Playlist command for %s" % playlist_name)
template_vars["PLAYLIST"] = playlist_name
self.command = self.command.format(**template_vars)
print_d("Actual command=%s" % self.command)
for i, song in enumerate(songs):
wrapped = SongWrapper(song)
if playlist_name:
wrapped["~playlistname"] = playlist_name
wrapped["~playlistindex"] = str(i + 1)
wrapped["~#playlistindex"] = i + 1
arg = str(self.__pat.format(wrapped))
if not arg:
print_w("Couldn't build shell command using \"%s\"."
"Check your pattern?" % self.pattern)
break
if not self.unique:
args.append(arg)
elif arg not in args:
args.append(arg)
max = int((self.max_args or 10000))
com_words = self.command.split(" ")
while args:
print_d("Running %s with %d substituted arg(s) (of %d%s total)..."
% (self.command, min(max, len(args)), len(args),
" unique" if self.unique else ""))
util.spawn(com_words + args[:max])
args = args[max:]
@property
def playlists_only(self):
return ("~playlistname" in self.pattern
or "playlistindex" in self.pattern)
def __str__(self):
return 'Command: "{command} {pattern}"'.format(**dict(self.data))
开发者ID:LudoBike,项目名称:quodlibet,代码行数:95,代码来源:custom_commands.py
示例19: Command
class Command(JSONObject):
"""
Wraps an arbitrary shell command and its argument pattern.
Serialises as JSON for some editability
"""
NAME = _("Command")
FIELDS = {
"name": Field(_("name"), _("The name of this command")),
"command": Field(_("command"), _("The shell command syntax to run")),
"parameter": Field(_("parameter"),
_("If specified, a parameter whose occurrences in "
"the command will be substituted with a "
"user-supplied value, e.g. by using 'PARAM' "
"all instances of '{PARAM}' in your command will "
"have the value prompted for when run")),
"pattern": Field(_("pattern"),
_("The QL pattern, e.g. <~filename>, to use to "
"compute a value for the command")),
"unique": Field(_("unique"),
_("If set, this will remove duplicate computed values "
"of the pattern")),
"max_args": Field(_("max args"),
_("The maximum number of argument to pass to the "
"command at one time (like xargs)")),
}
def __init__(self, name=None, command=None, pattern="<~filename>",
unique=False, parameter=None, max_args=10000,
warn_threshold=100):
JSONObject.__init__(self, name)
self.command = str(command or "")
self.pattern = str(pattern)
self.unique = bool(unique)
self.max_args = max_args
self.parameter = str(parameter or "")
self.__pat = Pattern(self.pattern)
self.warn_threshold = warn_threshold
def run(self, songs):
"""
Runs this command on `songs`,
splitting into multiple calls if necessary
"""
args = []
if self.parameter:
value = GetStringDialog(None, _("Input value"),
_("Value for %s?") % self.parameter).run()
self.command = self.command.format(**{self.parameter: value})
print_d("Actual command=%s" % self.command)
for song in songs:
arg = str(self.__pat.format(song))
if not arg:
print_w("Couldn't build shell command using \"%s\"."
"Check your pattern?" % self.pattern)
break
if not self.unique:
args.append(arg)
elif arg not in args:
args.append(arg)
max = int((self.max_args or 10000))
com_words = self.command.split(" ")
while args:
print_d("Running %s with %d substituted arg(s) (of %d%s total)..."
% (self.command, min(max, len(args)), len(args),
" unique" if self.unique else ""))
util.spawn(com_words + args[:max])
args = args[max:]
def __str__(self):
return "Command= {command} {pattern}".format(**dict(self.data))
开发者ID:Konzertheld,项目名称:quodlibet,代码行数:77,代码来源:custom_commands.py
示例20: test_conditional_equals_unicode
def test_conditional_equals_unicode(s):
pat = Pattern(u'<artist=Artist|matched|not matched>')
s.assertEquals(pat.format(s.g), 'not matched')
pat = Pattern(u'<artist=un élève français|matched|not matched>')
s.assertEquals(pat.format(s.g), 'matched')
开发者ID:SimonLarsen,项目名称:quodlibet,代码行数:5,代码来源:test_pattern.py
注:本文中的quodlibet.pattern.Pattern类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论