Given a configuration's filename, this returns a stream from which a configuration can be read.

    If `filename` is `None` or '-' then stream will be `sys.stdin`. Otherwise,
    it's the open file handle for the filename.
433805
def _config_stream(filename):
    
    if filename is None or filename == '-':
        log.info('Reading config from stdin')
        yield sys.stdin
    else:
        with open(filename, mode='rt') as handle:
            log.info('Reading config from %r', filename)
            yield handle
1150540
def _check_file(parameters):
    """"""
    (filename, args) = parameters

    if filename == '-':
        contents = sys.stdin.read()
    else:
        with contextlib.closing(
            docutils.io.FileInput(source_path=filename)
        ) as input_file:
            contents = input_file.read()

    args = load_configuration_from_file(
        os.path.dirname(os.path.realpath(filename)), args)

    ignore_directives_and_roles(args.ignore_directives, args.ignore_roles)

    for substitution in args.ignore_substitutions:
        contents = contents.replace('|{}|'.format(substitution), 'None')

    ignore = {
        'languages': args.ignore_language,
        'messages': args.ignore_messages,
    }
    all_errors = []
    for error in check(contents,
                       filename=filename,
                       report_level=args.report,
                       ignore=ignore,
                       debug=args.debug):
        all_errors.append(error)
    return (filename, all_errors)
492170
def _read_configuration_file(self, config_filename):
        
        config = configparser.ConfigParser()
        config.read(config_filename)

        self._source_directory = config.get('loader', 'source_directory')
        self._source_file_extension = config.get('loader', 'extension')
        self._source_file_encoding = config.get('loader', 'encoding')
        self.__shadow_directory = config.get('loader', 'shadow_directory', fallback=None)

        self._pystratum_metadata_filename = config.get('wrapper', 'metadata')

        self._constants_class_name = config.get('constants', 'class')
58459
def _read_file(fname):
    
    with open(fname) as input_file:
        re_grammar = [x.strip('\n') for x in input_file.readlines()]
    return re_grammar
386757
public InputStreamReader getFileStream(String filename)
			throws NoSuchPathException{
		try {
			return new InputStreamReader(new FileInputStream(filename));
		} catch (FileNotFoundException e) {
			throw new NoSuchPathException(e);
		}
	}
278614
def captured_output(stream_name):
    
    orig_stdout = getattr(sys, stream_name)
    setattr(sys, stream_name, StreamWrapper.from_stream(orig_stdout))
    try:
        yield getattr(sys, stream_name)
    finally:
        setattr(sys, stream_name, orig_stdout)
1269633
def load_config(filename):
    
    config = None
    if os.path.isfile(filename) and os.access(filename, os.R_OK):
        with open(filename, 'r') as fh:
            config = json.loads(fh.read())
    return config
259655
def read_config(self, filename):
        
        if not os.path.exists(filename):
            raise Exception("Configuration file cannot be found: %s" % filename)
        with io.open(filename, encoding='UTF-8') as stream:
            return yaml.safe_load(stream)
890864
def _read_configuration(config_filename):
        
        config = ConfigParser()
        config.read(config_filename)

        if 'supplement' in config['database']:
            path = os.path.dirname(config_filename) + '/' + config.get('database', 'supplement')
            config_supplement = ConfigParser()
            config_supplement.read(path)
        else:
            config_supplement = None

        return config, config_supplement
1002809
def _parse_file():
    
    file_name = path.join(
        path.abspath(path.dirname(path.dirname(__file__))), 'config.json'
    )
    logger.info('loading configuration from file: %r', file_name)
    try:
        data = _read_file(file_name)
    except FileNotFoundError:
        logger.error('no configuration available, set FLASH_CONFIG or '
                     'provide config.json')
        exit()
    for service in data.get('services', []):
        for key, val in service.items():
            if isinstance(val, str) and re.match(r'^\$[A-Z_]+$', val):
                env_val = getenv(val[1:])
                if env_val is None:
                    logger.warning('environment variable %r not found', val[1:])
                service[key] = env_val or val
    return data
585498
def read_file(filename, alt=None):
    
    lines = None

    try:
        with open(filename, encoding='utf-8') as f:
            lines = f.read()
    except IOError:
        lines = [] if alt is None else alt
    return lines
97210
def _read_configuration_file(self, path):
        
        parser = RawConfigParser(inline_comment_prefixes=('#', ';'))
        options = None
        should_inherit = True

        if parser.read(path) and self._get_section_name(parser):
            all_options = self._parser.option_list[:]
            for group in self._parser.option_groups:
                all_options.extend(group.option_list)

            option_list = {o.dest: o.type or o.action
                                for o in all_options}

            # First, read the default values
            new_options, _ = self._parse_args([])

            # Second, parse the configuration
            section_name = self._get_section_name(parser)
            for opt in parser.options(section_name):
                if opt == 'inherit':
                    should_inherit = parser.getboolean(section_name, opt)
                    continue

                if opt.replace('_', '-') not in self.CONFIG_FILE_OPTIONS:
                    log.warning("Unknown option '{}' ignored".format(opt))
                    continue

                normalized_opt = opt.replace('-', '_')
                opt_type = option_list[normalized_opt]
                if opt_type in ('int', 'count'):
                    value = parser.getint(section_name, opt)
                elif opt_type == 'string':
                    value = parser.get(section_name, opt)
                else:
                    assert opt_type in ('store_true', 'store_false')
                    value = parser.getboolean(section_name, opt)
                setattr(new_options, normalized_opt, value)

            # Third, fix the set-options
            options = self._fix_set_options(new_options)

        if options is not None:
            if not self._validate_options(options):
                raise IllegalConfiguration('in file: {}'.format(path))

        return options, should_inherit
783685
def _read_file(name, encoding='utf-8') -> str:
    
    with open(name, encoding=encoding) as f:
        return f.read()
811597
def parse_file(fname):
        
        try:
            with fopen(fname) as f:
                fstr = f.read()
        except IOError:
            if fname != 'stdin':
                raise
            sys.stdout.write('\nReading from stdin:\n\n')
            fstr = sys.stdin.read()
        fstr = fstr.replace('\r\n', '\n').replace('\r', '\n')
        if not fstr.endswith('\n'):
            fstr += '\n'
        return ast.parse(fstr, filename=fname)
450151
def read_file(filename, print_error=True):
    """"""
    try:
        for encoding in ['utf-8', 'latin1']:
            try:
                with io.open(filename, encoding=encoding) as fp:
                    return fp.read()
            except UnicodeDecodeError:
                pass
    except IOError as exception:
        if print_error:
            print(exception, file=sys.stderr)
        return None
661726
def read_config_file(self, file_name):
        
        with open(os.path.join(self.__path(), os.path.basename(file_name)),
                  'rt') as file_config:
            return self._parser.parseString(file_config.read())
1094036
def get_configuration(filename):
    
    logger.debug('Reading configuration from {}'.format(filename))
    conf = SafeConfigParser()
    conf.read(filename)

    if not conf:
        logger.error('Configuration file {} not found'.format(filename))
        sys.exit(1)

    if not conf.has_section('general'):
        logger.error('Missing [general] section in the configuration file')
        sys.exit(1)

    try:
        config = {
            'access-key-id': conf.get('general', 'access-key-id'),
            'secret-access-key': conf.get('general', 'secret-access-key'),
            'region': conf.get('general', 'region'),
        }
    except NoOptionError as err:
        logger.error('Error in config file: {}'.format(err))
        sys.exit(1)

    return config