Read configuration from a file-like object.
971475
def from_file(cls, f):
        """"""
        ret = cls()
        section = None
        setting = None
        for lineno, line in enumerate(f.readlines()):
            line = line.lstrip()
            if setting is None:
                if _strip_comments(line).strip() == "":
                    continue
                if line[0] == "[":
                    line = _strip_comments(line).rstrip()
                    if line[-1] != "]":
                        raise ValueError("expected trailing ]")
                    key = line.strip()
                    pts = key[1:-1].split(" ", 1)
                    pts[0] = pts[0].lower()
                    if len(pts) == 2:
                        if pts[1][0] != "\"" or pts[1][-1] != "\"":
                            raise ValueError(
                                "Invalid subsection " + pts[1])
                        else:
                            pts[1] = pts[1][1:-1]
                        if not _check_section_name(pts[0]):
                            raise ValueError("invalid section name %s" %
                                             pts[0])
                        section = (pts[0], pts[1])
                    else:
                        if not _check_section_name(pts[0]):
                            raise ValueError("invalid section name %s" %
                                    pts[0])
                        pts = pts[0].split(".", 1)
                        if len(pts) == 2:
                            section = (pts[0], pts[1])
                        else:
                            section = (pts[0], )
                    ret._values[section] = {}
                else:
                    if section is None:
                        raise ValueError("setting %r without section" % line)
                    try:
                        setting, value = line.split("=", 1)
                    except ValueError:
                        setting = line
                        value = "true"
                    setting = setting.strip().lower()
                    if not _check_variable_name(setting):
                        raise ValueError("invalid variable name %s" % setting)
                    if value.endswith("\\\n"):
                        value = value[:-2]
                        continuation = True
                    else:
                        continuation = False
                    value = _parse_string(value)
                    ret._values[section][setting] = value
                    if not continuation:
                        setting = None
            else:  # continuation line
                if line.endswith("\\\n"):
                    line = line[:-2]
                    continuation = True
                else:
                    continuation = False
                value = _parse_string(line)
                ret._values[section][setting] += value
                if not continuation:
                    setting = None
        return ret
348992
def read(config_file, configspec, server_mode=False, default_section='default_settings', list_values=True):
    '''
    
    '''
#    configspec = ConfigObj(path.join(path.abspath(path.dirname(__file__)), configspec),
#                           encoding='UTF8',
#                           interpolation='Template',
#                           list_values=False,
#                           _inspec=True)
    config = ConfigObj(config_file,
                       configspec=path.join(path.abspath(path.dirname(__file__)),
                                            configspec),
                                            list_values=list_values)
    validation = config.validate(validate.Validator(), preserve_errors=True)

    if validation == True:
        config = dict(config)
        for section in config:
            if section != default_section:
                if server_mode: # When it's a servers config file, retrieve the correct fqdn
                    config[section]['availability'] = True
                    if config[section]['custom_fqdn'] == None:
                        config[section]['custom_fqdn'] = socket.getfqdn()
                for option in config[section]:  # retrieve default configuration for missing values
                    if config[section][option] == None:
                        config[section][option] = config[default_section][option]

        del(config[default_section])

        return config
    else:
        raise ConfiguratorException(config_file, validation)
1211818
def read_config(config_path):
    """"""
    result = {}
    with open(config_path, 'r') as fd:
        for line in fd.readlines():
            if '=' in line:
                key, value = line.split('=', 1)
                try:
                    result[key] = json.loads(value)
                except ValueError:
                    result[key] = value.rstrip('\n')
    return result
883117
def config_from_file(self, config_file=None):
        """"""
        if PYLINT_VERSION >= (1, 5):
            self.read_config_file(config_file)
            if self.cfgfile_parser.has_option('MASTER', 'load-plugins'):
                # pylint: disable=protected-access
                plugins = _splitstrip(self.cfgfile_parser.get('MASTER', 'load-plugins'))
                self.load_plugin_modules(plugins)
            self.load_config_file()
            return True

        self.load_file_configuration(config_file)
        return False
1306953
def from_object(self, obj: Union[str, Any]) -> None:
        """"""
        if isinstance(obj, str):
            obj = importer.import_object_str(obj)

        for key in dir(obj):
            if key.isupper():
                value = getattr(obj, key)
                self._setattr(key, value)

        logger.info("Config is loaded from object: %r", obj)
617359
def _load_config():
    """"""
    fname = _get_config_fname()
    if fname is None or not op.isfile(fname):
        return dict()
    with open(fname, 'r') as fid:
        config = json.load(fid)
    return config
