Ejemplo n.º 1
0
    def test_types(self):
        parts = split_escape("\xff:\xff", ":")
        self.assertEqual(parts, ["\xff", "\xff"])
        self.assertTrue(isinstance(parts[0], bytes))

        parts = split_escape(u"a:b", u":")
        self.assertEqual(parts, [u"a", u"b"])
        self.assertTrue(all(isinstance(p, unicode) for p in parts))

        parts = split_escape(u"", u":")
        self.assertEqual(parts, [u""])
        self.assertTrue(all(isinstance(p, unicode) for p in parts))

        parts = split_escape(u":", u":")
        self.assertEqual(parts, [u"", u""])
        self.assertTrue(all(isinstance(p, unicode) for p in parts))
Ejemplo n.º 2
0
    def test_types(self):
        parts = split_escape("\xff:\xff", ":")
        self.assertEqual(parts, ["\xff", "\xff"])
        self.assertTrue(isinstance(parts[0], bytes))

        parts = split_escape(u"a:b", u":")
        self.assertEqual(parts, [u"a", u"b"])
        self.assertTrue(all(isinstance(p, unicode) for p in parts))

        parts = split_escape(u"", u":")
        self.assertEqual(parts, [u""])
        self.assertTrue(all(isinstance(p, unicode) for p in parts))

        parts = split_escape(u":", u":")
        self.assertEqual(parts, [u"", u""])
        self.assertTrue(all(isinstance(p, unicode) for p in parts))
Ejemplo n.º 3
0
def split_scan_dirs(s):
    """Split the value of the "scan" setting, accounting for drive letters on
    win32."""
    if sys.platform == "win32":
        return filter(None, re.findall(r"[a-zA-Z]:[\\/][^:]*", s))
    else:
        # See Issue 1413 - allow escaped colons
        return filter(None, split_escape(s, ":"))
Ejemplo n.º 4
0
def split_scan_dirs(s):
    """Split the value of the "scan" setting, accounting for drive letters on
    win32."""
    if sys.platform == "win32":
        return filter(None, re.findall(r"[a-zA-Z]:[\\/][^:]*", s))
    else:
        # See Issue 1413 - allow escaped colons
        return filter(None, split_escape(s, ":"))
Ejemplo n.º 5
0
    def getlist(self, section, option, default=_DEFAULT, sep=","):
        """Returns a str list saved with setlist()"""

        try:
            value = self._config.get(section, option)
        except Error:
            if default is _DEFAULT:
                raise
            if not isinstance(default, list):
                raise ValueError
            return default

        return split_escape(value, sep)
Ejemplo n.º 6
0
    def getlist(self, section, option, default=_DEFAULT, sep=","):
        """Returns a str list saved with setlist()"""

        try:
            value = self._config.get(section, option)
        except Error:
            if default is _DEFAULT:
                raise
            if not isinstance(default, list):
                raise ValueError
            return default

        return split_escape(value, sep)
Ejemplo n.º 7
0
    def getlist(self, section, option, default=_DEFAULT, sep=","):
        """Returns a str list saved with setlist()"""

        try:
            value = self._config.get(section, option)
            return split_escape(value, sep)
        except (Error, ValueError) as e:
            if default is _DEFAULT:
                if self.defaults is not None:
                    try:
                        return self.defaults.getlist(section, option, sep=sep)
                    except Error:
                        pass
                raise Error(e)
            return default
Ejemplo n.º 8
0
    def getlist(self, section, option, default=_DEFAULT, sep=","):
        """Returns a str list saved with setlist()"""

        try:
            value = self._config.get(section, option)
            return split_escape(value, sep)
        except (Error, ValueError) as e:
            if default is _DEFAULT:
                if self.defaults is not None:
                    try:
                        return self.defaults.getlist(section, option, sep=sep)
                    except Error:
                        pass
                raise Error(e)
            return default
Ejemplo n.º 9
0
def split_scan_dirs(joined_paths):
    """Returns a list of paths

    Args:
        joined_paths (fsnative)
    Return:
        list
    """

    assert isinstance(joined_paths, fsnative)

    if is_windows():
        # we used to separate this config with ":", so this is tricky
        return list(filter(None, re.findall(r"[a-zA-Z]:[\\/][^:]*", joined_paths)))
    else:
        return list(filter(None, split_escape(joined_paths, ":")))
