Genereting catetory from YAML file.
357388
def gen_category(yaml_file, sig):
    '''
    
    '''

    out_dic = yaml.load(open(yaml_file))

    for key in out_dic:

        if key.endswith('00'):
            uid = key[1:]
            cur_dic = out_dic[key]
            porder = cur_dic['order']
            cat_dic = {
                'uid': uid,
                'slug': cur_dic['slug'],
                'name': cur_dic['name'],
                'count': 0,
                'tmpl': 1,
                'pid': '0000',
                'order': porder * 100,
                'kind': '{0}'.format(sig),
            }

            MCategory.add_or_update(uid, cat_dic)
        else:
            sub_arr = out_dic[key]
            pid = key[1:3]

            for sub_dic in sub_arr:
                porder = out_dic['z' + pid + '00']['order']

                for key2 in sub_dic:
                    uid = key2[1:]

                    cur_dic = sub_dic[key2]

                    sorder = cur_dic['order']
                    cat_dic = {
                        'uid': uid,
                        'slug': cur_dic['slug'],
                        'name': cur_dic['name'],
                        'count': 0,
                        'tmpl': 1,
                        'pid': pid + '00',
                        'order': porder * 100 + sorder,
                        'kind': '{0}'.format(sig),
                    }

                    MCategory.add_or_update(pid + uid, cat_dic)
465686
def load_yaml(fname):
    """"""
    yaml = YAML(typ="safe")
    # Compat with HASS
    yaml.allow_duplicate_keys = True
    # Stub HASS constructors
    HassSafeConstructor.name = fname
    yaml.Constructor = HassSafeConstructor

    with open(fname, encoding="utf-8") as conf_file:
        # If configuration file is empty YAML returns None
        # We convert that to an empty dict
        return yaml.load(conf_file) or {}
536446
def _load_yaml_config(self):
        
        try:
            config = self._read_config()
        except OSError as error:
            raise ValueError('Could not read configuration file: %s' % error)
        try:
            return yaml.safe_load(config)
        except yaml.YAMLError as error:
            message = '\n'.join(['    > %s' % line
                                 for line in str(error).split('\n')])
            sys.stderr.write('\n\n  Error in the configuration file:\n\n'
                             '{}\n\n'.format(message))
            sys.stderr.write('  Configuration should be a valid YAML file.\n')
            sys.stderr.write('  YAML format validation available at '
                             'http://yamllint.com\n')
            raise ValueError(error)
330044
def load(self, ymlfile=None):
        """"""
        if ymlfile is not None:
            self.ymlfile = ymlfile

        try:
            # If yaml should be 'cleaned' of document references
            if self._clean:
                self.data = self.process(self.ymlfile)
            else:
                with open(self.ymlfile, 'rb') as stream:
                    for data in yaml.load_all(stream):
                        self.data.append(data)

            self.loaded = True
        except ScannerError, e:
            msg = "YAML formattting error - '" + self.ymlfile + ": '" + str(e) + "'"
            raise util.YAMLError(msg)
486221
def cfg_from_file(self, yaml_filename, config_dict):
        """"""
        import yaml
        from easydict import EasyDict as edict
        with open(yaml_filename, 'r') as f:
            yaml_cfg = edict(yaml.load(f))

        return self._merge_a_into_b(yaml_cfg, config_dict)
100010
def update_from_file(yaml_dict, filepaths):
    '''
    
    '''
    # load YAML settings with only fields in yaml_dict
    yaml_dict.update(registry.load(filepaths, list(yaml_dict)))
934625
def from_file(cls, filename):
        
        with open(filename) as infp:
            if filename.endswith('.yaml') or filename.endswith('.yml'):
                import yaml
                data = yaml.safe_load(infp)
            else:
                import json
                data = json.load(infp)
        return cls.from_data(data)
