Load common defaults data structures.

    For factorization purpose.
164906
def _load_defaults(inventory_path=None, roles=None, extra_vars=None, tags=None,
                   basedir=False):
    """"""

    extra_vars = extra_vars or {}
    tags = tags or []
    loader = DataLoader()
    if basedir:
        loader.set_basedir(basedir)

    inventory = EnosInventory(loader=loader,
                              sources=inventory_path, roles=roles)

    variable_manager = VariableManager(loader=loader,
                                       inventory=inventory)

    # seems mandatory to load group_vars variable
    if basedir:
        variable_manager.safe_basedir = True

    if extra_vars:
        variable_manager.extra_vars = extra_vars

    # NOTE(msimonin): The ansible api is "low level" in the
    # sense that we are redefining here all the default values
    # that are usually enforce by ansible called from the cli
    Options = namedtuple("Options", ["listtags", "listtasks",
                                     "listhosts", "syntax",
                                     "connection", "module_path",
                                     "forks", "private_key_file",
                                     "ssh_common_args",
                                     "ssh_extra_args",
                                     "sftp_extra_args",
                                     "scp_extra_args", "become",
                                     "become_method", "become_user",
                                     "remote_user", "verbosity",
                                     "check", "tags",
                                     "diff", "basedir"])

    options = Options(listtags=False, listtasks=False,
                      listhosts=False, syntax=False, connection="ssh",
                      module_path=None, forks=100,
                      private_key_file=None, ssh_common_args=None,
                      ssh_extra_args=None, sftp_extra_args=None,
                      scp_extra_args=None, become=None,
                      become_method="sudo", become_user="root",
                      remote_user=None, verbosity=2, check=False,
                      tags=tags, diff=None, basedir=basedir)

    return inventory, variable_manager, loader, options
382295
def load(self):
        
        if self._defaults_file is not None:
            if not os.path.exists(self._defaults_file):
                msg = "Unable to find defaults file: {}".format(self._defaults_file)
                LOGGER.error(msg)
                raise RuntimeError(msg)
            with open(self._defaults_file, 'r') as handle:
                self._defaults = json.load(handle)
                self.update(self._defaults)

        if self._settings_file is None:
            msg = "No context file has been provided"
            LOGGER.error(msg)
            raise RuntimeError(msg)
        if not os.path.exists(self._settings_file):
            msg = "Unable to find settings file: {}".format(self._settings_file)
            LOGGER.error(msg)
            raise RuntimeError(msg)
        with open(self._settings_file, 'r') as handle:
            settings = json.load(handle)
            update(self, settings)

        return
358380
def load_default(self):
        ''' 
        '''
        appdir = AppDirs(self.application_name, self.application_author,
                version=self.application_version)
        file_name = os.path.join(appdir.site_data_dir, "{0}.conf".format(
                self.application_name.lower()))
        if os.path.exists(file_name):
            self.load(file_name)
        if os.name is not 'posix' or os.getuid() > 0:
            config_file = os.path.join(appdir.user_data_dir, '{0}.conf'.format(
                    self.application_name.lower()))
            if os.path.exists(config_file):
                self.load(config_file)
1304098
def _add_defaults_python(self):
        """"""
        if self.distribution.has_pure_modules():
            build_py = self.get_finalized_command('build_py')
            self.filelist.extend(build_py.get_source_files())
            # This functionality is incompatible with include_package_data, and
            # will in fact create an infinite recursion if include_package_data
            # is True.  Use of include_package_data will imply that
            # distutils-style automatic handling of package_data is disabled
            if not self.distribution.include_package_data:
                for _, src_dir, _, filenames in build_py.data_files:
                    self.filelist.extend([os.path.join(src_dir, filename)
                                          for filename in filenames])
1251952
def load(*files):
    
    if len(files) == 0:
        raise errors.ConfigError("No config files provided.")
    doc = merge(*(yaml.safe_load(f) for f in files))
    return propagate_defaults(doc)
542486
def from_defaults(clz, defaults):
        
        if isinstance(defaults, (str, unicode)):
            defaults = json.loads(defaults)
        
        c = clz()
        for attribute in defaults.keys():
            if attribute in c:
                value = defaults[attribute]
                c[attribute].merge(value)
        # in case any values were not specified, attempt to merge them with 
        # the settings provided by clz.random()
        cr = clz.random()
        for attribute, value in cr:
            try:
                c[attribute].merge(value)
            except Contradiction:
                pass
        return c
