Mercurial > hgrepos > Python > libs > ConfigMix
comparison configmix/__init__.py @ 217:b869e792310e
FIX: Extra merged and unsafe merges in configmix.safe_load
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Wed, 08 May 2019 09:39:51 +0200 |
| parents | c03c9162f7e6 |
| children | 2034da70f8fd |
comparison
equal
deleted
inserted
replaced
| 216:c03c9162f7e6 | 217:b869e792310e |
|---|---|
| 61 if not files: | 61 if not files: |
| 62 if defaults is None: | 62 if defaults is None: |
| 63 return Configuration() | 63 return Configuration() |
| 64 else: | 64 else: |
| 65 return Configuration(defaults) | 65 return Configuration(defaults) |
| 66 else: | 66 if defaults is None: |
| 67 if defaults is None: | 67 start = 1 |
| 68 start = 1 | 68 ex = merge(None, _load_cfg_from_file(files[0])) |
| 69 ex = merge(None, _load_cfg_from_file(files[0])) | 69 else: |
| 70 else: | 70 start = 0 |
| 71 start = 0 | 71 ex = merge(None, defaults) |
| 72 ex = merge(None, defaults) | 72 for f in files[start:]: |
| 73 for f in files[start:]: | 73 ex = merge(_load_cfg_from_file(f), ex) |
| 74 ex = merge(_load_cfg_from_file(f), ex) | 74 return Configuration(ex) |
| 75 return Configuration(ex) | |
| 76 | 75 |
| 77 | 76 |
| 78 def safe_load(*files, **kwargs): | 77 def safe_load(*files, **kwargs): |
| 79 """Analogous to :func:`load` but do merging with :func:`safe_merge` | 78 """Analogous to :func:`load` but do merging with :func:`safe_merge` |
| 80 instead of :func:`merge` | 79 instead of :func:`merge` |
| 83 defaults = kwargs.get("defaults") | 82 defaults = kwargs.get("defaults") |
| 84 if not files: | 83 if not files: |
| 85 if defaults is None: | 84 if defaults is None: |
| 86 return Configuration() | 85 return Configuration() |
| 87 else: | 86 else: |
| 88 return Configuration(defaults) | 87 return Configuration(copy.deepcopy(defaults)) |
| 89 else: | 88 if defaults is None: |
| 90 if defaults is None: | 89 start = 1 |
| 91 start = 1 | |
| 92 ex = merge(None, _load_cfg_from_file(files[0])) | |
| 93 else: | |
| 94 start = 0 | |
| 95 ex = merge(None, defaults) | |
| 96 ex = safe_merge(None, _load_cfg_from_file(files[0])) | 90 ex = safe_merge(None, _load_cfg_from_file(files[0])) |
| 97 for f in files[start:]: | 91 else: |
| 98 ex = safe_merge(_load_cfg_from_file(f), ex) | 92 start = 0 |
| 99 return Configuration(ex) | 93 ex = safe_merge(None, defaults) |
| 94 for f in files[start:]: | |
| 95 ex = safe_merge(_load_cfg_from_file(f), ex) | |
| 96 return Configuration(ex) | |
| 100 | 97 |
| 101 | 98 |
| 102 def _load_yaml(filename): | 99 def _load_yaml(filename): |
| 103 from . import yaml | 100 from . import yaml |
| 104 with open(u2fs(filename), "rb") as yf: | 101 with open(u2fs(filename), "rb") as yf: |
