Load a set of facts into the CLIPS data base.

        The C equivalent of the CLIPS load-facts command.

        Facts can be loaded from a string or from a text file.
12516
def load_facts(self, facts):
        
        facts = facts.encode()

        if os.path.exists(facts):
            ret = lib.EnvLoadFacts(self._env, facts)
            if ret == -1:
                raise CLIPSError(self._env)
        else:
            ret = lib.EnvLoadFactsFromString(self._env, facts, -1)
            if ret == -1:
                raise CLIPSError(self._env)

        return ret
676473
function load(opts, cb) {
  if(typeof opts === 'function') {
    cb = opts;
    opts = null;
  }
  opts = opts || {};
  var files = opts.commands || []
    , i = 0
    , list = []
    , conf = opts.conf
    , rename = conf.get(ConfigKey.RENAME_COMMAND) || []
    , commands = {};

  if(!Array.isArray(files)) {
    files = [files];
  }

  function complete(err) {
    if(err) return cb(err);
    if(Object.keys(commands).length === 0) {
      return cb(new Error('no command definitions found'));
    }
    cb(null, commands);
  }

  /**
   *  Requires the array of files.
   */
  function include(list) {
    var cmd, clazz, i, file, j, name, newname;
    for(i = 0;i < list.length;i++) {
      file = list[i];
      try {
        clazz = require(file);
        // assume it is already instantiated
        if(typeof clazz === 'object') {
          cmd = clazz;
        }else{
          cmd = new clazz(clazz.definition);
        }

        // rename and delete commands
        if(cmd && cmd.definition && cmd.definition.name) {
          for(j = 0;j < rename.length;j++) {
            name = rename[j][0];
            newname = rename[j][1];
            if(name
              && name.toLowerCase() === cmd.definition.name.toLowerCase()) {
              newname = (newname || '').toLowerCase();
              // actually renaming
              if(newname) {
                log.warning(
                  'rename command %s -> %s', cmd.definition.name, newname);
                cmd.definition.name = newname;
              // deleting the command, mark as deleted with false
              }else{
                log.warning(
                  'deleted command %s (%s)', cmd.definition.name, file);
                commands[cmd.definition.name] = false;
                // clear the module cache
                delete require.cache[file];
              }
              break;
            }
          }
        }

        // deleted the command
        if(!require.cache[file]) continue;

        // sanity checks
        if(!(cmd instanceof CommandExec)) {
          throw new Error(
            util.format(
              'module does not export a command exec instance (%s)', file));
        }else if(
          !cmd.definition
          || !cmd.definition.constructor
          || cmd.definition.constructor.name !== Command.name) {
          throw new Error(
            util.format(
              'command does not have a valid definition (%s)', file));
        }else if(!cmd.definition.name) {
          throw new Error(
            util.format(
              'command definition does not have a name (%s)', file));
        }

        if(opts.override !== true && commands[cmd.definition.name]) {
          throw new Error(util.format(
              'duplicate command %s (%s)', cmd.definition.name, file));
        }

        log.debug('loaded %s (%s)', cmd.definition.name, file);

        // map of command names to command exec handlers
        commands[cmd.definition.name] = cmd;
      }catch(e) {
        return complete(e);
      }
    }
    complete();
  }

  /**
   *  Walk the file list array.
   */
  function walk(files, cb, list) {
    var i = 0;
    list = list || [];

    function check(file, cb) {
      fs.stat(file, function onStat(err, stats) {
        if(err) return cb(err);
        if(stats.isFile() && !/\.js$/.test(file)) {
          log.warning('ignoring %s', file);
          return cb();
        }
        if(stats.isFile()) {
          list.push(file);
          return cb(null, list);
        }else{
          return fs.readdir(file, function onRead(err, files) {
            if(err) return cb(err);
            if(!files.length) return cb();
            files = files.map(function(nm) {
              return path.join(file, nm);
            })
            //files.forEach()
            return walk(files, cb, list);
          })
        }
      });
    }

    check(files[i], function onCheck(err, list) {
      if(err) return cb(err);
      if(i === files.length - 1) {
        return cb(null, list);
      }
      i++;
      check(files[i], onCheck);
    });
  }

  walk(files, function onList(err, list) {
    if(err) return complete(err);
    if(list.length === 0) {
      return complete(new Error('no command files found'));
    }
    include(list);
  });
}
452462
def loadrc(filename):
    '''
    
    '''
    filename = os.path.expanduser(os.path.expandvars(filename))
    if not os.path.isfile(filename): raise ValueError('Filename %s does not exist' % filename)
    with open(filename, 'r') as fl:
        dat = json.load(fl)
    try: dat = dict(dat)
    except Exception: raise ValueError('Given file %s does not contain a dictionary' % filename)
    return dat
