本文整理汇总了Python中six.moves.configparser.RawConfigParser类的典型用法代码示例。如果您正苦于以下问题:Python RawConfigParser类的具体用法?Python RawConfigParser怎么用?Python RawConfigParser使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了RawConfigParser类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, **kw):
cfg_path = kw.pop('cfg', None) \
or os.path.join(APP_DIRS.user_config_dir, 'config.ini')
cfg_path = os.path.abspath(cfg_path)
RawConfigParser.__init__(self)
if os.path.exists(cfg_path):
assert os.path.isfile(cfg_path)
self.read(cfg_path)
else:
self.add_section('service')
for opt in 'url user password'.split():
self.set('service', opt, kw.get(opt, '') or '')
self.add_section('logging')
self.set('logging', 'level', 'INFO')
config_dir = os.path.dirname(cfg_path)
if not os.path.exists(config_dir):
try:
os.makedirs(config_dir)
except OSError: # pragma: no cover
# this happens when run on travis-ci, by a system user.
pass
if os.path.exists(config_dir):
with open(cfg_path, 'w') as fp:
self.write(fp)
level = self.get('logging', 'level', default=None)
if level:
logging.basicConfig(level=getattr(logging, level))
示例2: CredentialStore
class CredentialStore(object):
def __init__(self, **kwargs):
self.credential_search_path = [
os.path.join(os.path.sep, "etc", "cbdefense", "credentials"),
os.path.join(os.path.expanduser("~"), ".cbdefense", "credentials"),
os.path.join(".", ".cbdefense", "credentials"),
]
if "credential_file" in kwargs:
if isinstance(kwargs["credential_file"], six.string_types):
self.credential_search_path = [kwargs["credential_file"]]
elif type(kwargs["credential_file"]) is list:
self.credential_search_path = kwargs["credential_file"]
self.credentials = RawConfigParser(defaults=default_profile)
self.credential_files = self.credentials.read(self.credential_search_path)
def get_credentials(self, profile=None):
credential_profile = profile or "default"
if credential_profile not in self.get_profiles():
raise CredentialError("Cannot find credential profile '%s' after searching in these files: %s." %
(credential_profile, ", ".join(self.credential_search_path)))
retval = {}
for k, v in six.iteritems(default_profile):
retval[k] = self.credentials.get(credential_profile, k)
if not retval["api_key"] or not retval["conn_id"] or not retval["cbd_api_url"]:
raise CredentialError("API Key and Connector ID not available for profile %s" % credential_profile)
return Credentials(retval)
def get_profiles(self):
return self.credentials.sections()
示例3: set
def set(self, section, option, new_value):
with self.lock:
if self.callback and self.has_section(section) and self.has_option(section, option):
old_value = self.get(section, option)
if not self.callback(section, option, new_value, old_value):
raise OperationNotPossibleAtRuntimeException
RawConfigParser.set(self, section, option, new_value)
示例4: _fetchAzureAccountKey
def _fetchAzureAccountKey(accountName):
"""
Find the account key for a given Azure storage account.
The account key is taken from the AZURE_ACCOUNT_KEY_<account> environment variable if it
exists, then from plain AZURE_ACCOUNT_KEY, and then from looking in the file
~/.toilAzureCredentials. That file has format:
[AzureStorageCredentials]
accountName1=ACCOUNTKEY1==
accountName2=ACCOUNTKEY2==
"""
try:
return os.environ['AZURE_ACCOUNT_KEY_' + accountName]
except KeyError:
try:
return os.environ['AZURE_ACCOUNT_KEY']
except KeyError:
configParser = RawConfigParser()
configParser.read(os.path.expanduser(credential_file_path))
try:
return configParser.get('AzureStorageCredentials', accountName)
except NoOptionError:
raise RuntimeError("No account key found for '%s', please provide it in '%s'" %
(accountName, credential_file_path))
示例5: __init__
def __init__(self, name, default=None, **kw):
"""Initialization.
:param name: Basename for the config file (suffix .ini will be appended).
:param default: Default content of the config file.
"""
self.name = name
self.default = default
config_dir = Path(kw.pop('config_dir', None) or DIR)
RawConfigParser.__init__(self, kw, allow_no_value=True)
if self.default:
if PY3:
fp = io.StringIO(self.default)
else:
fp = io.BytesIO(self.default.encode('utf8'))
self.readfp(fp)
cfg_path = config_dir.joinpath(name + '.ini')
if cfg_path.exists():
assert cfg_path.is_file()
self.read(cfg_path.as_posix())
else:
if not config_dir.exists():
try:
config_dir.mkdir()
except OSError: # pragma: no cover
# this happens when run on travis-ci, by a system user.
pass
if config_dir.exists():
with open(cfg_path.as_posix(), 'w') as fp:
self.write(fp)
self.path = cfg_path
示例6: __init__
def __init__(self, name, default=None, **kw):
"""Initialization.
:param name: Basename for the config file (suffix .ini will be appended).
:param default: Default content of the config file.
"""
self.name = name
self.default = default
config_dir = kw.pop("config_dir", None) or text_type(DIR)
RawConfigParser.__init__(self, kw, allow_no_value=True)
if self.default:
if PY3:
fp = io.StringIO(self.default)
else:
fp = io.BytesIO(self.default.encode("utf8"))
self.readfp(fp)
cfg_path = os.path.join(config_dir, name + ".ini")
if os.path.exists(cfg_path):
assert os.path.isfile(cfg_path)
self.read(cfg_path)
else:
if not os.path.exists(config_dir):
try:
os.mkdir(config_dir)
except OSError: # pragma: no cover
# this happens when run on travis-ci, by a system user.
pass
if os.path.exists(config_dir):
with open(cfg_path, "w") as fp:
self.write(fp)
self.path = Path(cfg_path)
示例7: test_read_test_tribler_conf
def test_read_test_tribler_conf(self):
"""
Test upgrading a Tribler configuration from 7.0 to 7.1
"""
old_config = RawConfigParser()
old_config.read(os.path.join(self.CONFIG_PATH, "tribler70.conf"))
new_config = TriblerConfig()
result_config = add_tribler_config(new_config, old_config)
self.assertEqual(result_config.get_default_safeseeding_enabled(), True)
示例8: get_config
def get_config(self, path):
"""
Reads entry from configuration.
"""
section, option = path.split('.', 1)
filename = os.path.join(self.path, '.hg', 'hgrc')
config = RawConfigParser()
config.read(filename)
if config.has_option(section, option):
return config.get(section, option).decode('utf-8')
return None
示例9: test_read_test_libtribler_conf
def test_read_test_libtribler_conf(self):
"""
Test upgrading a libtribler configuration from 7.0 to 7.1
"""
os.environ['TSTATEDIR'] = self.session_base_dir
old_config = RawConfigParser()
old_config.read(os.path.join(self.CONFIG_PATH, "libtribler70.conf"))
new_config = TriblerConfig()
result_config = add_libtribler_config(new_config, old_config)
self.assertEqual(result_config.get_tunnel_community_socks5_listen_ports(), [1, 2, 3, 4, 5, 6])
self.assertEqual(result_config.get_anon_proxy_settings(), (2, ("127.0.0.1", [5, 4, 3, 2, 1]), ''))
self.assertEqual(result_config.get_credit_mining_sources(), ['source1', 'source2'])
self.assertEqual(result_config.get_log_dir(), '/a/b/c')
示例10: test_read_test_corr_tribler_conf
def test_read_test_corr_tribler_conf(self):
"""
Adding corrupt values should result in the default value.
Note that this test might fail if there is already an upgraded config stored in the default
state directory. The code being tested here however shouldn't be ran if that config already exists.
:return:
"""
old_config = RawConfigParser()
old_config.read(os.path.join(self.CONFIG_PATH, "triblercorrupt70.conf"))
new_config = TriblerConfig()
result_config = add_tribler_config(new_config, old_config)
self.assertEqual(result_config.get_default_anonymity_enabled(), True)
示例11: get_config
def get_config(self, path):
"""
Reads entry from configuration.
"""
result = None
section, option = path.split(".", 1)
filename = os.path.join(self.path, ".hg", "hgrc")
config = RawConfigParser()
config.read(filename)
if config.has_option(section, option):
result = config.get(section, option)
if six.PY2:
result = result.decode("utf-8")
return result
示例12: test_upgrade_pstate_files
def test_upgrade_pstate_files(self):
"""
Test whether the existing pstate files are correctly updated to 7.1.
"""
os.makedirs(os.path.join(self.state_dir, STATEDIR_DLPSTATE_DIR))
# Copy an old pstate file
src_path = os.path.join(self.CONFIG_PATH, "download_pstate_70.state")
shutil.copyfile(src_path, os.path.join(self.state_dir, STATEDIR_DLPSTATE_DIR, "download.state"))
# Copy a corrupt pstate file
src_path = os.path.join(self.CONFIG_PATH, "download_pstate_70_corrupt.state")
corrupt_dest_path = os.path.join(self.state_dir, STATEDIR_DLPSTATE_DIR, "downloadcorrupt.state")
shutil.copyfile(src_path, corrupt_dest_path)
old_config = RawConfigParser()
old_config.read(os.path.join(self.CONFIG_PATH, "tribler70.conf"))
convert_config_to_tribler71(old_config, state_dir=self.state_dir)
# Verify whether the section is correctly renamed
download_config = RawConfigParser()
download_config.read(os.path.join(self.state_dir, STATEDIR_DLPSTATE_DIR, "download.state"))
self.assertTrue(download_config.has_section("download_defaults"))
self.assertFalse(download_config.has_section("downloadconfig"))
self.assertFalse(os.path.exists(corrupt_dest_path))
# Do the upgrade again, it should not fail
convert_config_to_tribler71(old_config, state_dir=self.state_dir)
示例13: _test_write_pkispawn_config_file
def _test_write_pkispawn_config_file(self, template, expected):
"""
Test that the values we read from an ExternalCAProfile
object can be used to produce a reasonable-looking pkispawn
configuration.
"""
config = RawConfigParser()
config.optionxform = str
config.add_section("CA")
config.set("CA", "pki_req_ext_oid", template.ext_oid)
config.set("CA", "pki_req_ext_data",
hexlify(template.get_ext_data()).decode('ascii'))
out = StringIO()
config.write(out)
assert out.getvalue() == expected
示例14: __init__
def __init__(self, path=expanduser("~/.azkabanrc")):
self.parser = RawConfigParser()
self.path = path
if exists(path):
try:
self.parser.read(self.path)
except ParsingError:
raise AzkabanError("Invalid configuration file %r.", path)
示例15: __init__
def __init__(self):
self._config = RawConfigParser()
self._config.optionxform = str
self._settings = {}
self._sections = {}
self._finalized = False
self.loaded_files = set()