Example #1
0
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
Example #2
0
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
Example #3
0
 def test_mountpoint(self):
     song = AudioFile()
     song["~filename"] = fsnative(u"filename")
     song.sanitize()
     assert isinstance(song["~mountpoint"], fsnative)
     assert isinstance(song.comma("~mointpoint"), str)
Example #4
0
 def test_mountpoint(self):
     song = AudioFile()
     song["~filename"] = fsnative(u"filename")
     song.sanitize()
     assert isinstance(song["~mountpoint"], fsnative)
     assert isinstance(song.comma("~mointpoint"), text_type)
Example #5
0
 def test_blank_tag_handling_comma(self):
     q = AudioFile([("title", "A\n"), ("artists", "A\n\nB\n")])
     self.failUnlessEqual(q.comma("artists"), "A, B")
     self.failUnlessEqual(q.comma("~title~version"), "A")