本文整理汇总了Python中r2.lib.configparse.ConfigValue类的典型用法代码示例。如果您正苦于以下问题:Python ConfigValue类的具体用法?Python ConfigValue怎么用?Python ConfigValue使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ConfigValue类的18个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: load_environment
def load_environment(global_conf={}, app_conf={}, setup_globals=True):
# Setup our paths
root_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
paths = {'root': root_path,
'controllers': os.path.join(root_path, 'controllers'),
'templates': [os.path.join(root_path, 'templates')],
}
if ConfigValue.bool(global_conf.get('uncompressedJS')):
paths['static_files'] = os.path.join(root_path, 'public')
else:
paths['static_files'] = os.path.join(os.path.dirname(root_path), 'build/public')
config.init_app(global_conf, app_conf, package='r2',
template_engine='mako', paths=paths)
g = config['pylons.g'] = Globals(global_conf, app_conf, paths)
if setup_globals:
g.setup()
g.plugins.declare_queues(g.queues)
r2.config.cache = g.cache
g.plugins.load_plugins()
config['r2.plugins'] = g.plugins
g.startup_timer.intermediate("plugins")
config['pylons.h'] = r2.lib.helpers
config['routes.map'] = routing.make_map()
#override the default response options
config['pylons.response_options']['headers'] = {}
# The following template options are passed to your template engines
tmpl_options = config['buffet.template_options']
tmpl_options['mako.filesystem_checks'] = getattr(g, 'reload_templates', False)
tmpl_options['mako.default_filters'] = ["mako_websafe"]
tmpl_options['mako.imports'] = \
["from r2.lib.filters import websafe, unsafe, mako_websafe",
"from pylons import c, g, request",
"from pylons.i18n import _, ungettext"]
# when mako loads a previously compiled template file from its cache, it
# doesn't check that the original template path matches the current path.
# in the event that a new plugin defines a template overriding a reddit
# template, unless the mtime newer, mako doesn't update the compiled
# template. as a workaround, this makes mako store compiled templates with
# the original path in the filename, forcing it to update with the path.
def mako_module_path(filename, uri):
module_directory = tmpl_options['mako.module_directory']
filename = filename.lstrip('/').replace('/', '-')
path = os.path.join(module_directory, filename + ".py")
return os.path.abspath(path)
tmpl_options['mako.modulename_callable'] = mako_module_path
if setup_globals:
g.setup_complete()
开发者ID:BenHalberstam,项目名称:reddit,代码行数:57,代码来源:environment.py
示例2: test_dict
def test_dict(self):
self.assertEquals({}, ConfigValue.dict(str, str)(''))
self.assertEquals({'a': ''}, ConfigValue.dict(str, str)('a'))
self.assertEquals({'a': 3}, ConfigValue.dict(str, int)('a: 3'))
self.assertEquals({'a': 3, 'b': 4},
ConfigValue.dict(str, int)('a: 3, b: 4'))
self.assertEquals({'a': (3, 5), 'b': (4, 6)},
ConfigValue.dict(
str, ConfigValue.tuple_of(int), delim=';')
('a: 3, 5; b: 4, 6'))
开发者ID:AHAMED750,项目名称:reddit,代码行数:10,代码来源:configparse_test.py
示例3: load_environment
def load_environment(global_conf={}, app_conf={}, setup_globals=True):
# Setup our paths
root_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
paths = {
"root": root_path,
"controllers": os.path.join(root_path, "controllers"),
"templates": [os.path.join(root_path, "templates")],
}
if ConfigValue.bool(global_conf.get("uncompressedJS")):
paths["static_files"] = os.path.join(root_path, "public")
else:
paths["static_files"] = os.path.join(os.path.dirname(root_path), "build/public")
config.init_app(global_conf, app_conf, package="r2", template_engine="mako", paths=paths)
g = config["pylons.g"] = Globals(global_conf, app_conf, paths)
if setup_globals:
g.setup()
r2.config.cache = g.cache
g.plugins.load_plugins()
config["r2.plugins"] = g.plugins
config["pylons.h"] = r2.lib.helpers
config["routes.map"] = routing.make_map()
# override the default response options
config["pylons.response_options"]["headers"] = {}
# The following template options are passed to your template engines
# tmpl_options = {}
# tmpl_options['myghty.log_errors'] = True
# tmpl_options['myghty.escapes'] = dict(l=webhelpers.auto_link, s=webhelpers.simple_format)
tmpl_options = config["buffet.template_options"]
tmpl_options["mako.filesystem_checks"] = getattr(g, "reload_templates", False)
tmpl_options["mako.default_filters"] = ["mako_websafe"]
tmpl_options["mako.imports"] = [
"from r2.lib.filters import websafe, unsafe, mako_websafe",
"from pylons import c, g, request",
"from pylons.i18n import _, ungettext",
]
开发者ID:nod3x,项目名称:reddit,代码行数:43,代码来源:environment.py
示例4: load_environment
def load_environment(global_conf={}, app_conf={}, setup_globals=True):
# Setup our paths
root_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
paths = {'root': root_path,
'controllers': os.path.join(root_path, 'controllers'),
'templates': tmpl_dirs,
}
if ConfigValue.bool(global_conf.get('uncompressedJS')):
paths['static_files'] = os.path.join(root_path, 'public')
else:
paths['static_files'] = os.path.join(os.path.dirname(root_path), 'build/public')
config.init_app(global_conf, app_conf, package='r2',
template_engine='mako', paths=paths)
g = config['pylons.g'] = Globals(global_conf, app_conf, paths)
if setup_globals:
g.setup()
reddit_config.cache = g.cache
config['pylons.h'] = r2.lib.helpers
g.plugins = config['r2.plugins'] = PluginLoader().load_plugins(g.config.get('plugins', []))
config['routes.map'] = routing.make_map()
#override the default response options
config['pylons.response_options']['headers'] = {}
# The following template options are passed to your template engines
#tmpl_options = {}
#tmpl_options['myghty.log_errors'] = True
#tmpl_options['myghty.escapes'] = dict(l=webhelpers.auto_link, s=webhelpers.simple_format)
tmpl_options = config['buffet.template_options']
tmpl_options['mako.filesystem_checks'] = getattr(g, 'reload_templates', False)
tmpl_options['mako.default_filters'] = ["mako_websafe"]
tmpl_options['mako.imports'] = \
["from r2.lib.filters import websafe, unsafe, mako_websafe",
"from pylons import c, g, request",
"from pylons.i18n import _, ungettext"]
开发者ID:barneyfoxuk,项目名称:reddit,代码行数:42,代码来源:environment.py
示例5: load_environment
def load_environment(global_conf={}, app_conf={}, setup_globals=True):
# Setup our paths
root_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
paths = {'root': root_path,
'controllers': os.path.join(root_path, 'controllers'),
'templates': [os.path.join(root_path, 'templates')],
}
if ConfigValue.bool(global_conf.get('uncompressedJS')):
paths['static_files'] = os.path.join(root_path, 'public')
else:
paths['static_files'] = os.path.join(os.path.dirname(root_path), 'build/public')
config.init_app(global_conf, app_conf, package='r2',
template_engine='mako', paths=paths)
# don't put action arguments onto c automatically
config['pylons.c_attach_args'] = False
# when accessing non-existent attributes on c, return "" instead of dying
config['pylons.strict_c'] = False
g = config['pylons.g'] = Globals(global_conf, app_conf, paths)
if setup_globals:
g.setup()
g.plugins.declare_queues(g.queues)
g.plugins.load_plugins()
config['r2.plugins'] = g.plugins
g.startup_timer.intermediate("plugins")
config['pylons.h'] = r2.lib.helpers
config['routes.map'] = routing.make_map()
#override the default response options
config['pylons.response_options']['headers'] = {}
# when mako loads a previously compiled template file from its cache, it
# doesn't check that the original template path matches the current path.
# in the event that a new plugin defines a template overriding a reddit
# template, unless the mtime newer, mako doesn't update the compiled
# template. as a workaround, this makes mako store compiled templates with
# the original path in the filename, forcing it to update with the path.
if "cache_dir" in app_conf:
module_directory = os.path.join(app_conf['cache_dir'], 'templates')
def mako_module_path(filename, uri):
filename = filename.lstrip('/').replace('/', '-')
path = os.path.join(module_directory, filename + ".py")
return os.path.abspath(path)
else:
# we're probably in "paster run standalone" mode. we'll just avoid
# caching templates since we don't know where they should go.
module_directory = mako_module_path = None
# set up the templating system
config["pylons.g"].mako_lookup = TemplateLookup(
directories=paths["templates"],
error_handler=handle_mako_error,
module_directory=module_directory,
input_encoding="utf-8",
default_filters=["mako_websafe"],
filesystem_checks=getattr(g, "reload_templates", False),
imports=[
"from r2.lib.filters import websafe, unsafe, mako_websafe",
"from pylons import c, g, request",
"from pylons.i18n import _, ungettext",
],
modulename_callable=mako_module_path,
)
if setup_globals:
g.setup_complete()
开发者ID:383530895,项目名称:reddit,代码行数:72,代码来源:environment.py
示例6: load_environment
def load_environment(global_conf={}, app_conf={}, setup_globals=True):
r2_path = get_r2_path()
root_path = os.path.join(r2_path, "r2")
paths = {
"root": root_path,
"controllers": os.path.join(root_path, "controllers"),
"templates": [os.path.join(root_path, "templates")],
}
if ConfigValue.bool(global_conf.get("uncompressedJS")):
paths["static_files"] = get_raw_statics_path()
else:
paths["static_files"] = get_built_statics_path()
config = PylonsConfig()
config.init_app(global_conf, app_conf, package="r2", paths=paths)
# don't put action arguments onto c automatically
config["pylons.c_attach_args"] = False
# when accessing non-existent attributes on c, return "" instead of dying
config["pylons.strict_tmpl_context"] = False
g = Globals(config, global_conf, app_conf, paths)
config["pylons.app_globals"] = g
if setup_globals:
config["r2.import_private"] = ConfigValue.bool(global_conf["import_private"])
g.setup()
g.plugins.declare_queues(g.queues)
g.plugins.load_plugins(config)
config["r2.plugins"] = g.plugins
g.startup_timer.intermediate("plugins")
config["pylons.h"] = r2.lib.helpers
config["routes.map"] = make_map(config)
# override the default response options
config["pylons.response_options"]["headers"] = {}
# when mako loads a previously compiled template file from its cache, it
# doesn't check that the original template path matches the current path.
# in the event that a new plugin defines a template overriding a reddit
# template, unless the mtime newer, mako doesn't update the compiled
# template. as a workaround, this makes mako store compiled templates with
# the original path in the filename, forcing it to update with the path.
if "cache_dir" in app_conf:
module_directory = os.path.join(app_conf["cache_dir"], "templates")
def mako_module_path(filename, uri):
filename = filename.lstrip("/").replace("/", "-")
path = os.path.join(module_directory, filename + ".py")
return os.path.abspath(path)
else:
# disable caching templates since we don't know where they should go.
module_directory = mako_module_path = None
# set up the templating system
config["pylons.app_globals"].mako_lookup = TemplateLookup(
directories=paths["templates"],
error_handler=handle_mako_error,
module_directory=module_directory,
input_encoding="utf-8",
default_filters=["conditional_websafe"],
filesystem_checks=getattr(g, "reload_templates", False),
imports=[
"from r2.lib.filters import websafe, unsafe, conditional_websafe",
"from pylons import request",
"from pylons import tmpl_context as c",
"from pylons import app_globals as g",
"from pylons.i18n import _, ungettext",
],
modulename_callable=mako_module_path,
)
if setup_globals:
g.setup_complete()
return config
开发者ID:Shilohtd,项目名称:reddit,代码行数:83,代码来源:environment.py
示例7: test_timeinterval
def test_timeinterval(self):
self.assertEquals(datetime.timedelta(0, 60),
ConfigValue.timeinterval('1 minute'))
with self.assertRaises(KeyError):
ConfigValue.timeinterval('asdf')
开发者ID:AHAMED750,项目名称:reddit,代码行数:5,代码来源:configparse_test.py
示例8: test_choice
def test_choice(self):
self.assertEquals(1, ConfigValue.choice(alpha=1)('alpha'))
self.assertEquals(2, ConfigValue.choice(alpha=1, beta=2)('beta'))
with self.assertRaises(ValueError):
ConfigValue.choice(alpha=1)('asdf')
开发者ID:AHAMED750,项目名称:reddit,代码行数:5,代码来源:configparse_test.py
示例9: test_tuple_of
def test_tuple_of(self):
self.assertEquals((), ConfigValue.tuple_of(str)(''))
self.assertEquals(('a', 'b'), ConfigValue.tuple_of(str)('a, b'))
self.assertEquals(('a', 'b'),
ConfigValue.tuple_of(str, delim=':')('a : b'))
开发者ID:AHAMED750,项目名称:reddit,代码行数:5,代码来源:configparse_test.py
示例10: test_set
def test_set(self):
self.assertEquals(set([]), ConfigValue.set(''))
self.assertEquals(set(['a', 'b']), ConfigValue.set('a, b'))
开发者ID:AHAMED750,项目名称:reddit,代码行数:3,代码来源:configparse_test.py
示例11: test_tuple
def test_tuple(self):
self.assertEquals((), ConfigValue.tuple(''))
self.assertEquals(('a', 'b'), ConfigValue.tuple('a, b'))
开发者ID:AHAMED750,项目名称:reddit,代码行数:3,代码来源:configparse_test.py
示例12: test_bool
def test_bool(self):
self.assertEquals(True, ConfigValue.bool('TrUe'))
self.assertEquals(False, ConfigValue.bool('fAlSe'))
with self.assertRaises(ValueError):
ConfigValue.bool('asdf')
开发者ID:AHAMED750,项目名称:reddit,代码行数:5,代码来源:configparse_test.py
示例13: test_float
def test_float(self):
self.assertEquals(3.0, ConfigValue.float('3'))
self.assertEquals(-3.0, ConfigValue.float('-3'))
with self.assertRaises(ValueError):
ConfigValue.float('asdf')
开发者ID:AHAMED750,项目名称:reddit,代码行数:5,代码来源:configparse_test.py
示例14: test_int
def test_int(self):
self.assertEquals(3, ConfigValue.int('3'))
self.assertEquals(-3, ConfigValue.int('-3'))
with self.assertRaises(ValueError):
ConfigValue.int('asdf')
开发者ID:AHAMED750,项目名称:reddit,代码行数:5,代码来源:configparse_test.py
示例15: test_str
def test_str(self):
self.assertEquals('x', ConfigValue.str('x'))
开发者ID:AHAMED750,项目名称:reddit,代码行数:2,代码来源:configparse_test.py
示例16: test_set_of
def test_set_of(self):
self.assertEquals(set([]), ConfigValue.set_of(str)(''))
self.assertEquals(set(['a', 'b']), ConfigValue.set_of(str)('a, b, b'))
self.assertEquals(set(['a', 'b']),
ConfigValue.set_of(str, delim=':')('b : a : b'))
开发者ID:AHAMED750,项目名称:reddit,代码行数:5,代码来源:configparse_test.py
示例17: load_db_params
def load_db_params(self):
self.databases = tuple(ConfigValue.to_iter(self.config.raw_data['databases']))
self.db_params = {}
if not self.databases:
return
dbm = db_manager.db_manager()
db_param_names = ('name', 'db_host', 'db_user', 'db_pass', 'db_port',
'pool_size', 'max_overflow')
for db_name in self.databases:
conf_params = ConfigValue.to_iter(self.config.raw_data[db_name + '_db'])
params = dict(zip(db_param_names, conf_params))
if params['db_user'] == "*":
params['db_user'] = self.db_user
if params['db_pass'] == "*":
params['db_pass'] = self.db_pass
if params['db_port'] == "*":
params['db_port'] = self.db_port
if params['pool_size'] == "*":
params['pool_size'] = self.db_pool_size
if params['max_overflow'] == "*":
params['max_overflow'] = self.db_pool_overflow_size
dbm.setup_db(db_name, g_override=self, **params)
self.db_params[db_name] = params
dbm.type_db = dbm.get_engine(self.config.raw_data['type_db'])
dbm.relation_type_db = dbm.get_engine(self.config.raw_data['rel_type_db'])
def split_flags(raw_params):
params = []
flags = {}
for param in raw_params:
if not param.startswith("!"):
params.append(param)
else:
key, sep, value = param[1:].partition("=")
if sep:
flags[key] = value
else:
flags[key] = True
return params, flags
prefix = 'db_table_'
self.predefined_type_ids = {}
for k, v in self.config.raw_data.iteritems():
if not k.startswith(prefix):
continue
params, table_flags = split_flags(ConfigValue.to_iter(v))
name = k[len(prefix):]
kind = params[0]
server_list = self.config.raw_data["db_servers_" + name]
engines, flags = split_flags(ConfigValue.to_iter(server_list))
typeid = table_flags.get("typeid")
if typeid:
self.predefined_type_ids[name] = int(typeid)
if kind == 'thing':
dbm.add_thing(name, dbm.get_engines(engines),
**flags)
elif kind == 'relation':
dbm.add_relation(name, params[1], params[2],
dbm.get_engines(engines),
**flags)
return dbm
开发者ID:Anenome,项目名称:reddit,代码行数:70,代码来源:app_globals.py
示例18: load_db_params
def load_db_params(self):
self.databases = tuple(ConfigValue.to_iter(self.config.raw_data["databases"]))
self.db_params = {}
self.predefined_type_ids = {}
if not self.databases:
return
if self.env == "unit_test":
from mock import MagicMock
return MagicMock()
dbm = db_manager.db_manager()
db_param_names = ("name", "db_host", "db_user", "db_pass", "db_port", "pool_size", "max_overflow")
for db_name in self.databases:
conf_params = ConfigValue.to_iter(self.config.raw_data[db_name + "_db"])
params = dict(zip(db_param_names, conf_params))
if params["db_user"] == "*":
params["db_user"] = self.db_user
if params["db_pass"] == "*":
params["db_pass"] = self.db_pass
if params["db_port"] == "*":
params["db_port"] = self.db_port
if params["pool_size"] == "*":
params["pool_size"] = self.db_pool_size
if params["max_overflow"] == "*":
params["max_overflow"] = self.db_pool_overflow_size
dbm.setup_db(db_name, g_override=self, **params)
self.db_params[db_name] = params
dbm.type_db = dbm.get_engine(self.config.raw_data["type_db"])
dbm.relation_type_db = dbm.get_engine(self.config.raw_data["rel_type_db"])
def split_flags(raw_params):
params = []
flags = {}
for param in raw_params:
if not param.startswith("!"):
params.append(param)
else:
key, sep, value = param[1:].partition("=")
if sep:
flags[key] = value
else:
flags[key] = True
return params, flags
prefix = "db_table_"
for k, v in self.config.raw_data.iteritems():
if not k.startswith(prefix):
continue
params, table_flags = split_flags(ConfigValue.to_iter(v))
name = k[len(prefix) :]
kind = params[0]
server_list = self.config.raw_data["db_servers_" + name]
engines, flags = split_flags(ConfigValue.to_iter(server_list))
typeid = table_flags.get("typeid")
if typeid:
self.predefined_type_ids[name] = int(typeid)
if kind == "thing":
dbm.add_thing(name, dbm.get_engines(engines), **flags)
elif kind == "relation":
dbm.add_relation(name, params[1], params[2], dbm.get_engines(engines), **flags)
return dbm
开发者ID:loganfreeman,项目名称:reddit,代码行数:71,代码来源:app_globals.py
注:本文中的r2.lib.configparse.ConfigValue类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论