Load a single AgentML file
        :param file_path: Path to the file
        :type  file_path: str
502034
def load_file(self, file_path):
        
        self._log.info('Loading file: ' + file_path)
        agentml = etree.parse(file_path)

        # Validate the file for proper AgentML syntax
        self._schema.assertValid(agentml)

        # Get our root element and parse all elements inside of it
        root = etree.parse(file_path).getroot()
        defaults = {}

        def parse_element(element):
            for child in element:
                # Initialization
                if child.tag == 'init':
                    Init(self, child, file_path)

                # Set the group
                if child.tag == 'group':
                    self._log.info('Setting Trigger group: {group}'.format(group=child.get('name')))
                    defaults['groups'] = {child.get('name')}  # TODO
                    parse_element(child)
                    del defaults['groups']
                    continue

                # Set the topic
                if child.tag == 'topic':
                    self._log.info('Setting Trigger topic: {topic}'.format(topic=child.get('name')))
                    defaults['topic'] = child.get('name')
                    parse_element(child)
                    del defaults['topic']
                    continue

                # Set the emotion
                if child.tag == 'emotion':
                    self._log.info('Setting Trigger emotion: {emotion}'.format(emotion=child.get('name')))
                    defaults['emotion'] = child.get('name')
                    parse_element(child)
                    del defaults['emotion']
                    continue

                # Parse a standard Trigger element
                if child.tag == 'trigger':
                    try:
                        self.add_trigger(Trigger(self, child, file_path, **defaults))
                    except AgentMLError:
                        self._log.warn('Skipping Trigger due to an error', exc_info=True)

        # Begin element iteration by parsing the root element
        parse_element(root)
1330507
def load_from_file(module_path):
    
    from imp import load_module, PY_SOURCE

    imported = None
    if module_path:
        with open(module_path, 'r') as openfile:
            imported = load_module('mod', openfile, module_path, ('imported', 'r', PY_SOURCE))
    return imported
229104
def open_instance_resource(self, path: FilePath, mode: str='rb') -> IO[AnyStr]:
        
        return open(self.instance_path / file_path_to_path(path), mode)
185345
def load_and_set_file_content(self, file_system_path):
        
        semantic_data = load_data_file(os.path.join(file_system_path, storage.SEMANTIC_DATA_FILE))
        self.model.state.semantic_data = semantic_data
186660
def read_file(file_path, mode = 'rt'):
    
    contents = ''
    with open(file_path, mode) as f:
        contents = f.read()
    return contents
824680
def read_file(self, path, **kwargs):
        
        try:
            with open(path, "r") as handle:
                parsed_data = yaml.safe_load(handle)
                return parsed_data
        except IOError:
            LOGGER.warning("Error reading file: {0}".format(path))
        except TypeError:
            LOGGER.warning("Error reading file: {0}".format(path))
        return None
1305923
def set_path(self, file_path):
        
        if not file_path:
            self.read_data = self.memory_read
            self.write_data = self.memory_write
        elif not is_valid(file_path):
            self.write_data(file_path, {})

        self.path = file_path
19015
def load_file(file_path):
        
        log.debug('read data from {0}'.format(file_path))
        if os.path.exists(file_path):
            with open(file_path) as f:
                json_data = json.load(f)

            tf_state = Tfstate(json_data)
            tf_state.tfstate_file = file_path
            return tf_state

        log.debug('{0} is not exist'.format(file_path))

        return Tfstate()
1226382
def fromfile(cls, path):
        
        parser = etree.XMLParser(remove_blank_text=True)

        return cls.fromtree(etree.parse(path, parser=parser))
989918
def loads_json_or_yaml(file_path, content):
    
    if os.path.splitext(file_path)[1] == ".json":
        return json.loads(content)
    else:
        return inginious.common.custom_yaml.load(content)
1030184
def load_from_file(cls, file_path):
        """"""
        data = None
        if os.path.exists(file_path):
            metadata_file = open(file_path)
            data = json.loads(metadata_file.read())
        return cls(initial=data)
344518
def _load_data(path):
    
    path = os.path.abspath(path)
    if not os.path.isdir(path):
        raise InitializationError('Directory not found: {0}'.format(path))
    wordlists = {}
    for file_name in os.listdir(path):
        if os.path.splitext(file_name)[1] != '.txt':
            continue
        file_path = os.path.join(path, file_name)
        name = os.path.splitext(os.path.split(file_path)[1])[0]
        try:
            with codecs.open(file_path, encoding='utf-8') as file:
                wordlists[name] = _load_wordlist(name, file)
        except OSError as ex:
            raise InitializationError('Failed to read {}: {}'.format(file_path, ex))
    config = _load_config(os.path.join(path, 'config.json'))
    return (config, wordlists)
906546
def add_agent_preset(self, file_path):
        
        if file_path is not None and os.path.isfile(file_path):
            name = pathlib.Path(file_path).stem
        else:
            raise FileNotFoundError(f"File path {file_path} is not found!")

        if name in self.agent_presets:
            if self.agent_presets[name].config_path == file_path:
                return self.agent_presets[name]
            else:
                i = 1
                for preset_name in self.agent_presets:
                    if name in preset_name:
                        i += 1
                name = f"{name} ({i})"
        preset = AgentPreset(name, file_path)
        self.agent_presets[preset.get_name()] = preset
        return preset
1321859
def open_resource(self, path: FilePath, mode: str='rb') -> IO[AnyStr]:
        
        if mode not in {'r', 'rb'}:
            raise ValueError('Files can only be opened for reading')
        return open(self.root_path / file_path_to_path(path), mode)
715645
def load_yaml(filepath):
    """"""
    with open(filepath) as f:
        txt = f.read()
    return yaml.load(txt)
804264
def load_requires_from_file(filepath):
    
    with open(filepath) as fp:
        return [pkg_name.strip() for pkg_name in fp.readlines()]
414008
def from_file(cls, file_path, validate=True):
        
        return xmlmap.load_xmlobject_from_file(file_path, xmlclass=cls, validate=validate)