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


Python SafeConfigParser.__init__方法代码示例

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


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

示例1: __init__

# 需要导入模块: from ConfigParser import SafeConfigParser [as 别名]
# 或者: from ConfigParser.SafeConfigParser import __init__ [as 别名]
def __init__(self, fName=None, defaults={},create_file = True):
        SafeConfigParser.__init__(self, defaults)
        self.dummySection = "dummy"
        if fName:
            # create file if not existing

            if create_file and not os.path.exists(fName):
                try:
                    logger.debug("trying to create %s" % fName)
                    with open(fName, "w") as f:
                        pass
                except Exception as e:
                    logger.debug("failed to create %s" % fName)
                    logger.debug(e)

            self.read(fName) 
开发者ID:maweigert,项目名称:gputools,代码行数:18,代码来源:myconfigparser.py

示例2: __init__

# 需要导入模块: from ConfigParser import SafeConfigParser [as 别名]
# 或者: from ConfigParser.SafeConfigParser import __init__ [as 别名]
def __init__(self, config_files):

    Parser.__init__(self)

    # Write options in the case it was read.
    # self.optionxform = str

    # Parse to real path
    self.config_files = []
    for config_file in config_files:
      self.config_files.append(os.path.realpath(config_file))
      self.config_location = os.path.dirname(os.path.realpath(config_file))

    # Parse all config files in list
    for config_file in self.config_files:
      if os.path.isfile(config_file):
        logging.info("Using config file " + config_file)
        if PY2:
          self.readfp(open(config_file))
        else:
          self.read_file(open(config_file))
      else:
        logging.warning("Missing config file " + config_file)
        # Might also add command line options for overriding stuff 
开发者ID:intelligent-agent,项目名称:redeem,代码行数:26,代码来源:CascadingConfigParser.py

示例3: __init__

# 需要导入模块: from ConfigParser import SafeConfigParser [as 别名]
# 或者: from ConfigParser.SafeConfigParser import __init__ [as 别名]
def __init__(self):
        SafeConfigParser.__init__(self)
        self.eval_globals = None
        self.eval_locals = None 
开发者ID:hjimce,项目名称:Depth-Map-Prediction,代码行数:6,代码来源:configuration.py

示例4: __init__

# 需要导入模块: from ConfigParser import SafeConfigParser [as 别名]
# 或者: from ConfigParser.SafeConfigParser import __init__ [as 别名]
def __init__(self, config_file):
        if sys.version[0] == "2":
            CP.__init__(self)
        else:
            super().__init__()
        if not os.path.exists(config_file):
            raise Exception("Could not find " + config_file)
        f = open(config_file)
        id_string = f.readline().split("=")

        if id_string[0].strip().upper() in ["CAPI", "SAPI"]:
            self.type = id_string[0]
        else:
            raise SyntaxError("Could not find API type in " + config_file)
        try:
            self.version = int(id_string[1].strip())
        except ValueError:
            raise SyntaxError("Unknown version '{}'".format(id_string[1].strip()))

        except IndexError:
            raise SyntaxError("Could not find API version in " + config_file)
        if sys.version[0] == "2":
            exceptions = (configparser.ParsingError, configparser.DuplicateSectionError)
        else:
            exceptions = (
                configparser.ParsingError,
                configparser.DuplicateSectionError,
                configparser.DuplicateOptionError,
            )
        try:
            if sys.version[0] == "2":
                self.readfp(f)
            else:
                self.read_file(f)
        except configparser.MissingSectionHeaderError:
            raise SyntaxError("Missing section header")
        except exceptions as e:
            raise SyntaxError(e.message) 
开发者ID:olofk,项目名称:fusesoc,代码行数:40,代码来源:fusesocconfigparser.py

示例5: __init__

# 需要导入模块: from ConfigParser import SafeConfigParser [as 别名]
# 或者: from ConfigParser.SafeConfigParser import __init__ [as 别名]
def __init__(self, files=None, keep_dashes=True):  # pylint: disable=W0231
        """Initialize

        If defaults is True, default option files are read first

        Raises ValueError if defaults is set to True but defaults files
        cannot be found.
        """

        # Regular expression to allow options with no value(For Python v2.6)
        self.OPTCRE = re.compile(  # pylint: disable=C0103
            r'(?P<option>[^:=\s][^:=]*)'
            r'\s*(?:'
            r'(?P<vi>[:=])\s*'
            r'(?P<value>.*))?$'
        )

        self._options_dict = {}

        if PY2:
            SafeConfigParser.__init__(self)
        else:
            SafeConfigParser.__init__(self, strict=False)

        self.default_extension = DEFAULT_EXTENSIONS[os.name]
        self.keep_dashes = keep_dashes

        if not files:
            raise ValueError('files argument should be given')
        if isinstance(files, str):
            self.files = [files]
        else:
            self.files = files

        self._parse_options(list(self.files))
        self._sections = self.get_groups_as_dict() 