252229
def _read(self):
        """"""
        with open(self.path, 'r') as file_handle:

            content = file_handle.read()

        # Py27 INI config parser chokes if the content provided is not unicode.
        # All other versions seems to work appropriately. Forcing the value to
        # unicode here in order to resolve this issue.
        return compat.unicode(content)
1051763
def parsed_file(config_file):
    """"""
    parser = ConfigParser(allow_no_value=True)
    parser.readfp(config_file)
    return parser
1086719
def read_config():
    """"""
    config = configparser.RawConfigParser(allow_no_value=True)
    config.read(get_config_path())
    if not config.has_section('credentials'):
        config.add_section('credentials')
        config.set('credentials', 'key', '')
        config.set('credentials', 'secret', '')
        write_config(config)
    return config
1120756
def _read_config(self):
        
        
        this_dir = os.path.dirname(__file__)        
        config_file = os.path.abspath(os.path.join(this_dir, "..", "config", "config.json"))

        self.generic_enum_attrs = []
        self.base_attrs = []
        self.generic_enums = []
        self.named_entity_attrs = []
        self.overide_generic_enums = []
        self.enum_attrs_for_locale = {}
        self.generic_enum_attrs_for_locale = {}
        self.list_subtypes_generic = []
        
        Printer.log("Configuration file: %s" % (config_file))

        if (os.path.isfile(config_file)):
            with open(config_file, 'r') as input_json:
                json_config_data = json.load(input_json) 
                
            self.base_attrs = json_config_data['base_attrs']
            self.generic_enums =  json_config_data['generic_enums']
            self.named_entity_attrs = json_config_data['named_entity_attrs']
            self.overide_generic_enums = json_config_data['overide_generic_enums']
            self.list_subtypes_generic = json_config_data['list_subtypes_generic']

            for enum_name, values in self.generic_enums.iteritems():
                enum_attr =  SpecificationAttribute()
                enum_attr.name = enum_name
                enum_attr.allowed_choices = values
                self.generic_enum_attrs.append(enum_attr)
        else:
            Printer.log("Configuration file missing: %s" % (config_file))
905380
def load_config(filename=None):
    
    try:
        with _config_stream(filename) as handle:
            filename = handle.name
            return deserialize_config(handle.read())
    except (OSError, toml.TomlDecodeError, UnicodeDecodeError) as exc:
        raise ConfigError(
            'Error loading configuration from {}'.format(filename)) from exc
122094
def _read_file(file_name):
    
    with open(file_name) as config_file:
        data = json.load(config_file)
    return data
1155853
def read_settings(filename=None, defs=None):
    
    # READ SETTINGS
    defs = listwrap(defs)
    defs.append({
        "name": ["--config", "--settings", "--settings-file", "--settings_file"],
        "help": "path to JSON file with settings",
        "type": str,
        "dest": "filename",
        "default": None,
        "required": False
    })
    args = argparse(defs)

    args.filename = coalesce(filename, args.filename, "./config.json")
    settings_file = File(args.filename)
    if not settings_file.exists:
        Log.error("Can not read configuration file {{filename}}", {
            "filename": settings_file.abspath
        })
    settings = mo_json_config.get_file(settings_file)
    settings.args = args
    return settings
827859
function obtainConfig(file) {
  let json;
  try {
    const jsonFile = fs.readFileSync(file);
    json = JSON.parse(jsonFile);
  } catch (err) {
    throw Error(`fail to load/parse your '${file}': ${err.message}`);
  }
  return json;
}
1190747
def _get_config(config_file):
    ''''''
    parser = ConfigParser.SafeConfigParser()
    if os.path.lexists(config_file):
        try:
            log.info('Reading config: %s', config_file)
            inp = open(config_file)
            parser.readfp(inp)
            return parser
        except (IOError, ConfigParser.ParsingError), err:
            raise ConfigError("Failed to read configuration %s\n%s" % (config_file, err))
    return None
520308
def parseconf (self, filename):
        """"""
        with open(filename) as fd:
            # yet another config format, sigh
            for line in fd:
                line = line.strip()
                if not line or line.startswith("#"):
                    # ignore empty lines and comments
                    continue
                split = line.split(None, 1)
                if len(split) == 1:
                    self[split[0]] = True
                else:
                    self[split[0]] = split[1]
497283
def _read_config_file(self):
        """"""

        try:
            with open(self.config, 'r') as f:
                config_data = json.load(f)
        except FileNotFoundError:
            config_data = {}

        return config_data