comparison configmix/__init__.py @ 268:1484f6c0223a

Implemented "del_assoc()"
author Franz Glasner <fzglas.hg@dom66.de>
date Thu, 10 Sep 2020 09:22:30 +0200
parents d715c10f2930
children 7ef4362ca7c5
comparison
equal deleted inserted replaced
267:d715c10f2930 268:1484f6c0223a
203 "toml": _load_toml, 203 "toml": _load_toml,
204 "conf-toml": _load_toml, 204 "conf-toml": _load_toml,
205 "javascript": _load_json, 205 "javascript": _load_json,
206 "json": _load_json, 206 "json": _load_json,
207 "-*-ignore-*-": _load_ignore, 207 "-*-ignore-*-": _load_ignore,
208 "-*- ignore -*-": _load_ignore, 208 "-*- ignore -*-": _load_ignore,
209 } 209 }
210 """Default associations between file modes and loader functions""" 210 """Default associations between file modes and loader functions"""
211 211
212 212
213 DEFAULT_ASSOC = [ 213 DEFAULT_ASSOC = [
323 else: 323 else:
324 if append: 324 if append:
325 _extensions.append((fnpattern, mode)) 325 _extensions.append((fnpattern, mode))
326 else: 326 else:
327 _extensions.insert(0, (fnpattern, mode)) 327 _extensions.insert(0, (fnpattern, mode))
328
329
330 def del_assoc(fnpattern):
331 """Remove all associations for `fnpattern`.
332
333 :param str fnpattern: the :mod:`fnmatch` pattern to associate a loader
334 with
335
336 """
337 while True:
338 for i in range(len(_extensions)):
339 pat, fmode = _extensions[i]
340 if fnpattern == pat:
341 del _extensions[i]
342 break # restart
343 else:
344 return # nothing deleted -> done
328 345
329 346
330 def _load_cfg_from_file(filename, ignore_unknown=False): 347 def _load_cfg_from_file(filename, ignore_unknown=False):
331 """Determine the loader for file `filename` and return the loaded 348 """Determine the loader for file `filename` and return the loaded
332 configuration dict. 349 configuration dict.