+# Copyright (c) 2013, 2014, 2015, 2021 kaliko <kaliko@azylum.org>
+#
+# This file is part of sima
+#
+# sima is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# sima is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with sima. If not, see <http://www.gnu.org/licenses/>.
+#
+#
+"""
+Defines some object to handle audio file metadata
+"""
+
+
+from collections.abc import Set
+import logging
+import re
+
+from ..utils.utils import MPDSimaException
+
+
+UUID_RE = r'^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[89AB][a-f0-9]{3}-[a-f0-9]{12}$'
+#: The Track Object is collapsing multiple tags into a single string using this
+# separator. It is used then to split back the string to tags list.
+SEPARATOR = chr(0x1F) # ASCII Unit Separator
+
+
+def is_uuid4(uuid):
+ """Controls MusicBrainz UUID4 format
+
+ :param str uuid: String representing the UUID
+ :returns: boolean
+ """
+ regexp = re.compile(UUID_RE, re.IGNORECASE)
+ if regexp.match(uuid):
+ return True
+ return False
+
+
+class MetaException(MPDSimaException):
+ """Generic Meta Exception"""
+
+
+def mbidfilter(func):
+ def wrapper(*args, **kwargs):
+ cls = args[0]
+ if not cls.use_mbid:
+ kwargs.pop('mbid', None)
+ kwargs.pop('musicbrainz_artistid', None)
+ kwargs.pop('musicbrainz_albumartistid', None)
+ func(*args, **kwargs)
+ return wrapper
+
+
+def serialize(func):
+ def wrapper(*args, **kwargs):
+ ans = func(*args, **kwargs)
+ if isinstance(ans, set):
+ return {s.replace("'", r"\'").replace('"', r'\"') for s in ans}
+ return ans.replace("'", r"\'").replace('"', r'\"')
+ return wrapper