936859
def _load_from_yaml(self, filename: str, model_identifiers: Dict[str, List[str]]):
        
        class_name = filename[:filename.rfind('.')]
        rendered_yaml = self.env.get_template(filename).render(
            model_identifiers=model_identifiers)
        fixture_data, self.relationships[class_name] = self._post_process_yaml_data(
            yaml.load(rendered_yaml),
            self.factory.get_relationships(class_name))

        for identifier_key, data in fixture_data.items():
            self.model_fixtures[class_name][identifier_key] = data
399436
def from_yaml(cls, file_path=None):
        """"""
        try:
            import yaml
        except ImportError:  # pragma: no cover
            yaml = None
        if not yaml:
            import sys
            sys.exit('PyYAML is not installed, but is required in order to parse YAML files.'
                     '\nTo install, run:\n$ pip install PyYAML\nor visit'
                     ' http://pyyaml.org/wiki/PyYAML for instructions.')

        with io.open(file_path, encoding=text_type('utf-8')) as stream:
            users_yaml = yaml.safe_load(stream)
            if isinstance(users_yaml, dict):
                return cls.construct_user_list(raw_users=users_yaml.get('users'))
            else:
                raise ValueError('No YAML object could be decoded')
189743
def build_from_yamlfile(yamlfile):
        
        d = yaml.load(open(yamlfile))
        return MktimeFilterDict(d['aliases'], d['selections'])
447176
def _analyze_yaml_file(self, file, filename):
        
        if os.path.splitext(filename)[1] not in YAML_EXTENSIONS:
            # The yaml parser is pretty powerful. It eagerly
            # parses things when it's not even a yaml file. Therefore,
            # we use this heuristic to quit early if appropriate.
            raise yaml.YAMLError

        parser = YamlFileParser(
            file,
            exclude_lines_regex=self.exclude_lines_regex,
        )
        data = parser.json()
        ignored_lines = parser.get_ignored_lines()
        potential_secrets = {}

        to_search = [data]
        with self.non_quoted_string_regex():
            while len(to_search) > 0:
                item = to_search.pop()

                try:
                    if '__line__' in item and not item['__line__'] in ignored_lines:
                        potential_secrets.update(
                            self.analyze_string(
                                item['__value__'],
                                item['__line__'],
                                filename,
                            ),
                        )

                    if '__line__' in item:
                        continue

                    for key in item:
                        obj = item[key] if isinstance(item, dict) else key
                        if isinstance(obj, dict):
                            to_search.append(obj)
                except TypeError:
                    pass

        return potential_secrets
41753
def parse_yaml(self, y):
        '''

        '''
        self.name = y['name']
        if 'data' in y:
            self.data = y['data']
        else:
            self.data = ''
        return self
811306
def read_yaml_configuration(filename):
    '''
    '''
    with open(filename, 'r') as f:
        config = yaml.load(f.read())
    return config
1011613
def _load_yaml_config(path=None):
    """"""
    countour_yaml_path = path or find_contour_yaml()

    if countour_yaml_path is None:
        logging.debug("countour.yaml not found.")
        return None

    with open(countour_yaml_path) as yaml_file:
        return yaml_file.read()
120440
def from_file(path):
        """"""
        with open(path) as stream:
            obj = yaml.safe_load(stream)
        Config.lint(obj)
        return Config(config_dict=obj)
45845
def from_yaml():
    
    default_yaml_str = snippets.get_snippet_content('hatchery.yml')
    ret = yaml.load(default_yaml_str, Loader=yaml.RoundTripLoader)
    for config_path in CONFIG_LOCATIONS:
        config_path = os.path.expanduser(config_path)
        if os.path.isfile(config_path):
            with open(config_path) as config_file:
                config_dict = yaml.load(config_file, Loader=yaml.RoundTripLoader)
                if config_dict is None:
                    continue
                for k, v in config_dict.items():
                    if k not in ret.keys():
                        raise ConfigError(
                            'found garbage key "{}" in {}'.format(k, config_path)
                        )
                    ret[k] = v
    return ret
1155519
def as_yaml(self):
        
        dumped = dump(self.as_marked_up(), Dumper=StrictYAMLDumper, allow_unicode=True)
        return dumped if sys.version_info[0] == 3 else dumped.decode("utf8")