837507
def gather_facts(self):
        
        facts = []

        for file in self.yaml_files:
            facts += self.gather_facts_list(file)

        unique_facts = list(set(facts))
        self.facts = unique_facts

        return len(unique_facts)
674831
def _parse_fact_dir(self, fact_dir, fact_cache=False):
        
        self.log.debug("Parsing fact dir: {0}".format(fact_dir))
        if not os.path.isdir(fact_dir):
            raise IOError("Not a directory: '{0}'".format(fact_dir))

        flist = []
        for (dirpath, dirnames, filenames) in os.walk(fact_dir):
            flist.extend(filenames)
            break

        for fname in flist:
            if fname.startswith('.'):
                continue
            self.log.debug("Reading host facts from {0}".format(os.path.join(fact_dir, fname)))
            hostname = fname

            fd = codecs.open(os.path.join(fact_dir, fname), 'r', encoding='utf8')
            s = fd.readlines()
            fd.close()
            try:
                x = json.loads(''.join(s))
                # for compatibility with fact_caching=jsonfile
                # which omits the "ansible_facts" parent key added by the setup module
                if fact_cache:
                    x = json.loads('{ "ansible_facts": ' + ''.join(s) + ' }')
                self.update_host(hostname, x)
                self.update_host(hostname, {'name': hostname})
            except ValueError as e:
                # Ignore non-JSON files (and bonus errors)
                self.log.warning("Error parsing: %s: %s" % (fname, e))
1371747
def loads(content):
    """"""
    lines = _group_lines(line for line in content.split('\n'))
    lines = [
        (i, _parse_envfile_line(line))
        for i, line in lines if line.strip()
    ]
    errors = []
    # Reject files with duplicate variables (no sane default).
    duplicates = _find_duplicates(((i, line[0]) for i, line in lines))
    for i, variable, j in duplicates:
        errors.append(''.join([
                'Line %d: duplicate environment variable "%s": ',
                'already appears on line %d.',
            ]) % (i + 1, variable, j + 1)
        )
    # Done!
    if errors:
        raise ValueError(errors)
    return {k: v for _, (k, v) in lines}
420442
def _loadData(self, data):
        
        self._setValue = None
        self.id = data.attrib.get('id')
        self.label = data.attrib.get('label')
        self.summary = data.attrib.get('summary')
        self.type = data.attrib.get('type')
        self.default = self._cast(data.attrib.get('default'))
        self.value = self._cast(data.attrib.get('value'))
        self.hidden = utils.cast(bool, data.attrib.get('hidden'))
        self.advanced = utils.cast(bool, data.attrib.get('advanced'))
        self.group = data.attrib.get('group')
        self.enumValues = self._getEnumValues(data)
740431
def new_fact(self):
        """"""
        fact = lib.EnvCreateFact(self._env, self._tpl)
        if fact == ffi.NULL:
            raise CLIPSError(self._env)

        return new_fact(self._env, fact)
983737
def Parse(self, stat, file_object, knowledge_base):
    """"""
    _ = knowledge_base
    # TODO(user): Convert this to use the far more intelligent plaso parser.
    chrome = ChromeParser(file_object)
    for timestamp, entry_type, url, data1, _, _ in chrome.Parse():
      if entry_type == "CHROME_DOWNLOAD":
        yield rdf_webhistory.BrowserHistoryItem(
            url=url,
            domain=urlparse.urlparse(url).netloc,
            access_time=timestamp,
            program_name="Chrome",
            source_path=file_object.Path(),
            download_path=data1)
      elif entry_type == "CHROME_VISIT":
        yield rdf_webhistory.BrowserHistoryItem(
            url=url,
            domain=urlparse.urlparse(url).netloc,
            access_time=timestamp,
            program_name="Chrome",
            source_path=file_object.Path(),
            title=data1)
