当前位置: 首页>>代码示例>>Python>>正文


Python configparser.RawConfigParser方法代码示例

本文整理汇总了Python中pip._vendor.six.moves.configparser.RawConfigParser方法的典型用法代码示例。如果您正苦于以下问题:Python configparser.RawConfigParser方法的具体用法?Python configparser.RawConfigParser怎么用?Python configparser.RawConfigParser使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pip._vendor.six.moves.configparser的用法示例。


在下文中一共展示了configparser.RawConfigParser方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _construct_parser

# 需要导入模块: from pip._vendor.six.moves import configparser [as 别名]
# 或者: from pip._vendor.six.moves.configparser import RawConfigParser [as 别名]
def _construct_parser(self, fname):
        # type: (str) -> RawConfigParser
        parser = configparser.RawConfigParser()
        # If there is no such file, don't bother reading it but create the
        # parser anyway, to hold the data.
        # Doing this is useful when modifying and saving files, where we don't
        # need to construct a parser.
        if os.path.exists(fname):
            try:
                parser.read(fname)
            except UnicodeDecodeError:
                raise ConfigurationError((
                    "ERROR: "
                    "Configuration file contains invalid %s characters.\n"
                    "Please fix your configuration, located at %s\n"
                ) % (locale.getpreferredencoding(False), fname))
        return parser 
开发者ID:HaoZhang95,项目名称:Python24,代码行数:19,代码来源:configuration.py

示例2: _construct_parser

# 需要导入模块: from pip._vendor.six.moves import configparser [as 别名]
# 或者: from pip._vendor.six.moves.configparser import RawConfigParser [as 别名]
def _construct_parser(self, fname):
        # type: (str) -> RawConfigParser
        parser = configparser.RawConfigParser()
        # If there is no such file, don't bother reading it but create the
        # parser anyway, to hold the data.
        # Doing this is useful when modifying and saving files, where we don't
        # need to construct a parser.
        if os.path.exists(fname):
            try:
                parser.read(fname)
            except UnicodeDecodeError:
                # See https://github.com/pypa/pip/issues/4963
                raise ConfigurationFileCouldNotBeLoaded(
                    reason="contains invalid {} characters".format(
                        locale.getpreferredencoding(False)
                    ),
                    fname=fname,
                )
            except configparser.Error as error:
                # See https://github.com/pypa/pip/issues/4893
                raise ConfigurationFileCouldNotBeLoaded(error=error)
        return parser 
开发者ID:PacktPublishing,项目名称:Mastering-Elasticsearch-7.0,代码行数:24,代码来源:configuration.py

示例3: get_entrypoints

# 需要导入模块: from pip._vendor.six.moves import configparser [as 别名]
# 或者: from pip._vendor.six.moves.configparser import RawConfigParser [as 别名]
def get_entrypoints(filename):
    if not os.path.exists(filename):
        return {}, {}

    # This is done because you can pass a string to entry_points wrappers which
    # means that they may or may not be valid INI files. The attempt here is to
    # strip leading and trailing whitespace in order to make them valid INI
    # files.
    with open(filename) as fp:
        data = StringIO()
        for line in fp:
            data.write(line.strip())
            data.write("\n")
        data.seek(0)

    cp = configparser.RawConfigParser()
    cp.optionxform = lambda option: option
    cp.readfp(data)

    console = {}
    gui = {}
    if cp.has_section('console_scripts'):
        console = dict(cp.items('console_scripts'))
    if cp.has_section('gui_scripts'):
        gui = dict(cp.items('gui_scripts'))
    return console, gui 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:28,代码来源:wheel.py

示例4: __init__

# 需要导入模块: from pip._vendor.six.moves import configparser [as 别名]
# 或者: from pip._vendor.six.moves.configparser import RawConfigParser [as 别名]
def __init__(self, *args, **kwargs):
        self.config = configparser.RawConfigParser()
        self.name = kwargs.pop('name')
        self.isolated = kwargs.pop("isolated", False)
        self.files = self.get_config_files()
        if self.files:
            self.config.read(self.files)
        assert self.name
        optparse.OptionParser.__init__(self, *args, **kwargs) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:11,代码来源:baseparser.py

示例5: __init__

# 需要导入模块: from pip._vendor.six.moves import configparser [as 别名]
# 或者: from pip._vendor.six.moves.configparser import RawConfigParser [as 别名]
def __init__(self, isolated, load_only=None):
        # type: (bool, Kind) -> None
        super(Configuration, self).__init__()

        _valid_load_only = [kinds.USER, kinds.GLOBAL, kinds.VENV, None]
        if load_only not in _valid_load_only:
            raise ConfigurationError(
                "Got invalid value for load_only - should be one of {}".format(
                    ", ".join(map(repr, _valid_load_only[:-1]))
                )
            )
        self.isolated = isolated  # type: bool
        self.load_only = load_only  # type: Optional[Kind]

        # The order here determines the override order.
        self._override_order = [
            kinds.GLOBAL, kinds.USER, kinds.VENV, kinds.ENV, kinds.ENV_VAR
        ]

        self._ignore_env_names = ["version", "help"]

        # Because we keep track of where we got the data from
        self._parsers = {
            variant: [] for variant in self._override_order
        }  # type: Dict[Kind, List[Tuple[str, RawConfigParser]]]
        self._config = {
            variant: {} for variant in self._override_order
        }  # type: Dict[Kind, Dict[str, Any]]
        self._modified_parsers = []  # type: List[Tuple[str, RawConfigParser]] 
开发者ID:HaoZhang95,项目名称:Python24,代码行数:31,代码来源:configuration.py

示例6: _load_file

# 需要导入模块: from pip._vendor.six.moves import configparser [as 别名]
# 或者: from pip._vendor.six.moves.configparser import RawConfigParser [as 别名]
def _load_file(self, variant, fname):
        # type: (Kind, str) -> RawConfigParser
        logger.debug("For variant '%s', will try loading '%s'", variant, fname)
        parser = self._construct_parser(fname)

        for section in parser.sections():
            items = parser.items(section)
            self._config[variant].update(self._normalized_keys(section, items))

        return parser 
开发者ID:HaoZhang95,项目名称:Python24,代码行数:12,代码来源:configuration.py

示例7: _get_parser_to_modify

# 需要导入模块: from pip._vendor.six.moves import configparser [as 别名]
# 或者: from pip._vendor.six.moves.configparser import RawConfigParser [as 别名]
def _get_parser_to_modify(self):
        # type: () -> Tuple[str, RawConfigParser]
        # Determine which parser to modify
        parsers = self._parsers[self.load_only]
        if not parsers:
            # This should not happen if everything works correctly.
            raise ConfigurationError(
                "Fatal Internal error [id=2]. Please report as a bug."
            )

        # Use the highest priority parser.
        return parsers[-1]

    # XXX: This is patched in the tests. 
开发者ID:HaoZhang95,项目名称:Python24,代码行数:16,代码来源:configuration.py

示例8: _mark_as_modified

# 需要导入模块: from pip._vendor.six.moves import configparser [as 别名]
# 或者: from pip._vendor.six.moves.configparser import RawConfigParser [as 别名]
def _mark_as_modified(self, fname, parser):
        # type: (str, RawConfigParser) -> None
        file_parser_tuple = (fname, parser)
        if file_parser_tuple not in self._modified_parsers:
            self._modified_parsers.append(file_parser_tuple) 
开发者ID:HaoZhang95,项目名称:Python24,代码行数:7,代码来源:configuration.py


注:本文中的pip._vendor.six.moves.configparser.RawConfigParser方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。