comparison piecrust/configuration.py @ 444:1359b2b0cc73

performance: Use the fast YAML loader if available.
author Ludovic Chabant <ludovic@chabant.com>
date Mon, 29 Jun 2015 18:12:31 -0700
parents 32c7c2d219d2
children 9ccc933ac2c7
comparison
equal deleted inserted replaced
443:6b9f59b19db7 444:1359b2b0cc73
1 import re 1 import re
2 import logging 2 import logging
3 import collections.abc 3 import collections.abc
4 import yaml 4 import yaml
5 from yaml.constructor import ConstructorError 5 from yaml.constructor import ConstructorError
6 try:
7 from yaml import CSafeLoader as SafeLoader
8 except ImportError:
9 from yaml import SafeLoader
6 10
7 11
8 logger = logging.getLogger(__name__) 12 logger = logging.getLogger(__name__)
9 13
10 default_allowed_types = (dict, list, tuple, float, int, bool, str) 14 default_allowed_types = (dict, list, tuple, float, int, bool, str)
164 config = {} 168 config = {}
165 offset = 0 169 offset = 0
166 return config, offset 170 return config, offset
167 171
168 172
169 class ConfigurationLoader(yaml.SafeLoader): 173 class ConfigurationLoader(SafeLoader):
170 """ A YAML loader that loads mappings into ordered dictionaries. 174 """ A YAML loader that loads mappings into ordered dictionaries.
171 """ 175 """
172 def __init__(self, *args, **kwargs): 176 def __init__(self, *args, **kwargs):
173 super(ConfigurationLoader, self).__init__(*args, **kwargs) 177 super(ConfigurationLoader, self).__init__(*args, **kwargs)
174 178