本文整理汇总了Python中configparser.ExtendedInterpolation方法的典型用法代码示例。如果您正苦于以下问题:Python configparser.ExtendedInterpolation方法的具体用法?Python configparser.ExtendedInterpolation怎么用?Python configparser.ExtendedInterpolation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类configparser
的用法示例。
在下文中一共展示了configparser.ExtendedInterpolation方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: copy_dependencies
# 需要导入模块: import configparser [as 别名]
# 或者: from configparser import ExtendedInterpolation [as 别名]
def copy_dependencies(f):
config_path = '/etc/yangcatalog/yangcatalog.conf'
config = ConfigParser.ConfigParser()
config._interpolation = ConfigParser.ExtendedInterpolation()
config.read(config_path)
yang_models = config.get('Directory-Section', 'save-file-dir')
tmp = config.get('Directory-Section', 'temp')
out = f.getvalue()
letters = string.ascii_letters
suffix = ''.join(random.choice(letters) for i in range(8))
dep_dir = '{}/yangvalidator-dependencies-{}'.format(tmp, suffix)
os.mkdir(dep_dir)
dependencies = out.split(':')[1].strip().split(' ')
for dep in dependencies:
for file in glob.glob(r'{}/{}*.yang'.format(yang_models, dep)):
shutil.copy(file, dep_dir)
return dep_dir
示例2: configs_from_inifile
# 需要导入模块: import configparser [as 别名]
# 或者: from configparser import ExtendedInterpolation [as 别名]
def configs_from_inifile(inifile):
try:
from configparser import ConfigParser, ExtendedInterpolation
except ImportError:
import errno
raise IOError(
errno.ENOENT,
'Missing ConfigParser and ExtendedInterpolation: '
'please use python3+')
else:
parser = ConfigParser(
allow_no_value=False, # don't allow "key" without "="
delimiters=('=',), # inifile "=" between key and value
comment_prefixes=(';',), # only ';' for comments (fixes #channel)
inline_comment_prefixes=(';',), # comments after lines
interpolation=ExtendedInterpolation(),
empty_lines_in_values=False) # empty line means new key
parser.read_file(inifile)
return BridgeConfigsFromIni(parser).get()
示例3: load
# 需要导入模块: import configparser [as 别名]
# 或者: from configparser import ExtendedInterpolation [as 别名]
def load(path: str, fallback: ConfigParser = None) -> ConfigParser:
"""
Retrieve the PyRDP settings from a file
:param path: The path of the file to load.
:param fallback: The fallback configuration path.
:returns: A ConfigParser instance with the loaded settings.
:throws Exception: When the fallback configuration is missing and no configuration is found.
"""
config = ConfigParser(interpolation=ExtendedInterpolation())
config.optionxform = str
try:
if len(config.read(path)) > 0:
return config
except Exception:
# Fallback to default settings.
pass
if not fallback:
raise Exception('Invalid configuration with no fallback specified')
return fallback
示例4: get_config
# 需要导入模块: import configparser [as 别名]
# 或者: from configparser import ExtendedInterpolation [as 别名]
def get_config(config_filename):
friar_config = configparser.ConfigParser(
interpolation=configparser.ExtendedInterpolation(),
allow_no_value=True,
delimiters='=',
inline_comment_prefixes='#'
)
local_filename = config_filename.replace('.cfg', '_local.cfg')
if path.isfile(local_filename):
config_filename = local_filename
with open(config_filename, 'r') as file:
friar_config.read_file(file)
return friar_config
示例5: read_ini_file
# 需要导入模块: import configparser [as 别名]
# 或者: from configparser import ExtendedInterpolation [as 别名]
def read_ini_file(cpFile):
"""Read a .ini file and return it as a ConfigParser class.
This function does none of the parsing/combining of sections. It simply
reads the file and returns it unedited
Parameters
----------
cpFile : The path to a .ini file to be read in
Returns
-------
cp: The ConfigParser class containing the read in .ini file
"""
# Initialise ConfigParser class
cp = ConfigParser.ConfigParser(\
interpolation=ConfigParser.ExtendedInterpolation())
# Read the file
fp = open(cpFile,'r')
cp.read_file(fp)
fp.close()
return cp
示例6: __init__
# 需要导入模块: import configparser [as 别名]
# 或者: from configparser import ExtendedInterpolation [as 别名]
def __init__(self, extended_interpolation=True):
if extended_interpolation:
cp = ConfigParser(interpolation=ExtendedInterpolation())
else:
cp = ConfigParser()
cp.optionxform = _name_xform
self._cp = cp
示例7: __init__
# 需要导入模块: import configparser [as 别名]
# 或者: from configparser import ExtendedInterpolation [as 别名]
def __init__(self, paths_config, verbose=False):
config = configparser.ConfigParser()
config._interpolation = configparser.ExtendedInterpolation()
config.read(paths_config)
print(paths_config)
c = config['DEFAULT']
d = {}
for k in c:
d[k] = c[k]
self.resources_dir = d['resources_dir']
self.vocab_dir = d['vocab_dir']
# Word2Vec Vocab to Idxs
self.word_vocab_pkl = d['word_vocab_pkl']
# Wid2Idx for Known Entities ~ 620K (readers.train.vocab.py)
self.kwnwid_vocab_pkl = d['kwnwid_vocab_pkl']
# FIGER Type label 2 idx (readers.train.vocab.py)
self.label_vocab_pkl = d['label_vocab_pkl']
# EntityWid: [FIGER Type Labels]
# CoherenceStr2Idx at various thresholds (readers.train.vocab.py)
self.cohstringG9_vocab_pkl = d['cohstringg9_vocab_pkl']
# wid2Wikititle for whole KB ~ 3.18M (readers.train.vocab.py)
self.widWiktitle_pkl = d['widwiktitle_pkl']
self.crosswikis_pruned_pkl = d['crosswikis_pruned_pkl']
self.glove_pkl = d['glove_pkl']
self.glove_word_vocab_pkl = d['glove_word_vocab_pkl']
self.test_file = d['test_file']
if verbose:
pp.pprint(d)
#endinit
示例8: __init__
# 需要导入模块: import configparser [as 别名]
# 或者: from configparser import ExtendedInterpolation [as 别名]
def __init__(self, defaults_file=os.path.join('config', 'defaults.cfg'), config_file='', **kwargs):
""""""
#super(Config, self).__init__(defaults=kwargs.pop('DEFAULT', {}))
super(Config, self).__init__(interpolation=ExtendedInterpolation())
self.read([defaults_file, config_file])
for section, options in six.iteritems(kwargs):
if section != 'DEFAULT' and not self.has_section(section):
self.add_section(section)
for option, value in six.iteritems(options):
self.set(section, option, str(value))
return
#=============================================================
示例9: test_get_extended_interpolation
# 需要导入模块: import configparser [as 别名]
# 或者: from configparser import ExtendedInterpolation [as 别名]
def test_get_extended_interpolation(self):
parser = configparser.ConfigParser(
interpolation=configparser.ExtendedInterpolation())
parser.read_string("""
[Paths]
home_dir: /Users
my_dir: ${home_dir1}/lumberjack
my_pictures: ${my_dir}/Pictures
""")
cm = self.assertRaises(configparser.InterpolationMissingOptionError)
with cm:
parser.get('Paths', 'my_dir')
self.assertIs(cm.exception.__suppress_context__, True)
示例10: _get_prefs
# 需要导入模块: import configparser [as 别名]
# 或者: from configparser import ExtendedInterpolation [as 别名]
def _get_prefs(self):
"""
"""
prefs = ConfigParser(interpolation=ExtendedInterpolation())
prefs.read_string("""
[default]
ads_token = dev_key
[proxy]
ssh_user = None
ssh_server = None
ssh_port = 22
[options]
download_pdf = True
alert_sound = True
debug = False
""")
prefs_dir = os.path.dirname(self.prefs_path)
if not os.path.exists(prefs_dir):
os.makedirs(prefs_dir)
if not os.path.exists(self.prefs_path):
with open(self.prefs_path, 'w') as prefs_file:
prefs.write(prefs_file)
else:
prefs.read(self.prefs_path)
return prefs
示例11: clean
# 需要导入模块: import configparser [as 别名]
# 或者: from configparser import ExtendedInterpolation [as 别名]
def clean(self):
print('Ahenk cleaning..')
import configparser
try:
config = configparser.ConfigParser()
config._interpolation = configparser.ExtendedInterpolation()
config.read(System.Ahenk.config_path())
db_path = config.get('BASE', 'dbPath')
if Util.is_exist(System.Ahenk.fifo_file()):
Util.delete_file(System.Ahenk.fifo_file())
if Util.is_exist(db_path):
Util.delete_file(db_path)
if Util.is_exist(System.Ahenk.pid_path()):
Util.delete_file(System.Ahenk.pid_path())
config.set('CONNECTION', 'uid', '')
config.set('CONNECTION', 'password', '')
config.set('CONNECTION', 'host', '')
config.set('MACHINE', 'user_disabled', 'false')
with open(System.Ahenk.config_path(), 'w') as file:
config.write(file)
file.close()
print('Ahenk cleaned.')
except Exception as e:
self.logger.error("Error while running clean command. Error Message " + str(e))
print('Error while running clean command. Error Message {0}'.format(str(e)))
示例12: clean
# 需要导入模块: import configparser [as 别名]
# 或者: from configparser import ExtendedInterpolation [as 别名]
def clean(self):
print('Ahenk cleaning..')
try:
config = configparser.ConfigParser()
config._interpolation = configparser.ExtendedInterpolation()
config.read(System.Ahenk.config_path())
db_path = config.get('BASE', 'dbPath')
if Util.is_exist(System.Ahenk.fifo_file()):
Util.delete_file(System.Ahenk.fifo_file())
if Util.is_exist(db_path):
Util.delete_file(db_path)
if Util.is_exist(System.Ahenk.pid_path()):
Util.delete_file(System.Ahenk.pid_path())
config.set('CONNECTION', 'uid', '')
config.set('CONNECTION', 'password', '')
with open(System.Ahenk.config_path(), 'w') as file:
config.write(file)
file.close()
print('Ahenk cleaned.')
except Exception as e:
print('Error while running clean command. Error Message {0}'.format(str(e)))
示例13: db_path
# 需要导入模块: import configparser [as 别名]
# 或者: from configparser import ExtendedInterpolation [as 别名]
def db_path():
config = configparser.ConfigParser()
config._interpolation = configparser.ExtendedInterpolation()
config.read(System.Ahenk.config_path())
return config.get('BASE', 'dbPath')
示例14: agreement_timeout
# 需要导入模块: import configparser [as 别名]
# 或者: from configparser import ExtendedInterpolation [as 别名]
def agreement_timeout():
config = configparser.ConfigParser()
config._interpolation = configparser.ExtendedInterpolation()
config.read(System.Ahenk.config_path())
return config.get('SESSION', 'agreement_timeout')
示例15: registration_timeout
# 需要导入模块: import configparser [as 别名]
# 或者: from configparser import ExtendedInterpolation [as 别名]
def registration_timeout():
config = configparser.ConfigParser()
config._interpolation = configparser.ExtendedInterpolation()
config.read(System.Ahenk.config_path())
return config.get('SESSION', 'registration_timeout')