def LoadSingleDos(dos_info, open_fn=None): """Load a dos.yaml file or string and return a DosInfoExternal object. Args: dos_info: The contents of a dos.yaml file as a string, or an open file object. open_fn: Function for opening files. Unused. Returns: A DosInfoExternal instance which represents the contents of the parsed yaml file. Raises: MalformedDosConfiguration: The yaml file contains multiple blacklist sections. yaml_errors.EventError: An error occured while parsing the yaml file. """ builder = yaml_object.ObjectBuilder(DosInfoExternal) handler = yaml_builder.BuilderHandler(builder) listener = yaml_listener.EventListener(handler) listener.Parse(dos_info) parsed_yaml = handler.GetResults() if not parsed_yaml: return DosInfoExternal() if len(parsed_yaml) > 1: raise MalformedDosConfiguration('Multiple blacklist: sections ' 'in configuration.') return parsed_yaml[0]
def LoadSingleClientDeployInfo(client_deploy_info): """Returns a ClientDeployInfoExternal from a deploy_info.yaml file or string. Args: client_deploy_info: The contents of a client_deploy_info.yaml file or string, or an open file object. Returns: A ClientDeployInfoExternal instance which represents the contents of the parsed yaml. Raises: EmptyYaml: when there are no documents in yaml. MultipleClientDeployInfo: when there are multiple documents in yaml. yaml_errors.EventError: when an error occurs while parsing the yaml. """ builder = yaml_object.ObjectBuilder(ClientDeployInfoExternal) handler = yaml_builder.BuilderHandler(builder) listener = yaml_listener.EventListener(handler) listener.Parse(client_deploy_info) parsed_yaml = handler.GetResults() if not parsed_yaml: raise EmptyYaml() if len(parsed_yaml) > 1: raise MultipleClientDeployInfo() return parsed_yaml[0]
def LoadSingleDispatch(dispatch_info, open_fn=None): """Load a dispatch.yaml file or string and return a DispatchInfoExternal. Args: dispatch_info: The contents of a dispatch.yaml file as a string, or an open file object. open_fn: Function for opening files. Unused here, needed to provide a polymorphic API used by appcfg.py yaml parsing. Returns: A DispatchInfoExternal instance which represents the contents of the parsed yaml file. Raises: MalformedDispatchConfigurationError: The yaml file contains multiple dispatch sections. yaml_errors.EventError: An error occured while parsing the yaml file. """ builder = yaml_object.ObjectBuilder(DispatchInfoExternal) handler = yaml_builder.BuilderHandler(builder) listener = yaml_listener.EventListener(handler) listener.Parse(dispatch_info) parsed_yaml = handler.GetResults() if not parsed_yaml: return DispatchInfoExternal() if len(parsed_yaml) > 1: raise MalformedDispatchConfigurationError('Multiple dispatch: sections ' 'in configuration.') return parsed_yaml[0]
def LoadPagespeedEntry(pagespeed_entry, open_fn=None): """Load a yaml file or string and return a PagespeedEntry. Args: pagespeed_entry: The contents of a pagespeed entry from a yaml file as a string, or an open file object. open_fn: Function for opening files. Unused. Returns: A PagespeedEntry instance which represents the contents of the parsed yaml. Raises: yaml_errors.EventError: An error occured while parsing the yaml. MalformedPagespeedConfiguration: The configuration is parseable but invalid. """ builder = yaml_object.ObjectBuilder(PagespeedEntry) handler = yaml_builder.BuilderHandler(builder) listener = yaml_listener.EventListener(handler) listener.Parse(pagespeed_entry) parsed_yaml = handler.GetResults() if not parsed_yaml: return PagespeedEntry() if len(parsed_yaml) > 1: raise MalformedPagespeedConfiguration( 'Multiple configuration sections in the yaml') return parsed_yaml[0]
def LoadSingleCron(cron_info, open_fn=None): """Load a cron.yaml file or string and return a CronInfoExternal object.""" builder = yaml_object.ObjectBuilder(CronInfoExternal) handler = yaml_builder.BuilderHandler(builder) listener = yaml_listener.EventListener(handler) listener.Parse(cron_info) cron_info_result = handler.GetResults() if len(cron_info_result) < 1: raise MalformedCronfigurationFile('Empty cron configuration.') if len(cron_info_result) > 1: raise MalformedCronfigurationFile('Multiple cron sections ' 'in configuration.') return cron_info_result[0]
def LoadSingleQueue(queue_info, open_fn=None): """Load a queue.yaml file or string and return a QueueInfoExternal object. Args: queue_info: the contents of a queue.yaml file, as a string. open_fn: Function for opening files. Unused. Returns: A QueueInfoExternal object. """ builder = yaml_object.ObjectBuilder(QueueInfoExternal) handler = yaml_builder.BuilderHandler(builder) listener = yaml_listener.EventListener(handler) listener.Parse(queue_info) queue_info = handler.GetResults() if len(queue_info) < 1: raise MalformedQueueConfiguration('Empty queue configuration.') if len(queue_info) > 1: raise MalformedQueueConfiguration('Multiple queue: sections ' 'in configuration.') return queue_info[0]