def read_config(filename, args):
<EOL>config = defaultdict(dict)<EOL>splitter = operator.methodcaller('<STR_LIT>', '<STR_LIT:U+0020>')<EOL>converters = {<EOL>__script__: {<EOL>'<STR_LIT>': safe_path,<EOL>'<STR_LIT>': splitter,<EOL>},<EOL>'<STR_LIT>': {<EOL>'<STR_LIT>': splitter,<EOL>'<STR_LIT>': splitter,<EOL>}<EOL>}<EOL>default = copy.deepcopy(CONFIG)<EOL>sections = set(iterkeys(default))<EOL>if int(getattr(pip, '<STR_LIT>', '<STR_LIT>').split('<STR_LIT:.>')[<NUM_LIT:0>]) < <NUM_LIT:6>:<EOL><INDENT>default['<STR_LIT>']['<STR_LIT>'] = safe_path(os.path.expanduser(<EOL>os.path.join('<STR_LIT>', '<STR_LIT>'.format(__script__), '<STR_LIT>')<EOL>))<EOL><DEDENT>is_default = filename == DEFAULT_CONFIG<EOL>filename = os.path.expandvars(os.path.expanduser(filename))<EOL>if not is_default and not os.path.isfile(filename):<EOL><INDENT>print_error('<STR_LIT>'.format(filename))<EOL>return None<EOL><DEDENT>parser = ConfigParser()<EOL>try:<EOL><INDENT>parser.read(filename)<EOL><DEDENT>except ConfigParserError:<EOL><INDENT>print_error('<STR_LIT>'.format(filename))<EOL>return None<EOL><DEDENT>for section in sections:<EOL><INDENT>if not parser.has_section(section):<EOL><INDENT>continue<EOL><DEDENT>items = parser.items(section)<EOL>for key, value in items:<EOL><INDENT>try:<EOL><INDENT>value = int(value)<EOL><DEDENT>except (TypeError, ValueError):<EOL><INDENT>try:<EOL><INDENT>value = bool(strtobool(value))<EOL><DEDENT>except ValueError:<EOL><INDENT>pass<EOL><DEDENT><DEDENT>if section in converters and key in converters[section]:<EOL><INDENT>value = converters[section][key](value)<EOL><DEDENT>config[section][key] = value<EOL><DEDENT><DEDENT>for section, data in iteritems(default):<EOL><INDENT>if section not in config:<EOL><INDENT>config[section] = data<EOL><DEDENT>else:<EOL><INDENT>for key, value in iteritems(data):<EOL><INDENT>config[section].setdefault(key, value)<EOL><DEDENT><DEDENT><DEDENT>keys = set((<EOL>'<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>',<EOL>'<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>'<EOL>))<EOL>for key in keys:<EOL><INDENT>value = getattr(args, key)<EOL>config[__script__].setdefault(key, value)<EOL>if key == '<STR_LIT>' and not value:<EOL><INDENT>continue<EOL><DEDENT>if value is not None:<EOL><INDENT>config[__script__][key] = value<EOL><DEDENT><DEDENT>return config<EOL>
Read and parse configuration file. By default, ``filename`` is relative
path to current work directory.

If no config file found, default ``CONFIG`` would be used.

:param filename: Read config from given filename.
:param args: Parsed command line arguments.