# HG changeset patch # User Franz Glasner # Date 1599722550 -7200 # Node ID 1484f6c0223a6224e873a6964efff7615abfed87 # Parent d715c10f29307b5490ee1177ebbdc23d222b8d3b Implemented "del_assoc()" diff -r d715c10f2930 -r 1484f6c0223a CHANGES.txt --- a/CHANGES.txt Thu Sep 10 02:01:28 2020 +0200 +++ b/CHANGES.txt Thu Sep 10 09:22:30 2020 +0200 @@ -25,6 +25,12 @@ Unknown filetypes within these directories are ignored automatically. + .. change:: + :tags: feature + + Implemented a function to delete an association: + :py:func:`configmix.del_assoc`. + .. changelog:: :version: 0.9 :released: 2020-07-28 diff -r d715c10f2930 -r 1484f6c0223a configmix/__init__.py --- a/configmix/__init__.py Thu Sep 10 02:01:28 2020 +0200 +++ b/configmix/__init__.py Thu Sep 10 09:22:30 2020 +0200 @@ -205,7 +205,7 @@ "javascript": _load_json, "json": _load_json, "-*-ignore-*-": _load_ignore, - "-*- ignore -*-": _load_ignore, + "-*- ignore -*-": _load_ignore, } """Default associations between file modes and loader functions""" @@ -327,6 +327,23 @@ _extensions.insert(0, (fnpattern, mode)) +def del_assoc(fnpattern): + """Remove all associations for `fnpattern`. + + :param str fnpattern: the :mod:`fnmatch` pattern to associate a loader + with + + """ + while True: + for i in range(len(_extensions)): + pat, fmode = _extensions[i] + if fnpattern == pat: + del _extensions[i] + break # restart + else: + return # nothing deleted -> done + + def _load_cfg_from_file(filename, ignore_unknown=False): """Determine the loader for file `filename` and return the loaded configuration dict.