845714
def defaults(current: dict, *args: AnyMapping) -> dict:
    
    """
    for data in args:
        for key, value in data.items():
            current.setdefault(key, value)
    return current
60515
def set_defaults(self):
        """"""

        for const_name, c in file_classes.items():
            if c.multiplicity == '1':
                f = self.file(const_name)
                if not f.record.unpacked_contents:
                    f.setcontent(f.default)
594455
def load_bulk(cls, bulk_data, parent=None, keep_ids=False):
        """"""

        cls = get_result_class(cls)

        # tree, iterative preorder
        added = []
        if parent:
            parent_id = parent.pk
        else:
            parent_id = None
        # stack of nodes to analize
        stack = [(parent_id, node) for node in bulk_data[::-1]]
        foreign_keys = cls.get_foreign_keys()
        while stack:
            parent_id, node_struct = stack.pop()
            # shallow copy of the data strucure so it doesn't persist...
            node_data = node_struct['data'].copy()
            cls._process_foreign_keys(foreign_keys, node_data)
            if keep_ids:
                node_data['id'] = node_struct['id']
            if parent_id:
                parent = cls.objects.get(pk=parent_id)
                node_obj = parent.add_child(**node_data)
            else:
                node_obj = cls.add_root(**node_data)
            added.append(node_obj.pk)
            if 'children' in node_struct:
                # extending the stack with the current node as the parent of
                # the new nodes
                stack.extend([
                    (node_obj.pk, node)
                    for node in node_struct['children'][::-1]
                ])
        return added
236470
def gather_defaults(self):
        
        total_defaults = 0
        defaults_lines = []

        if not os.path.exists(self.paths["defaults"]):
            # reset the defaults if no defaults were found
            self.defaults = ""
            return 0

        file = open(self.paths["defaults"], "r")
        for line in file:
            if len(line) > 0:
                first_char = line[0]
            else:
                first_char = ""

            defaults_lines.append(line)

            if (first_char != "#" and first_char != "-" and
                    first_char != " " and
                    first_char != "\r" and
                    first_char != "\n" and
                    first_char != "\t"):
                total_defaults += 1
        file.close()

        self.defaults = "".join(defaults_lines)

        return total_defaults
1198797
function dict(schema, defaults, options) {
  if (kindOf(schema) !== 'array' || schema.length !== 2) {
    if (process.env.NODE_ENV !== 'production') {
      throw new Error(
        `Dict structs must be defined as an array with two elements, but you passed: ${schema}`
      )
    } else {
      throw new Error(`Invalid schema: ${schema}`)
    }
  }

  const obj = scalar('object', undefined, options)
  const keys = any(schema[0], undefined, options)
  const values = any(schema[1], undefined, options)
  const name = 'dict'
  const type = `dict<${keys.type},${values.type}>`
  const validate = value => {
    const resolved = resolveDefaults(defaults)
    value = resolved ? { ...resolved, ...value } : value
    const [error] = obj.validate(value)

    if (error) {
      error.type = type
      return [error]
    }

    const ret = {}
    const errors = []

    for (let k in value) {
      const v = value[k]
      const [e, r] = keys.validate(k)

      if (e) {
        const allE = e.errors || [e]
        allE.forEach(singleE => {
          singleE.path = [k].concat(singleE.path)
          singleE.data = value
          errors.push(singleE)
        })
        continue
      }

      k = r
      const [e2, r2] = values.validate(v)

      if (e2) {
        const allE2 = e2.errors || [e2]
        allE2.forEach(singleE => {
          singleE.path = [k].concat(singleE.path)
          singleE.data = value
          errors.push(singleE)
        })
        continue
      }

      ret[k] = r2
    }

    if (errors.length) {
      const first = errors[0]
      first.errors = errors
      return [first]
    }

    return [undefined, ret]
  }

  return new Kind(name, type, validate)
}
60997
def diffFromDefaults(theTask, report=False):
    
    # get the 2 dicts (trees: dicts of dicts)
    defaultTree = load(theTask, canExecute=False, strict=True, defaults=True)
    thisTree    = load(theTask, canExecute=False, strict=True, defaults=False)
    # they must be flattenable
    defaultFlat = cfgpars.flattenDictTree(defaultTree)
    thisFlat    = cfgpars.flattenDictTree(thisTree)
    # use the "set" operations till there is a dict.diff()
    # thanks to:  http://stackoverflow.com/questions/715234
    diffFlat = dict( set(thisFlat.items()) - \
                     set(defaultFlat.items()) )
    if report:
        defaults_of_diffs_only = {}
#       { k:defaultFlat[k] for k in diffFlat.keys() }
        for k in diffFlat:
            defaults_of_diffs_only[k] = defaultFlat[k]
        msg = 'Non-default values of "'+str(theTask)+'":\n'+ \
              _flat2str(diffFlat)+ \
              '\n\nDefault values:\n'+ \
              _flat2str(defaults_of_diffs_only)
        print(msg)
    return diffFlat
1139673
def load(obj, cls, default_factory):
    
    if obj is None:
        return default_factory()
    if isinstance(obj, dict):
        return cls.load(obj)
    return obj
83428
def load_defaults_files(files)
      # collect the class => path => value entries from each defaults file
      hash = LazyHash.new { Hash.new }
      files.enumerate { |file| load_defaults_file(file, hash) }
      hash
    end
1280741
def load_defaults(self):
        '''
        
        '''
        # Load the user extract file first to ensure its rules take precedence.
        extract_files = [
            self.config.settings.user.extract,
            self.config.settings.system.extract,
        ]

        for extract_file in extract_files:
            if extract_file:
                try:
                    self.load_from_file(extract_file)
                except KeyboardInterrupt as e:
                    raise e
                except Exception as e:
                    if binwalk.core.common.DEBUG:
                        raise Exception("Extractor.load_defaults failed to load file '%s': %s" % (extract_file, str(e)))
1265435
def _parse_variable_defaults(cls, defaults):
        """"""

        default_dict = {}

        for item in defaults:
            key = next(iter(item))
            value = item[key]

            if key in default_dict:
                raise RecipeFileInvalid("Default variable value specified twice", name=key, old_value=default_dict[key], new_value=value)

            default_dict[key] = value

        return default_dict
1354278
def processAndSetDefaults(self):
        
        # INPUT, OUTPUT, GIVEN + BUILDABLE DEPS
        if not self.input:
            raise ValueError(NO_INPUT_FILE)

        if not self.output:
            # Build directory must exist, right?
            if not self.build_directory:
                File()
            pass  # Can it be built? / reference self.output_format for this
        else:
            pass  # if it is not congruent with other info provided

        if not self.build_directory:
            pass  # Initialize it

        for dependency in self.given_dependencies:
            pass  # Check if the dependcy exists

        if self.output_format != self.output.getType():
            raise ValueError("")
        # Given dependencies must actually exist!
        # output_name must be at a lower extenion level than input_name
        # The build directory
        return