Пример #1
0
def LoadSingleAppInfo(app_info):
    """Load a single AppInfo object where one and only one is expected.

  Args:
    app_info: A file-like object or string.  If it is a string, parse it as
    a configuration file.  If it is a file-like object, read in data and
    parse.

  Returns:
    An instance of AppInfoExternal as loaded from a YAML file.

  Raises:
    ValueError: if a specified service is not valid.
    EmptyConfigurationFile: when there are no documents in YAML file.
    MultipleConfigurationFile: when there is more than one document in YAML
    file.
  """
    builder = yaml_object.ObjectBuilder(AppInfoExternal)
    handler = yaml_builder.BuilderHandler(builder)
    listener = yaml_listener.EventListener(handler)
    listener.Parse(app_info)

    app_infos = handler.GetResults()
    if len(app_infos) < 1:
        raise appinfo_errors.EmptyConfigurationFile()
    if len(app_infos) > 1:
        raise appinfo_errors.MultipleConfigurationFile()

    appyaml = app_infos[0]
    ValidateHandlers(appyaml.handlers)
    if appyaml.builtins:
        BuiltinHandler.Validate(appyaml.builtins)

    return appyaml
Пример #2
0
def LoadAppInclude(app_include):
    """Load a single AppInclude object where one and only one is expected.

  Args:
    app_include: A file-like object or string.  If it is a string, parse it as
    a configuration file.  If it is a file-like object, read in data and
    parse.

  Returns:
    An instance of AppInclude as loaded from a YAML file.

  Raises:
    EmptyConfigurationFile: when there are no documents in YAML file.
    MultipleConfigurationFile: when there is more than one document in YAML
    file.
  """
    builder = yaml_object.ObjectBuilder(AppInclude)
    handler = yaml_builder.BuilderHandler(builder)
    listener = yaml_listener.EventListener(handler)
    listener.Parse(app_include)

    includes = handler.GetResults()
    if len(includes) < 1:
        raise appinfo_errors.EmptyConfigurationFile()
    if len(includes) > 1:
        raise appinfo_errors.MultipleConfigurationFile()

    includeyaml = includes[0]
    if includeyaml.handlers:
        for handler in includeyaml.handlers:
            handler.FixSecureDefaults()
            handler.WarnReservedURLs()
    if includeyaml.builtins:
        BuiltinHandler.Validate(includeyaml.builtins)

    return includeyaml