本文整理汇总了Python中ConfigParser.ConfigParser.defaults方法的典型用法代码示例。如果您正苦于以下问题:Python ConfigParser.defaults方法的具体用法?Python ConfigParser.defaults怎么用?Python ConfigParser.defaults使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ConfigParser.ConfigParser
的用法示例。
在下文中一共展示了ConfigParser.defaults方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_export_site_with_subfolders
# 需要导入模块: from ConfigParser import ConfigParser [as 别名]
# 或者: from ConfigParser.ConfigParser import defaults [as 别名]
def test_export_site_with_subfolders(self):
from Products.GenericSetup.utils import _getDottedName
self._setUpAdapters()
FOLDER_IDS = ('foo', 'bar', 'baz')
site = _makeFolder('site')
site.title = 'AAA'
site._setProperty('description', 'BBB')
aside = _makeFolder('aside')
dotted = _getDottedName(aside.__class__)
for id in FOLDER_IDS:
folder = _makeFolder(id)
folder.title = 'Title: %s' % id
site._setObject(id, folder)
context = DummyExportContext(site)
exporter = self._getExporter()
exporter(context)
self.assertEqual(len(context._wrote), 2 + (2 *len(FOLDER_IDS)))
filename, text, content_type = context._wrote[0]
self.assertEqual(filename, 'structure/.objects')
self.assertEqual(content_type, 'text/comma-separated-values')
objects = [x for x in reader(StringIO(text))]
self.assertEqual(len(objects), 3)
for index in range(len(FOLDER_IDS)):
id = FOLDER_IDS[index]
self.assertEqual(objects[index][0], id)
self.assertEqual(objects[index][1], dotted)
filename, text, content_type = context._wrote[2 + (2 * index)]
self.assertEqual(filename, '/'.join(('structure', id, '.objects')))
self.assertEqual(content_type, 'text/comma-separated-values')
subobjects = [x for x in reader(StringIO(text))]
self.assertEqual(len(subobjects), 0)
filename, text, content_type = context._wrote[2 + (2 * index) + 1]
self.assertEqual(filename,
'/'.join(('structure', id, '.properties')))
self.assertEqual(content_type, 'text/plain')
parser = ConfigParser()
parser.readfp(StringIO(text))
defaults = parser.defaults()
self.assertEqual(len(defaults), 1)
self.assertEqual(defaults['title'], 'Title: %s' % id)
filename, text, content_type = context._wrote[1]
self.assertEqual(filename, 'structure/.properties')
self.assertEqual(content_type, 'text/plain')
parser = ConfigParser()
parser.readfp(StringIO(text))
defaults = parser.defaults()
self.assertEqual(len(defaults), 2)
self.assertEqual(defaults['title'], 'AAA')
self.assertEqual(defaults['description'], 'BBB')
示例2: __init__
# 需要导入模块: from ConfigParser import ConfigParser [as 别名]
# 或者: from ConfigParser.ConfigParser import defaults [as 别名]
def __init__(self):
if not os.path.exists("BAG.conf"):
print "*** FOUT *** Kan configuratiebestand 'BAG.conf' niet openen."
print ""
raw_input("Druk <enter> om af te sluiten")
sys.exit()
configdict = ConfigParser()
configdict.read("BAG.conf")
try:
self.database = configdict.defaults()["database"]
self.host = configdict.defaults()["host"]
self.user = configdict.defaults()["user"]
self.password = configdict.defaults()["password"]
self.download = configdict.defaults()["download"]
self.extract = configdict.defaults()["extract"]
self.logging = configdict.defaults()["logging"]
except:
print "*** FOUT *** Inhoud van configuratiebestand 'BAG.conf' is niet volledig."
print ""
raw_input("Druk <enter> om af te sluiten")
sys.exit()
try:
self.bestand = configdict.defaults()["bestand"]
except:
pass
示例3: __init__
# 需要导入模块: from ConfigParser import ConfigParser [as 别名]
# 或者: from ConfigParser.ConfigParser import defaults [as 别名]
def __init__(self):
if not os.path.exists('BAG.conf'):
print "*** FOUT *** Kan configuratiebestand 'BAG.conf' niet openen."
print ""
#raw_input("Druk <enter> om af te sluiten")
sys.exit()
configdict = ConfigParser()
configdict.read('BAG.conf')
try:
self.database = configdict.defaults()['database']
self.host = configdict.defaults()['host']
self.user = configdict.defaults()['user']
self.password = configdict.defaults()['password']
self.download = configdict.defaults()['download']
self.extract = configdict.defaults()['extract']
self.logging = configdict.defaults()['logging']
# TODO controleer of er commandline parameters zijn meegegeven die de instellingen overrulen
except:
print "*** FOUT *** Inhoud van configuratiebestand 'BAG.conf' is niet volledig."
print ""
raw_input("Druk <enter> om af te sluiten")
sys.exit()
try:
self.bestand = configdict.defaults()['bestand']
except:
pass
示例4: __init__
# 需要导入模块: from ConfigParser import ConfigParser [as 别名]
# 或者: from ConfigParser.ConfigParser import defaults [as 别名]
def __init__(self, args):
# Derive home dir from script location
self.bagextract_home = os.path.realpath(os.path.dirname(sys.argv[0]) + '/..')
# Default config file
config_file = os.path.realpath(self.bagextract_home + '/extract.conf')
# Option: overrule config file with command line arg pointing to config file
if args.config:
config_file = args.config
Log.log.info("Configuratiebestand is " + str(config_file))
if not os.path.exists(config_file):
Log.log.fatal("ik kan het configuratiebestand '" + str(config_file) + "' ech niet vinden.")
configdict = ConfigParser()
try:
configdict.read(config_file)
except:
Log.log.fatal("ik kan " + str(config_file) + " wel vinden maar niet inlezen.")
try:
# Zet parameters uit config bestand
self.database = configdict.defaults()['database']
self.schema = configdict.defaults()['schema']
self.host = configdict.defaults()['host']
self.user = configdict.defaults()['user']
self.password = configdict.defaults()['password']
self.port = configdict.defaults()['port']
except:
Log.log.fatal(" de inhoud van configuratiebestand " + str(config_file) + " is niet volledig.")
try:
# Optioneel: overrulen met (commandline) args
if args.database:
self.database = args.database
if args.host:
self.host = args.host
if args.schema:
self.schema = args.schema
# default to public schema
if not self.schema:
self.schema = 'public'
if args.username:
self.user = args.username
if args.port:
self.port = args.port
if args.no_password:
# Gebruik geen wachtwoord voor de database verbinding
self.password = None
else:
if args.password:
self.password = args.password
# Assign Singleton (of heeft Python daar namespaces voor?) (Java achtergrond)
BAGConfig.config = self
except:
Log.log.fatal(" het overrulen van configuratiebestand " + str(config_file) + " via commandline loopt spaak")
示例5: load_app
# 需要导入模块: from ConfigParser import ConfigParser [as 别名]
# 或者: from ConfigParser.ConfigParser import defaults [as 别名]
def load_app(filename):
filename = os.path.abspath(filename)
parser = ConfigParser()
parser.read([filename])
parser.filename = filename
parser.defaults()['here'] = os.path.dirname(filename)
parser.defaults()['__file__'] = filename
return load_app_from_parser(parser)
示例6: raw_configurator
# 需要导入模块: from ConfigParser import ConfigParser [as 别名]
# 或者: from ConfigParser.ConfigParser import defaults [as 别名]
def raw_configurator(ini_file, local_conf_key='app:mailcone', here=__file__, zope_conf=''):
configparser = ConfigParser()
configparser.read(ini_file)
configparser.defaults().update(dict(here=here))
configurator(dict(here=here,
__file__=ini_file,
zope_conf=zope_conf),
**dict(configparser.items(local_conf_key)))
示例7: test_export_empty_site
# 需要导入模块: from ConfigParser import ConfigParser [as 别名]
# 或者: from ConfigParser.ConfigParser import defaults [as 别名]
def test_export_empty_site(self):
self._setUpAdapters()
site = _makeFolder('site')
site.title = 'test_export_empty_site'
site.description = 'Testing export of an empty site.'
context = DummyExportContext(site)
exporter = self._getExporter()
exporter(context)
self.assertEqual(len(context._wrote), 2)
filename, text, content_type = context._wrote[0]
self.assertEqual(filename, 'structure/.objects')
self.assertEqual(content_type, 'text/comma-separated-values')
objects = [x for x in reader(StringIO(text))]
self.assertEqual(len(objects), 0)
filename, text, content_type = context._wrote[1]
self.assertEqual(filename, 'structure/.properties')
self.assertEqual(content_type, 'text/plain')
parser = ConfigParser()
parser.readfp(StringIO(text))
defaults = parser.defaults()
self.assertEqual(len(defaults), 1)
self.assertEqual(defaults['title'], site.title)
示例8: options
# 需要导入模块: from ConfigParser import ConfigParser [as 别名]
# 或者: from ConfigParser.ConfigParser import defaults [as 别名]
def options(self):
# If all fails we will always have default values
configuration = self.defaults()
try:
if self.config == None or isfile(self.config) == False:
configuration = self.defaults()
return configuration
except TypeError:
# if we are getting a ready-to-go dict then we still try
# to do our little translation-and-map thing and if that
# comes out as empty, then we assume keys are already
# translated
if type(self.config) is dict:
configuration = self.key_matcher(self.config, return_empty=True)
if not configuration:
configuration = self.defaults(self.config)
return configuration
# we could get an object that is dict-like but type(object)
# doesn't recognize it as a dict
else:
configuration = self.key_matcher(self.config)
return configuration
else: # this will get executed *only* if we are seeing a file
try:
parser = ConfigParser()
parser.read(self.config)
file_options = parser.defaults()
configuration = self.key_matcher(file_options)
except Exception, error:
raise OptionConfigurationError(error)
示例9: test_export_empty_site_with_setup_tool
# 需要导入模块: from ConfigParser import ConfigParser [as 别名]
# 或者: from ConfigParser.ConfigParser import defaults [as 别名]
def test_export_empty_site_with_setup_tool(self):
self._setUpAdapters()
site = _makeFolder('site')
site._setObject('setup_tool', self._makeSetupTool())
site._updateProperty('title', 'test_export_empty_site_with_setup_tool')
site._setProperty('description',
'Testing export of an empty site with setup tool.')
context = DummyExportContext(site)
exporter = self._getExporter()
exporter(context)
self.assertEqual(len(context._wrote), 2)
filename, text, content_type = context._wrote[0]
self.assertEqual(filename, 'structure/.objects')
self.assertEqual(content_type, 'text/comma-separated-values')
objects = [x for x in reader(StringIO(text))]
self.assertEqual(len(objects), 0)
filename, text, content_type = context._wrote[1]
self.assertEqual(filename, 'structure/.properties')
self.assertEqual(content_type, 'text/plain')
parser = ConfigParser()
parser.readfp(StringIO(text))
defaults = parser.defaults()
self.assertEqual(len(defaults), 2)
self.assertEqual(defaults['title'], site.title)
self.assertEqual(defaults['description'], site.description)
示例10: load_environment
# 需要导入模块: from ConfigParser import ConfigParser [as 别名]
# 或者: from ConfigParser.ConfigParser import defaults [as 别名]
def load_environment(global_conf, app_conf):
"""Configure the Pylons environment via the ``pylons.config``
object
"""
config = PylonsConfig()
# Pylons paths
root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
paths = dict(root=root,
controllers=os.path.join(root, 'controllers'),
static_files=os.path.join(root, 'public'),
templates=[os.path.join(root, 'templates')])
# import our private.ini that holds keys, etc
imp = global_conf.get('import')
if imp:
cp = ConfigParser()
cp.read(imp)
global_conf.update(cp.defaults())
if cp.has_section('APP'):
app_conf.update(cp.items('APP'))
# Initialize config with the basic options
config.init_app(global_conf, app_conf, package='linkdrop', paths=paths)
config['routes.map'] = make_map(config)
config['pylons.app_globals'] = app_globals.Globals(config)
import linkdrop.lib.helpers as h
config['pylons.h'] = h
# Setup cache object as early as possible
import pylons
pylons.cache._push_object(config['pylons.app_globals'].cache)
# Create the Mako TemplateLookup, with the default auto-escaping
config['pylons.app_globals'].mako_lookup = TemplateLookup(
directories=paths['templates'],
error_handler=handle_mako_error,
module_directory=os.path.join(app_conf['cache_dir'], 'templates'),
input_encoding='utf-8', default_filters=['escape'],
imports=['from webhelpers.html import escape'])
# Setup the SQLAlchemy database engine
engine = engine_from_config(config, 'sqlalchemy.')
init_model(engine)
# sqlalchemy auto migration
if asbool(config.get('migrate.auto')):
try:
# managed upgrades
cschema = schema.ControlledSchema.create(engine, config['migrate.repository'])
cschema.update_db_from_model(meta.Base.metadata)
except exceptions.InvalidRepositoryError, e:
# unmanaged upgrades
diff = schemadiff.getDiffOfModelAgainstDatabase(
meta.Base.metadata, engine, excludeTables=None)
genmodel.ModelGenerator(diff).applyModel()
示例11: parse_config
# 需要导入模块: from ConfigParser import ConfigParser [as 别名]
# 或者: from ConfigParser.ConfigParser import defaults [as 别名]
def parse_config(self):
"""
Reads the config file (default in /etc/vcscommit/vcscommit.cfg
:rtype: ConfigParser object
"""
cfg = ConfigParser()
cfg.read('/etc/vcscommit/vcscommit.cfg')
return cfg.defaults()
示例12: defaults
# 需要导入模块: from ConfigParser import ConfigParser [as 别名]
# 或者: from ConfigParser.ConfigParser import defaults [as 别名]
def defaults(self):
"""Return the defaults, with their values interpolated (with the
defaults dict itself)
Mainly to support defaults using values such as %(here)s
"""
defaults = ConfigParser.defaults(self).copy()
for key, val in iteritems(defaults):
defaults[key] = self.get('DEFAULT', key) or val
return defaults
示例13: test_as_ini_no_properties
# 需要导入模块: from ConfigParser import ConfigParser [as 别名]
# 或者: from ConfigParser.ConfigParser import defaults [as 别名]
def test_as_ini_no_properties(self):
context = _makePropertied('no_properties')
context._properties = ()
adapter = self._getTargetClass()(context)
text = adapter.as_ini()
parser = ConfigParser()
parser.readfp(StringIO(text))
self.failIf(parser.sections())
default_options = parser.defaults()
self.assertEqual(len(default_options), 0)
示例14: put_ini
# 需要导入模块: from ConfigParser import ConfigParser [as 别名]
# 或者: from ConfigParser.ConfigParser import defaults [as 别名]
def put_ini(self, text):
"""
"""
context = self.context
parser = ConfigParser()
parser.readfp(StringIO(text))
for option, value in parser.defaults().items():
prop_type = context.getPropertyType(option)
if prop_type is None:
context._setProperty(option, value, 'string')
else:
context._updateProperty(option, value)
示例15: Config
# 需要导入模块: from ConfigParser import ConfigParser [as 别名]
# 或者: from ConfigParser.ConfigParser import defaults [as 别名]
class Config(object):
def __init__(self):
self._parser = ConfigParser()
self._parser._defaults = IncludeDict(self._parser)
# Copy attributes from the parser to avoid one additional
# function call on each access.
for attr in ["has_section", "remove_section"]:
setattr(self, attr, getattr(self._parser, attr))
def read_configs(self, configs):
for config in configs:
match = re.match("(.*)/([^/]+)=(.*)", config)
if not match:
raise Exception, "Invalid config string: %s" % config
(name, option, value) = match.groups()
if not self._parser.has_section(name):
self._parser.add_section(name)
self._parser.set(name, option, value)
def read_file(self, file, filename="<stream>"):
logging.info("Reading configurations from: %s", filename)
self._parser.readfp(file, filename)
def read_filename(self, filename):
if not posixpath.exists(filename):
raise Exception, "No such configuration file: %s" % filename
file = open(filename, "r")
return self.read_file(file, filename)
def get_defaults(self):
attributes = self._parser.defaults()
return ConfigDefaults(self, 'DEFAULT', attributes)
def get_section(self, name):
if self._parser.has_section(name):
attributes = dict(self._parser.items(name))
return ConfigSection(self, name, attributes)
return None
def get_section_names(self):
return self._parser.sections()
def add_section(self, name):
self._parser.add_section(name)
return self.get_section(name)