Ejemplo n.º 10
0
def split_scan_dirs(joined_paths):
    """Returns a list of paths

    Args:
        joined_paths (fsnative)
    Return:
        list
    """

    assert isinstance(joined_paths, fsnative)

    if is_windows():
        # we used to separate this config with ":", so this is tricky
        return filter(None, re.findall(r"[a-zA-Z]:[\\/][^:]*", joined_paths))
    else:
        return filter(None, split_escape(joined_paths, ":"))
Ejemplo n.º 11
0
def _enqueue_files(app, value):
    """Enqueues comma-separated filenames or song names.
    Commas in filenames should be backslash-escaped"""

    library = app.library
    window = app.window
    songs = []
    for param in split_escape(value, ","):
        try:
            song_path = uri2fsn(param)
        except ValueError:
            song_path = param
        if song_path in library:
            songs.append(library[song_path])
        elif os.path.isfile(song_path):
            songs.append(library.add_filename(os.path.realpath(value)))
    if songs:
        window.playlist.enqueue(songs)
Ejemplo n.º 12
0
def _enqueue_files(app, value):
    """Enqueues comma-separated filenames or song names.
    Commas in filenames should be backslash-escaped"""

    library = app.library
    window = app.window
    songs = []
    for param in split_escape(value, ","):
        try:
            song_path = uri2fsn(param)
        except ValueError:
            song_path = param
        if song_path in library:
            songs.append(library[song_path])
        elif os.path.isfile(song_path):
            songs.append(library.add_filename(os.path.realpath(value)))
    if songs:
        window.playlist.enqueue(songs)
Ejemplo n.º 13
0
    def test_split_escape(self):
        # from mutagen

        inout = [
            (("", ":"), [""]),
            ((":", ":"), ["", ""]),
            ((":", ":", 0), [":"]),
            ((":b:c:", ":", 0), [":b:c:"]),
            ((":b:c:", ":", 1), ["", "b:c:"]),
            ((":b:c:", ":", 2), ["", "b", "c:"]),
            ((":b:c:", ":", 3), ["", "b", "c", ""]),
            (("a\\:b:c", ":"), ["a:b", "c"]),
            (("a\\\\:b:c", ":"), ["a\\", "b", "c"]),
            (("a\\\\\\:b:c\\:", ":"), ["a\\:b", "c:"]),
            (("\\", ":"), [""]),
            (("\\\\", ":"), ["\\"]),
            (("\\\\a\\b", ":"), ["\\a\\b"]),
        ]

        for inargs, out in inout:
            self.assertEqual(split_escape(*inargs), out)
Ejemplo n.º 14
0
    def test_split_escape(self):
        # from mutagen

        inout = [
            (("", ":"), [""]),
            ((":", ":"), ["", ""]),
            ((":", ":", 0), [":"]),
            ((":b:c:", ":", 0), [":b:c:"]),
            ((":b:c:", ":", 1), ["", "b:c:"]),
            ((":b:c:", ":", 2), ["", "b", "c:"]),
            ((":b:c:", ":", 3), ["", "b", "c", ""]),
            (("a\\:b:c", ":"), ["a:b", "c"]),
            (("a\\\\:b:c", ":"), ["a\\", "b", "c"]),
            (("a\\\\\\:b:c\\:", ":"), ["a\\:b", "c:"]),
            (("\\", ":"), [""]),
            (("\\\\", ":"), ["\\"]),
            (("\\\\a\\b", ":"), ["\\a\\b"]),
        ]

        for inargs, out in inout:
            self.assertEqual(split_escape(*inargs), out)
Ejemplo n.º 15
0
 def test_roundtrip(self):
     values = ["\\:", ":"]
     joined = join_escape(values, ":")
     self.assertEqual(split_escape(joined, ":"), values)
Ejemplo n.º 16
0
 def test_roundtrip(self):
     values = ["\\:", ":"]
     joined = join_escape(values, ":")
     self.assertEqual(split_escape(joined, ":"), values)