开发者ID:LuciferJack,项目名称:python-mysql-pool,代码行数:38,代码来源:optionfiles.py

示例6: __init__

# 需要导入模块: from ConfigParser import SafeConfigParser [as 别名]
# 或者: from ConfigParser.SafeConfigParser import __init__ [as 别名]
def __init__(self, files=None, keep_dashes=True):  # pylint: disable=W0231
        """Initialize

        If defaults is True, default option files are read first

        Raises ValueError if defaults is set to True but defaults files
        cannot be found.
        """

        # Regular expression to allow options with no value(For Python v2.6)
        self.OPTCRE = re.compile(           # pylint: disable=C0103
            r'(?P<option>[^:=\s][^:=]*)'
            r'\s*(?:'
            r'(?P<vi>[:=])\s*'
            r'(?P<value>.*))?$'
        )

        self._options_dict = {}

        if PY2:
            SafeConfigParser.__init__(self)
        else:
            SafeConfigParser.__init__(self, strict=False)

        self.default_extension = DEFAULT_EXTENSIONS[os.name]
        self.keep_dashes = keep_dashes

        if not files:
            raise ValueError('files argument should be given')
        if isinstance(files, str):
            self.files = [files]
        else:
            self.files = files

        self._parse_options(list(self.files))
        self._sections = self.get_groups_as_dict() 
开发者ID:CastagnaIT,项目名称:plugin.video.netflix,代码行数:38,代码来源:optionfiles.py

示例7: __init__

# 需要导入模块: from ConfigParser import SafeConfigParser [as 别名]
# 或者: from ConfigParser.SafeConfigParser import __init__ [as 别名]
def __init__(self, filename):
        self.filename = filename
        SafeConfigParser.__init__(self)
        self.load()
        self.init_defaults(self._DEFAULTS)
        # upgrade from deprecated "currency" to "quote_currency"
        # todo: remove this piece of code again in a few months
        if self.has_option("api", "currency"):
            self.set("api", "quote_currency", self.get_string("api", "currency"))
            self.remove_option("api", "currency")
            self.save() 
开发者ID:caktux,项目名称:pytrader,代码行数:13,代码来源:api.py

示例8: __init__

# 需要导入模块: from ConfigParser import SafeConfigParser [as 别名]
# 或者: from ConfigParser.SafeConfigParser import __init__ [as 别名]
def __init__(self, files=None, keep_dashes=True):
        """Initialize

        files[in]       The files to parse searching for configuration items.
        keep_dashes[in] If False, dashes in options are replaced with
                        underscores.

        Raises ValueError if defaults is set to True but defaults files
        cannot be found.
        """

        # Regular expression to allow options with no value(For Python v2.6)
        self.OPTCRE = re.compile(           # pylint: disable=C0103
            r'(?P<option>[^:=\s][^:=]*)'
            r'\s*(?:'
            r'(?P<vi>[:=])\s*'
            r'(?P<value>.*))?$'
        )

        self._options_dict = {}

        SafeConfigParser.__init__(self)
        self.default_extension = DEFAULT_EXTENSIONS[os.name]
        self.keep_dashes = keep_dashes

        if not files:
            raise ValueError('files argument should be given')
        if isinstance(files, str):
            self.files = [files]
        else:
            self.files = files

        self._parse_options(list(self.files))
        self._sections = self.get_groups_as_dict() 
开发者ID:mysql,项目名称:mysql-utilities,代码行数:36,代码来源:options_parser.py

示例9: __init__

# 需要导入模块: from ConfigParser import SafeConfigParser [as 别名]
# 或者: from ConfigParser.SafeConfigParser import __init__ [as 别名]
def __init__(self, fName=None, defaults={}, create_file = True):
        SafeConfigParser.__init__(self, defaults)
        self.dummySection = "dummy"

        if fName:
            if create_file and not os.path.exists(fName):
                try:
                    logger.debug("trying to create %s"%fName)
                    with open(fName,"w") as f:
                        pass
                except Exception as e:
                    logger.debug("failed to create %s"%fName)
                    logger.debug(e)
            self.read(fName) 
开发者ID:maweigert,项目名称:spimagine,代码行数:16,代码来源:myconfigparser.py


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