Mercurial > hgrepos > Python > libs > ConfigMix
comparison configmix/yaml.py @ 134:2f2e819e8d17
Check the return type of the JSON and YAML loading functions: they must be a dict alike
| author | Franz Glasner <hg@dom66.de> |
|---|---|
| date | Thu, 05 Apr 2018 09:12:29 +0200 |
| parents | 99e7b10c8aa8 |
| children | b7b0cea8ec6e |
comparison
equal
deleted
inserted
replaced
| 133:05cb18c8697a | 134:2f2e819e8d17 |
|---|---|
| 149 u("tag:yaml.org,2002:omap"), | 149 u("tag:yaml.org,2002:omap"), |
| 150 ConfigSafeLoader.construct_yaml_map) | 150 ConfigSafeLoader.construct_yaml_map) |
| 151 | 151 |
| 152 | 152 |
| 153 def load(stream, Loader=ConfigLoader): | 153 def load(stream, Loader=ConfigLoader): |
| 154 return yaml.load(stream, Loader) | 154 data = yaml.load(stream, Loader) |
| 155 if OrderedDict: | |
| 156 if not isinstance(data, OrderedDict): | |
| 157 raise TypeError("YAML root object must be a mapping") | |
| 158 return data | |
| 155 | 159 |
| 156 | 160 |
| 157 def load_all(stream, Loader=ConfigLoader): | 161 def load_all(stream, Loader=ConfigLoader): |
| 158 return yaml.load_all(stream, Loader) | 162 data_all = yaml.load_all(stream, Loader) |
| 163 if OrderedDict: | |
| 164 for data in data_all: | |
| 165 if not isinstance(data, OrderedDict): | |
| 166 raise TypeError("YAML root object must be a mapping") | |
| 167 return data_all | |
| 159 | 168 |
| 160 | 169 |
| 161 def safe_load(stream): | 170 def safe_load(stream): |
| 162 return yaml.load(stream, Loader=ConfigSafeLoader) | 171 data = yaml.load(stream, Loader=ConfigSafeLoader) |
| 172 if OrderedDict: | |
| 173 if not isinstance(data, OrderedDict): | |
| 174 raise TypeError("YAML root object must be a mapping") | |
| 175 return data | |
| 163 | 176 |
| 164 | 177 |
| 165 def safe_load_all(stream): | 178 def safe_load_all(stream): |
| 166 return yaml.load_all(stream, Loader=ConfigSafeLoader) | 179 data_all = yaml.load_all(stream, Loader=ConfigSafeLoader) |
| 180 if OrderedDict: | |
| 181 for data in data_all: | |
| 182 if not isinstance(data, OrderedDict): | |
| 183 raise TypeError("YAML root object must be a mapping") | |
| 184 return data_all |
