in tools/yaml_parser.py [0:0]
def from_yaml(cls: Type[UrlTagConfigType],
yaml_config: Mapping[str, Any]) -> UrlTagConfigType:
"""Builds an UrlTagConfig instance from a YAML config.
Args:
yaml_config: A config loaded from a YAML file.
Returns:
An UrlTagConfig instance loaded from the YAML config.
Raises:
ValueError:
- if yaml_config does not contain a `format` field.
- if yaml_config['format'] is not one of the supported formats.
"""
if _FORMAT_KEY not in yaml_config:
raise ValueError(f"YAML config should contain `{_FORMAT_KEY}` key "
f"but was {yaml_config}.")
format_value = yaml_config[_FORMAT_KEY]
domain_value = None
if format_value not in _SUPPORTED_FORMAT_VALUES:
raise ValueError(
f"'format' must be one of {set(_SUPPORTED_FORMAT_VALUES)} but was "
f"{format_value}.")
if _REQUIRED_DOMAIN_KEY in yaml_config:
domain_value = yaml_config[_REQUIRED_DOMAIN_KEY]
return cls(format=format_value, required_domain=domain_value)