本文整理匯總了Python中quodlibet.pattern.XMLFromMarkupPattern類的典型用法代碼示例。如果您正苦於以下問題:Python XMLFromMarkupPattern類的具體用法?Python XMLFromMarkupPattern怎麽用?Python XMLFromMarkupPattern使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了XMLFromMarkupPattern類的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: pattern
def pattern(pat, cap=True, esc=False, markup=False):
"""Return a 'natural' version of the pattern string for human-readable
bits. Assumes all tags in the pattern are present.
"""
from quodlibet.pattern import Pattern, XMLFromPattern, XMLFromMarkupPattern
class Fakesong(dict):
cap = False
def comma(self, key):
return " - ".join(self.list(key))
def list(self, key):
return [tag(k, self.cap) for k in tagsplit(key)]
list_separate = list
def __call__(self, tag, *args):
return 0 if '~#' in tag[:2] else self.comma(tag)
fakesong = Fakesong({'filename': tag('filename', cap)})
fakesong.cap = cap
try:
if markup:
p = XMLFromMarkupPattern(pat)
elif esc:
p = XMLFromPattern(pat)
else:
p = Pattern(pat)
except ValueError:
return _("Invalid pattern")
return p.format(fakesong)
示例2: test_escape
def test_escape(s):
pat = XMLFromMarkupPattern(r'\[b]')
s.assertEquals(pat.format(s.a), '[b]')
s._test_markup(pat.format(s.a))
pat = XMLFromMarkupPattern(r'\\[b]\\[/b]')
s.assertEquals(pat.format(s.a), r'\<b>\</b>')
s._test_markup(pat.format(s.a))
示例3: test_span
def test_span(s):
pat = XMLFromMarkupPattern(r'[span]foo[/span]')
s.assertEquals(pat.format(s.a), '<span>foo</span>')
s._test_markup(pat.format(s.a))
pat = XMLFromMarkupPattern(r'[span weight="bold"]foo[/span]')
s.assertEquals(pat.format(s.a), '<span weight="bold">foo</span>')
s._test_markup(pat.format(s.a))
示例4: test_convenience
def test_convenience(s):
pat = XMLFromMarkupPattern(r'[b]foo[/b]')
s.assertEquals(pat.format(s.a), '<b>foo</b>')
s._test_markup(pat.format(s.a))
pat = XMLFromMarkupPattern('[small ]foo[/small \t]')
s.assertEquals(pat.format(s.a), '<small >foo</small \t>')
s._test_markup(pat.format(s.a))
示例5: test_convenience_invalid
def test_convenience_invalid(s):
pat = XMLFromMarkupPattern(r'[b foo="1"]')
s.assertEquals(pat.format(s.a), '[b foo="1"]')
s._test_markup(pat.format(s.a))
示例6: test_link
def test_link(s):
pat = XMLFromMarkupPattern(r'[a href=""]foo[/a]')
s.assertEquals(pat.format(s.a), '<a href="">foo</a>')