<commit_before>import collections
import os

from mopidy import config, ext

__version__ = "2.0.3"

SORT_FIELDS = [
    f"{f} {o}"
    for o in ("asc", "desc")
    for f in (
        "addeddate",
        "avg_rating",
        "call_number",
        "createdate",
        "creatorSorter",
        "date",
        "downloads",
        "foldoutcount",
        "headerImage",
        "identifier",
        "imagecount",
        "indexdate",
        "languageSorter",
        "licenseurl",
        "month",
        "nav_order",
        "num_reviews",
        "publicdate",
        "reviewdate",
        "stars",
        "titleSorter",
        "week",
        "year",
    )
]


class ConfigMap(config.ConfigValue):
    def __init__(
        self,
        keys=config.String(),
        values=config.String(),
        delim="|",
        optional=False,
    ):
        self.__keys = keys
        self.__values = values
        self.__delim = delim
        self.__optional = optional

    def deserialize(self, value):
        dict = collections.OrderedDict()
        for s in config.List(optional=self.__optional).deserialize(value):
            parts = s.partition(self.__delim)
            key = self.__keys.deserialize(parts[0])
            val = self.__values.deserialize(parts[2])
            dict[key] = val
        return dict

    def serialize(self, value, display=False):
        if not value:
            return b""
        items = [
            (self.__keys.serialize(k), self.__values.serialize(v))
            for k, v in value.items()
        ]
        return config.List().serialize(map(self.__delim.join, items))


class Extension(ext.Extension):

    dist_name = "Mopidy-InternetArchive"
    ext_name = "internetarchive"
    version = __version__

    def get_default_config(self):
        return config.read(os.path.join(os.path.dirname(__file__), "ext.conf"))

    def get_config_schema(self):
        schema = super().get_config_schema()
        schema.update(<commit_msg>Use pathlib to read ext.conf<commit_after>import collections
import pathlib

from mopidy import config, ext

__version__ = "2.0.3"

SORT_FIELDS = [
    f"{f} {o}"
    for o in ("asc", "desc")
    for f in (
        "addeddate",
        "avg_rating",
        "call_number",
        "createdate",
        "creatorSorter",
        "date",
        "downloads",
        "foldoutcount",
        "headerImage",
        "identifier",
        "imagecount",
        "indexdate",
        "languageSorter",
        "licenseurl",
        "month",
        "nav_order",
        "num_reviews",
        "publicdate",
        "reviewdate",
        "stars",
        "titleSorter",
        "week",
        "year",
    )
]


class ConfigMap(config.ConfigValue):
    def __init__(
        self,
        keys=config.String(),
        values=config.String(),
        delim="|",
        optional=False,
    ):
        self.__keys = keys
        self.__values = values
        self.__delim = delim
        self.__optional = optional

    def deserialize(self, value):
        dict = collections.OrderedDict()
        for s in config.List(optional=self.__optional).deserialize(value):
            parts = s.partition(self.__delim)
            key = self.__keys.deserialize(parts[0])
            val = self.__values.deserialize(parts[2])
            dict[key] = val
        return dict

    def serialize(self, value, display=False):
        if not value:
            return b""
        items = [
            (self.__keys.serialize(k), self.__values.serialize(v))
            for k, v in value.items()
        ]
        return config.List().serialize(map(self.__delim.join, items))


class Extension(ext.Extension):

    dist_name = "Mopidy-InternetArchive"
    ext_name = "internetarchive"
    version = __version__

    def get_default_config(self):
        return config.read(pathlib.Path(__file__).parent / "ext.conf")

    def get_config_schema(self):
        schema = super().get_config_schema()
        schema.update(
{'fraction_non_alphanumeric': 0.12333584526500879, 'fraction_numerical': 0.0025119316754584277, 'mean_word_length': 1.9894894894894894, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4804226', 'n_tokens_mistral': 1196, 'n_tokens_neox': 1170, 'n_words': 241}