+
+class _CountryInfo:
+ """ Caches country-specific properties from the configuration file.
+ """
+
+ def __init__(self):
+ self._info = {}
+ self._key_prefix = 'name'
+
+ def load(self, config):
+ """ Load the country properties from the configuration files,
+ if they are not loaded yet.
+ """
+ if not self._info:
+ self._info = config.load_sub_configuration('country_settings.yaml')
+ # Convert languages into a list for simpler handling.
+ for prop in self._info.values():
+ if 'languages' not in prop:
+ prop['languages'] = []
+ elif not isinstance(prop['languages'], list):
+ prop['languages'] = [x.strip()
+ for x in prop['languages'].split(',')]
+ if 'names' not in prop or prop['names'] is None:
+ prop['names'] = {self._key_prefix: {}}
+
+ def items(self):
+ """ Return tuples of (country_code, property dict) as iterable.
+ """
+ return self._info.items()
+
+ def key_prefix(self):
+ """ Return the prefix that will be attached to the keys of the country
+ names values when storing them in the database
+ """
+ return self._key_prefix
+
+
+_COUNTRY_INFO = _CountryInfo()
+
+
+def setup_country_config(config):
+ """ Load country properties from the configuration file.
+ Needs to be called before using any other functions in this
+ file.
+ """
+ _COUNTRY_INFO.load(config)
+
+
+def iterate():
+ """ Iterate over country code and properties.
+ """
+ return _COUNTRY_INFO.items()
+
+