Mercurial > hgrepos > Python > libs > ConfigMix
comparison configmix/yaml.py @ 135:b7b0cea8ec6e
Document "configmix.yaml.loadXXX()" functions
| author | Franz Glasner <hg@dom66.de> |
|---|---|
| date | Thu, 05 Apr 2018 09:23:44 +0200 |
| parents | 2f2e819e8d17 |
| children | eee1dd1f99bf |
comparison
equal
deleted
inserted
replaced
| 134:2f2e819e8d17 | 135:b7b0cea8ec6e |
|---|---|
| 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 """Parse the given `stream` and return a Python object constructed | |
| 155 from for the first document in the stream. | |
| 156 | |
| 157 """ | |
| 154 data = yaml.load(stream, Loader) | 158 data = yaml.load(stream, Loader) |
| 155 if OrderedDict: | 159 if OrderedDict: |
| 156 if not isinstance(data, OrderedDict): | 160 if not isinstance(data, OrderedDict): |
| 157 raise TypeError("YAML root object must be a mapping") | 161 raise TypeError("YAML root object must be a mapping") |
| 158 return data | 162 return data |
| 159 | 163 |
| 160 | 164 |
| 161 def load_all(stream, Loader=ConfigLoader): | 165 def load_all(stream, Loader=ConfigLoader): |
| 166 """Parse the given `stream` and return a sequence of Python objects | |
| 167 corresponding to the documents in the `stream`. | |
| 168 | |
| 169 """ | |
| 162 data_all = yaml.load_all(stream, Loader) | 170 data_all = yaml.load_all(stream, Loader) |
| 163 if OrderedDict: | 171 if OrderedDict: |
| 164 for data in data_all: | 172 for data in data_all: |
| 165 if not isinstance(data, OrderedDict): | 173 if not isinstance(data, OrderedDict): |
| 166 raise TypeError("YAML root object must be a mapping") | 174 raise TypeError("YAML root object must be a mapping") |
| 167 return data_all | 175 return data_all |
| 168 | 176 |
| 169 | 177 |
| 170 def safe_load(stream): | 178 def safe_load(stream): |
| 179 """Parse the given `stream` and return a Python object constructed | |
| 180 from for the first document in the stream. | |
| 181 | |
| 182 Recognize only standard YAML tags and cannot construct an | |
| 183 arbitrary Python object. | |
| 184 | |
| 185 """ | |
| 171 data = yaml.load(stream, Loader=ConfigSafeLoader) | 186 data = yaml.load(stream, Loader=ConfigSafeLoader) |
| 172 if OrderedDict: | 187 if OrderedDict: |
| 173 if not isinstance(data, OrderedDict): | 188 if not isinstance(data, OrderedDict): |
| 174 raise TypeError("YAML root object must be a mapping") | 189 raise TypeError("YAML root object must be a mapping") |
| 175 return data | 190 return data |
| 176 | 191 |
| 177 | 192 |
| 178 def safe_load_all(stream): | 193 def safe_load_all(stream): |
| 194 """Return the list of all decoded YAML documents in the file `stream`. | |
| 195 | |
| 196 Recognize only standard YAML tags and cannot construct an | |
| 197 arbitrary Python object. | |
| 198 | |
| 199 """ | |
| 179 data_all = yaml.load_all(stream, Loader=ConfigSafeLoader) | 200 data_all = yaml.load_all(stream, Loader=ConfigSafeLoader) |
| 180 if OrderedDict: | 201 if OrderedDict: |
| 181 for data in data_all: | 202 for data in data_all: |
| 182 if not isinstance(data, OrderedDict): | 203 if not isinstance(data, OrderedDict): |
| 183 raise TypeError("YAML root object must be a mapping") | 204 raise TypeError("YAML root object must be a mapping") |