397965
def _loadData(self, data):
        
        self._data = data
        self.id = utils.cast(int, data.attrib.get('id'))
        self.serverId = utils.cast(int, data.attrib.get('serverId'))
        self.machineIdentifier = data.attrib.get('machineIdentifier')
        self.name = data.attrib.get('name')
        self.lastSeenAt = utils.toDatetime(data.attrib.get('lastSeenAt'))
        self.numLibraries = utils.cast(int, data.attrib.get('numLibraries'))
        self.allLibraries = utils.cast(bool, data.attrib.get('allLibraries'))
        self.owned = utils.cast(bool, data.attrib.get('owned'))
        self.pending = utils.cast(bool, data.attrib.get('pending'))
195677
def load_from_file(path, fmt=None, is_training=True):
    '''
    
    '''
    if fmt is None:
        fmt = 'squad'
    assert fmt in ['squad', 'csv'], 'input format must be squad or csv'
    qp_pairs = []
    if fmt == 'squad':
        with open(path) as data_file:
            data = json.load(data_file)['data']
            for doc in data:
                for paragraph in doc['paragraphs']:
                    passage = paragraph['context']
                    for qa_pair in paragraph['qas']:
                        question = qa_pair['question']
                        qa_id = qa_pair['id']
                        if not is_training:
                            qp_pairs.append(
                                {'passage': passage, 'question': question, 'id': qa_id})
                        else:
                            for answer in qa_pair['answers']:
                                answer_begin = int(answer['answer_start'])
                                answer_end = answer_begin + len(answer['text'])
                                qp_pairs.append({'passage': passage,
                                                 'question': question,
                                                 'id': qa_id,
                                                 'answer_begin': answer_begin,
                                                 'answer_end': answer_end})
    else:
        with open(path, newline='') as csvfile:
            reader = csv.reader(csvfile, delimiter='\t')
            line_num = 0
            for row in reader:
                qp_pairs.append(
                    {'passage': row[1], 'question': row[0], 'id': line_num})
                line_num += 1
    return qp_pairs
1037397
def from_data(data):
        """"""
        header, length = struct.unpack('4s<I', data[:8])
        data = data[8:]
        return RiffDataChunk(header, data)
1325910
def clip(self, channels=True):
        """"""
        if not isinstance(channels, (tuple, list)):
            channels = [channels] * len(self.channels)

        for i in range(len(self.channels)):
            if channels[i]:
                self.channels[i] = np.ma.clip(self.channels[i], 0.0, 1.0)
1005362
def _load_general(data, targets):
    """"""
    for d_src, d_targets in zip(data, targets):
        if isinstance(d_targets, nd.NDArray):
            d_src.copyto(d_targets)
        else:
            assert d_targets[-1][0].stop == d_src.shape[0], \
                "Batch size miss match. Expected %d, got %d"%( \
                    d_targets[-1][0].stop, d_src.shape[0])
            for slice_idx, d_dst in d_targets:
                d_src[slice_idx].copyto(d_dst)
1192497
def load(self, filename, *, metadata=None):
        
        with open(filename, "rt", encoding="utf-8") as file:
            text = file.read()
        self.parse(text, metadata=metadata, filename=filename)
