Parse a structured reaction definition as obtained from a YAML file

    Returns a ReactionEntry.
549878
def parse_reaction(reaction_def, default_compartment, context=None):
    

    reaction_id = reaction_def.get('id')
    _check_id(reaction_id, 'Reaction')

    reaction_props = dict(reaction_def)

    # Parse reaction equation
    if 'equation' in reaction_def:
        reaction_props['equation'] = parse_reaction_equation(
            reaction_def['equation'], default_compartment)

    mark = FileMark(context, None, None)
    return ReactionEntry(reaction_props, mark)
718814
def parse_yaml(self, node):
        '''

        '''
        self.group_id = y['groupId']
        self._members = []
        if 'members' in y:
            for m in y.get('members'):
                self._members.append(TargetComponent().parse_yaml(m))
        return self
1055730
def read_collection_from_yaml(desired_type: Type[Any], file_object: TextIOBase, logger: Logger,
                              conversion_finder: ConversionFinder, fix_imports: bool = True, errors: str = 'strict',
                              **kwargs) -> Any:
    
    res = yaml.load(file_object)

    # convert if required
    return ConversionFinder.convert_collection_values_according_to_pep(res, desired_type, conversion_finder, logger,
                                                                       **kwargs)
189743
def build_from_yamlfile(yamlfile):
        
        d = yaml.load(open(yamlfile))
        return MktimeFilterDict(d['aliases'], d['selections'])
1004195
def yaml_parse(yamlstr):
    """"""
    try:
        # PyYAML doesn't support json as well as it should, so if the input
        # is actually just json it is better to parse it with the standard
        # json parser.
        return json.loads(yamlstr)
    except ValueError:
        yaml.SafeLoader.add_multi_constructor("!", intrinsics_multi_constructor)
        return yaml.safe_load(yamlstr)
65179
def _parse_yaml_config(config_data=None):
    
    data_map = default_config()

    # If we were given config data to use, use it.  Otherwise, see if there is
    # a furious.yaml to read the config from.  Note that the empty string will
    # result in the default config being used.
    if config_data is None:
        config_data = _load_yaml_config()

    if not config_data:
        logging.debug("No custom furious config, using default config.")
        return data_map

    # TODO: validate the yaml contents
    config = yaml.safe_load(config_data)

    # If there was a valid custom config, it will be a dict.  Otherwise,
    # ignore it.
    if isinstance(config, dict):
        # Apply the custom config over the default config.  This allows us to
        # extend functionality without breaking old stuff.
        data_map.update(config)
    elif not None:
        raise InvalidYamlFile("The furious.yaml file "
                              "is invalid yaml")

    return data_map
198100
def post_parse_action(self, entry):
        """"""
        if 'source_host' in entry.keys():
            host = self.ip_port_regex.findall(entry['source_host'])
            if host:
                hlist = host[0].split('.')
                entry['source_host'] = '.'.join(hlist[:4])
                entry['source_port'] = hlist[-1]
        if 'dest_host' in entry.keys():
            host = self.ip_port_regex.findall(entry['dest_host'])
            if host:
                hlist = host[0].split('.')
                entry['dest_host'] = '.'.join(hlist[:4])
                entry['dest_port'] = hlist[-1]

        return entry
404237
def Parse(factory, file):
    

    entities = []

    while 1:
        # Just gets the whole struct nicely formatted
        data = GetNextStruct(file)

        if not data:
            break

        entities.extend(ProcessStruct(factory, data))

    return entities
956326
def parse_yaml(self, y):
        '''

        '''
        self._targets = []
        if 'targets' in y:
            for t in y['targets']:
                if 'waitTime' in t['condition']:
                    new_target = WaitTime()
                elif 'preceding' in t['condition']:
                    new_target = Preceding()
                else:
                    new_target = Condition()
                new_target.parse_yaml(t)
                self._targets.append(new_target)
        return self
56193
def parse_model_file(path):
    

    context = FilePathContext(path)

    format = resolve_format(None, context.filepath)
    if format == 'tsv':
        logger.debug('Parsing model file {} as TSV'.format(context.filepath))
        with context.open('r') as f:
            for reaction_id in parse_model_table_file(context, f):
                yield reaction_id
    elif format == 'yaml':
        logger.debug('Parsing model file {} as YAML'.format(context.filepath))
        with context.open('r') as f:
            for reaction_id in parse_model_yaml_file(context, f):
                yield reaction_id
830079
def load_yaml(filename):
    
    try:
        with open(filename, 'rb') as f:
            return yaml.load(f, Loader=Loader)
    except (IOError, yaml.error.YAMLError) as exc:
        raise ConfigReadError(filename, exc)
11916
def parse_yaml(self, y):
        ''''''
        super(TargetPort, self).parse_yaml(y)
        self.port_name = y['portName']
        return self
1172566
def parse_entry(source, loc, tokens):
    
    type_ = tokens[1].lower()
    entry_type = structures.TypeRegistry.get_type(type_)
    if entry_type is None or not issubclass(entry_type, structures.Entry):
        raise exceptions.UnsupportedEntryType(
                "%s is not a supported entry type" % type_
            )
    new_entry = entry_type()
    new_entry.name = tokens[3]
    for key, value in [t for t in tokens[4:-1] if t != ',']:
        new_entry[key] = value
    return new_entry
618303
def read_yaml(yaml_data, schema):
    
    try:
        resource = resource_stream('atomic_reactor', schema)
        schema = codecs.getreader('utf-8')(resource)
    except (IOError, TypeError):
        logger.error('unable to extract JSON schema, cannot validate')
        raise

    try:
        schema = json.load(schema)
    except ValueError:
        logger.error('unable to decode JSON schema, cannot validate')
        raise
    data = yaml.safe_load(yaml_data)
    validator = jsonschema.Draft4Validator(schema=schema)
    try:
        jsonschema.Draft4Validator.check_schema(schema)
        validator.validate(data)
    except jsonschema.SchemaError:
        logger.error('invalid schema, cannot validate')
        raise
    except jsonschema.ValidationError:
        for error in validator.iter_errors(data):
            path = "".join(
                ('[{}]' if isinstance(element, int) else '.{}').format(element)
                for element in error.path
            )

            if path.startswith('.'):
                path = path[1:]

            logger.error('validation error (%s): %s', path or 'at top level', error.message)

        raise

    return data
807283
def from_file(cls, filepath):
        """"""
        with open(filepath, "rt") as fh:
            return cls(**yaml.safe_load(fh))
1057462
def parse_reaction_list(path, reactions, default_compartment=None):
    

    context = FilePathContext(path)

    for reaction_def in reactions:
        if 'include' in reaction_def:
            include_context = context.resolve(reaction_def['include'])
            for reaction in parse_reaction_file(
                    include_context, default_compartment):
                yield reaction
        else:
            yield parse_reaction(reaction_def, default_compartment, context)
1145724
def parse_model(self):
        """"""

        if self.has_model_definition():
            for reaction_id in parse_model_group_list(
                    self._context, self._model['model']):
                yield reaction_id