
from heat.common.template_format import yaml


SECTIONS = (PARAMETERS, RESOURCE_REGISTRY) = \
           ('parameters', 'resource_registry')


def parse(env_str):
    '''
    Takes a string and returns a dict containing the parsed structure.
    This includes determination of whether the string is using the
    JSON or YAML format.
    '''
    try:
        env = yaml.safe_load(env_str)
    except (yaml.scanner.ScannerError, yaml.parser.ParserError) as e:
        raise ValueError(e)
    else:
        if env is None:
            env = {}

    for param in env:
        if param not in SECTIONS:
            raise ValueError(_('environment has wrong section "%s"') % param)

    return env


def default_for_missing(env):
    '''
    Checks a parsed environment for missing sections.
    '''
    for param in SECTIONS:
        if param not in env:
            env[param] = {}


from heat.common.template_format import yaml
from heat.common.template_format import yaml_loader


SECTIONS = (PARAMETERS, RESOURCE_REGISTRY) = \
           ('parameters', 'resource_registry')


def parse(env_str):
    '''
    Takes a string and returns a dict containing the parsed structure.
    This includes determination of whether the string is using the
    JSON or YAML format.
    '''
    try:
        env = yaml.load(env_str, Loader=yaml_loader)
    except (yaml.scanner.ScannerError, yaml.parser.ParserError) as e:
        raise ValueError(e)
    else:
        if env is None:
            env = {}

    for param in env:
        if param not in SECTIONS:
            raise ValueError(_('environment has wrong section "%s"') % param)

    return env


def default_for_missing(env):
    '''
    Checks a parsed environment for missing sections.
    '''
    for param in SECTIONS:
        if param not in env:
            env[param] = {}

Make the template and env yaml parsing more consistent
Make the template and env yaml parsing more consistent

in the environment_format.py use the same yaml_loader

Partial-bug: #1242155
Change-Id: I66b08415d450bd4758af648eaff0f20dd934a9cc

  
  from heat.common.template_format import yaml
+ from heat.common.template_format import yaml_loader
  
  
  SECTIONS = (PARAMETERS, RESOURCE_REGISTRY) = \
             ('parameters', 'resource_registry')
  
  
  def parse(env_str):
      '''
      Takes a string and returns a dict containing the parsed structure.
      This includes determination of whether the string is using the
      JSON or YAML format.
      '''
      try:
-         env = yaml.safe_load(env_str)
+         env = yaml.load(env_str, Loader=yaml_loader)
      except (yaml.scanner.ScannerError, yaml.parser.ParserError) as e:
          raise ValueError(e)
      else:
          if env is None:
              env = {}
  
      for param in env:
          if param not in SECTIONS:
              raise ValueError(_('environment has wrong section "%s"') % param)
  
      return env
  
  
  def default_for_missing(env):
      '''
      Checks a parsed environment for missing sections.
      '''
      for param in SECTIONS:
          if param not in env:
              env[param] = {}
  
Make the template and env yaml parsing more consistent
## Code Before:

from heat.common.template_format import yaml


SECTIONS = (PARAMETERS, RESOURCE_REGISTRY) = \
           ('parameters', 'resource_registry')


def parse(env_str):
    '''
    Takes a string and returns a dict containing the parsed structure.
    This includes determination of whether the string is using the
    JSON or YAML format.
    '''
    try:
        env = yaml.safe_load(env_str)
    except (yaml.scanner.ScannerError, yaml.parser.ParserError) as e:
        raise ValueError(e)
    else:
        if env is None:
            env = {}

    for param in env:
        if param not in SECTIONS:
            raise ValueError(_('environment has wrong section "%s"') % param)

    return env


def default_for_missing(env):
    '''
    Checks a parsed environment for missing sections.
    '''
    for param in SECTIONS:
        if param not in env:
            env[param] = {}

## Instruction:
Make the template and env yaml parsing more consistent
## Code After:

from heat.common.template_format import yaml
from heat.common.template_format import yaml_loader


SECTIONS = (PARAMETERS, RESOURCE_REGISTRY) = \
           ('parameters', 'resource_registry')


def parse(env_str):
    '''
    Takes a string and returns a dict containing the parsed structure.
    This includes determination of whether the string is using the
    JSON or YAML format.
    '''
    try:
        env = yaml.load(env_str, Loader=yaml_loader)
    except (yaml.scanner.ScannerError, yaml.parser.ParserError) as e:
        raise ValueError(e)
    else:
        if env is None:
            env = {}

    for param in env:
        if param not in SECTIONS:
            raise ValueError(_('environment has wrong section "%s"') % param)

    return env


def default_for_missing(env):
    '''
    Checks a parsed environment for missing sections.
    '''
    for param in SECTIONS:
        if param not in env:
            env[param] = {}