1204814
def get_facts(state, name, args=None, ensure_hosts=None):
    '''
    
    '''

    # Create an instance of the fact
    fact = FACTS[name]()

    if isinstance(fact, ShortFactBase):
        return get_short_facts(state, fact, args=args, ensure_hosts=ensure_hosts)

    logger.debug('Getting fact: {0} (ensure_hosts: {1})'.format(
        name, ensure_hosts,
    ))

    args = args or []

    # Apply args or defaults
    sudo = state.config.SUDO
    sudo_user = state.config.SUDO_USER
    su_user = state.config.SU_USER
    ignore_errors = state.config.IGNORE_ERRORS

    # Timeout for operations !== timeout for connect (config.CONNECT_TIMEOUT)
    timeout = None

    # Get the current op meta
    current_op_hash = state.current_op_hash
    current_op_meta = state.op_meta.get(current_op_hash)

    # If inside an operation, fetch config meta
    if current_op_meta:
        sudo = current_op_meta['sudo']
        sudo_user = current_op_meta['sudo_user']
        su_user = current_op_meta['su_user']
        ignore_errors = current_op_meta['ignore_errors']
        timeout = current_op_meta['timeout']

    # Make a hash which keeps facts unique - but usable cross-deploy/threads.
    # Locks are used to maintain order.
    fact_hash = make_hash((name, args, sudo, sudo_user, su_user, ignore_errors))

    # Already got this fact? Unlock and return 'em
    current_facts = state.facts.get(fact_hash, {})
    if current_facts:
        if not ensure_hosts or all(
            host in current_facts for host in ensure_hosts
        ):
            return current_facts

    with FACT_LOCK:
        # Add any hosts we must have, whether considered in the inventory or not
        # (these hosts might be outside the --limit or current op limit_hosts).
        hosts = set(state.inventory)
        if ensure_hosts:
            hosts.update(ensure_hosts)

        # Execute the command for each state inventory in a greenlet
        greenlet_to_host = {}

        for host in hosts:
            if host in current_facts:
                continue

            # if host in state.ready_hosts:
            #     continue

            # Work out the command
            command = fact.command

            if ismethod(command) or isfunction(command):
                # Generate actual arguments by pasing strings as jinja2 templates
                host_args = [get_arg_value(state, host, arg) for arg in args]

                command = command(*host_args)

            greenlet = state.fact_pool.spawn(
                host.run_shell_command, state, command,
                sudo=sudo, sudo_user=sudo_user,
                su_user=su_user, timeout=timeout,
                print_output=state.print_fact_output,
            )
            greenlet_to_host[greenlet] = host

        # Wait for all the commands to execute
        progress_prefix = 'fact: {0}'.format(name)
        if args:
            progress_prefix = '{0}{1}'.format(progress_prefix, args)

        with progress_spinner(
            greenlet_to_host.values(),
            prefix_message=progress_prefix,
        ) as progress:
            for greenlet in gevent.iwait(greenlet_to_host.keys()):
                host = greenlet_to_host[greenlet]
                progress(host)

        hostname_facts = {}
        failed_hosts = set()

        # Collect the facts and any failures
        for greenlet, host in six.iteritems(greenlet_to_host):
            status = False
            stdout = []

            try:
                status, stdout, _ = greenlet.get()

            except (timeout_error, socket_error, SSHException) as e:
                failed_hosts.add(host)
                log_host_command_error(
                    host, e,
                    timeout=timeout,
                )

            data = fact.default()

            if status and stdout:
                data = fact.process(stdout)

            hostname_facts[host] = data

        log_name = click.style(name, bold=True)

        filtered_args = list(filter(None, args))
        if filtered_args:
            log = 'Loaded fact {0}: {1}'.format(log_name, tuple(filtered_args))
        else:
            log = 'Loaded fact {0}'.format(log_name)

        if state.print_fact_info:
            logger.info(log)
        else:
            logger.debug(log)

        # Check we've not failed
        if not ignore_errors:
            state.fail_hosts(failed_hosts)

        # Assign the facts
        state.facts.setdefault(fact_hash, {}).update(hostname_facts)

    return state.facts[fact_hash]
407935
def facts(puppet=False):
    '''
    
    '''
    ret = {}
    opt_puppet = '--puppet' if puppet else ''
    cmd_ret = __salt__['cmd.run_all']('facter {0}'.format(opt_puppet))

    if cmd_ret['retcode'] != 0:
        raise CommandExecutionError(cmd_ret['stderr'])

    output = cmd_ret['stdout']

    # Loop over the facter output and  properly
    # parse it into a nice dictionary for using
    # elsewhere
    for line in output.splitlines():
        if not line:
            continue
        fact, value = _format_fact(line)
        if not fact:
            continue
        ret[fact] = value
    return ret