本文整理汇总了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)
示例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
示例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
示例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)
示例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()
示例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()
示例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()
示例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()
示例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)