本文整理汇总了Python中mozsvc.plugin.load_and_register函数的典型用法代码示例。如果您正苦于以下问题:Python load_and_register函数的具体用法?Python load_and_register怎么用?Python load_and_register使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了load_and_register函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: setUp
def setUp(self):
super(TestShardedNode, self).setUp()
# get the options from the config
self.config = testing.setUp()
self.ini = os.path.join(os.path.dirname(__file__),
'test_sharded.ini')
settings = {}
load_into_settings(self.ini, settings)
self.config.add_settings(settings)
# instantiate the backend to test
self.config.include("tokenserver")
load_and_register("tokenserver", self.config)
self.backend = self.config.registry.getUtility(INodeAssignment)
# adding a node with 100 slots
self.backend._safe_execute(
"""insert into nodes (`node`, `service`, `available`,
`capacity`, `current_load`, `downed`, `backoff`)
values ("https://phx12", "sync-1.0", 100, 100, 0, 0, 0)""",
service=_SERVICE)
self.backend._safe_execute(
"""insert into service_pattern
(`service`, `pattern`)
values
("sync-1.0", "{node}/{version}/{uid}")""",
service="sync-1.0")
self._sqlite = self.backend._dbs['sync'][0].driver == 'pysqlite'
read_endpoints(self.config)
开发者ID:hfeeki,项目名称:tokenserver,代码行数:33,代码来源:test_backend_shardedsql.py
示例2: includeme
def includeme(config):
config.include("cornice")
config.include("mozsvc")
config.include("pyramid_whoauth")
config.scan("tokenserver.views")
# initializes the assignment backend
load_and_register("tokenserver", config)
# initializes the powerhose backend
try:
load_and_register("powerhose", config)
except NoSectionError:
pass
# load apps and set them up back in the setting
settings = config.registry.settings
key = 'tokenserver.applications'
applications = defaultdict(list)
for element in settings.get(key, '').split(','):
element = element.strip()
if element == '':
continue
element = element.split('-')
if len(element) != 2:
continue
app, version = element
applications[app].append(version)
settings[key] = applications
# load the secrets file
key = 'tokenserver.secrets_file'
settings[key] = Secrets(settings[key])
开发者ID:almet,项目名称:tokenserver,代码行数:34,代码来源:__init__.py
示例3: test_loading_with_conflict_detection
def test_loading_with_conflict_detection(self):
settings = {
"test1.backend": "mozsvc.tests.test_plugin.Test1",
"test_both.backend": "mozsvc.tests.test_plugin.Test1And2",
}
config = Configurator(settings=settings)
load_and_register("test1", config)
load_and_register("test_both", config)
self.assertRaises(ConfigurationConflictError, config.commit)
开发者ID:mozilla-services,项目名称:mozservices,代码行数:9,代码来源:test_plugin.py
示例4: includeme
def includeme(config):
settings = config.registry.settings
if settings.get('tokenserver.monkey_patch_gevent', True):
monkey_patch_gevent()
config.include("cornice")
config.include("mozsvc")
config.include("tokenserver.tweens")
config.scan("tokenserver.views")
# initializes the assignment backend
load_and_register("tokenserver", config)
# initialize the and browserid backend if it exists
if "browserid.backend" in settings:
load_and_register("browserid", config)
# load apps and set them up back in the setting
key = 'tokenserver.applications'
applications = defaultdict(list)
for element in settings.get(key, '').split(','):
element = element.strip()
if element == '':
continue
element = element.split('-')
if len(element) != 2:
continue
app, version = element
applications[app].append(version)
settings[key] = applications
# load the secrets backend, with a b/w-compat hook
# for the old 'secrets_file' setting.
secrets_file = settings.get('tokenserver.secrets_file')
if secrets_file is not None:
if 'tokenserver.secrets.backend' in settings:
raise ValueError("can't use secrets_file with secrets.backend")
if isinstance(secrets_file, basestring):
secrets_file = secrets_file.split()
settings['tokenserver.secrets.backend'] = 'mozsvc.secrets.Secrets'
settings['tokenserver.secrets.filename'] = secrets_file
secrets = load_from_settings('tokenserver.secrets', settings)
settings['tokenserver.secrets'] = secrets
# ensure the metrics_id_secret_key is an ascii string.
id_key = settings.get('fxa.metrics_uid_secret_key')
if id_key is None:
logger.warning(
'fxa.metrics_uid_secret_key is not set. '
'This will allow PII to be more easily identified')
elif isinstance(id_key, unicode):
settings['fxa.metrics_uid_secret_key'] = id_key.encode('ascii')
read_endpoints(config)
开发者ID:adamchainz,项目名称:tokenserver,代码行数:55,代码来源:__init__.py
示例5: setUp
def setUp(self):
self.config = testing.setUp()
settings = {}
load_into_settings(self.get_ini(), settings)
self.config.add_settings(settings)
self.config.include("tokenserver")
load_and_register("tokenserver", self.config)
self.backend = self.config.registry.getUtility(INodeAssignment)
self.backend.add_service(SERVICE, "{node}/{version}/{uid}")
self.backend.add_node(SERVICE, "https://phx12", 100)
self.logs = LogCapture()
开发者ID:mozilla-services,项目名称:tokenserver,代码行数:11,代码来源:test_process_account_events.py
示例6: includeme
def includeme(config):
# adds cornice
config.include("cornice")
# adds Mozilla default views
config.include("mozsvc")
# adds local views
config.scan("appsync.views")
# initializes the storage backend
load_and_register("storage", config)
开发者ID:anantn,项目名称:appsync,代码行数:12,代码来源:__init__.py
示例7: setUpClass
def setUpClass(cls):
cls.config = testing.setUp()
settings = {}
try:
fileConfig(cls.get_ini())
except NoSectionError:
pass
load_into_settings(cls.get_ini(), settings)
cls.config.add_settings(settings)
cls.config.include("tokenserver")
load_and_register("tokenserver", cls.config)
cls.backend = cls.config.registry.getUtility(INodeAssignment)
开发者ID:jrgm,项目名称:tokenserver,代码行数:12,代码来源:test_powerhose.py
示例8: includeme
def includeme(config):
"""Include the default app-session-management definitions.
Call this function on a pyramid configurator to register a utility for
the IAppSessionDB interface. The particular implementation to use will
be taken from the configurator settings dict, falling back to a simple
in-memory implementation as the default.
"""
settings = config.get_settings()
if "sauropod.session.backend" not in settings:
default_backend = "pysauropod.server.session.SignedSessionManager"
settings["sauropod.session.backend"] = default_backend
plugin.load_and_register("sauropod.session", config)
开发者ID:mozilla,项目名称:sauropod,代码行数:13,代码来源:session.py
示例9: includeme
def includeme(config):
"""Include the default credential-checking definitions.
Call this function on a pyramid configurator to register a utility for
the ICredentialChecker interface. The particular implementation to use
will be taken from the configurator settings dict, falling back to a
BrowserID-based scheme as the default.
"""
settings = config.get_settings()
if "sauropod.credentials.backend" not in settings:
# default_backend = "pysauropod.server.credentials.BrowserIDCredentials"
default_backend = "pysauropod.server.credentials.DummyCredentials"
settings["sauropod.credentials.backend"] = default_backend
plugin.load_and_register("sauropod.credentials", config)
开发者ID:dclarke,项目名称:sauropod,代码行数:14,代码来源:credentials.py
示例10: setUp
def setUp(self):
self.config = testing.setUp()
settings = {}
load_into_settings(self.get_ini(), settings)
self.config.add_settings(settings)
self.config.include("tokenserver")
load_and_register("tokenserver", self.config)
self.backend = self.config.registry.getUtility(INodeAssignment)
wsgiapp = self.config.make_wsgi_app()
wsgiapp = CatchErrors(wsgiapp)
self.app = TestApp(wsgiapp)
# Mock out the verifier to return successfully by default.
self.mock_verifier_context = self.mock_verifier()
self.mock_verifier_context.__enter__()
self.logs = LogCapture()
开发者ID:mozilla-services,项目名称:tokenserver,代码行数:15,代码来源:test_service.py
示例11: includeme
def includeme(config):
config.include("cornice")
config.include("mozsvc")
config.include("pysauropod.server.security")
config.include("pysauropod.server.session")
config.include("pysauropod.server.credentials")
config.scan("pysauropod.server.views")
settings = config.get_settings()
if "sauropod.storage.backend" not in settings:
default_backend = "pysauropod.backends.sql:SQLBackend"
settings["sauropod.storage.backend"] = default_backend
#settings["sauropod.storage.sqluri"] = "sqlite:///:memory:"
settings["sauropod.storage.sqluri"] = "sqlite:////tmp/sauropod.db"
settings["sauropod.storage.create_tables"] = True
plugin.load_and_register("sauropod.storage", config)
开发者ID:dclarke,项目名称:sauropod,代码行数:15,代码来源:__init__.py
示例12: test_shard
def test_shard(self):
# Use a configuration with sharding enabled.
config = get_test_configurator(__file__, 'tests-shard.ini')
storage = load_and_register("storage", config)
# Make sure it's using the expected table name.
table = storage.dbconnector.get_bso_table(_UID).name
self.assertEqual(table, 'bso1')
# The table should initially be empty.
COUNT_ITEMS = 'select count(*) from bso1 /* queryName=COUNT_ITEMS */'
with storage.dbconnector.connect() as c:
res = c.execute(COUNT_ITEMS)
self.assertEqual(res.fetchall()[0][0], 0)
# Do a few things on the DB
id1 = 'ec1b7457-003a-45a9-bf1c-c34e37225ad7'
id2 = '339f52e1-deed-497c-837a-1ab25a655e37'
storage.set_item(_UID, 'col1', id1, {'payload': _PLD})
storage.set_item(_UID, 'col1', id2, {'payload': _PLD * 89})
self.assertEquals(len(storage.get_items(_UID, 'col1')["items"]), 2)
# Now make sure we did that in the right table
with storage.dbconnector.connect() as c:
res = c.execute(COUNT_ITEMS)
self.assertEqual(res.fetchall()[0][0], 2)
开发者ID:return42,项目名称:server-syncstorage,代码行数:26,代码来源:test_sql.py
示例13: main
def main(global_config, **settings):
config = get_configurator(global_config, **settings)
config.set_root_factory(Root)
# adds authorization
# option 1: auth via repoze.who
# config.include("pyramid_whoauth")
# option 2: auth based on IP address
# config.include("pyramid_ipauth")
# option 3: multiple stacked auth modules
# config.include("pyramid_multiauth")
# adds cornice
config.include("cornice")
# adds Mozilla default views
config.include("mozsvc")
# adds application-specific views
config.add_route("whoami", "/whoami")
# initialize the metrics plugin
config.registry["metrics"] = load_and_register("metrics", config)
config.scan("demoapp.views")
return config.make_wsgi_app()
开发者ID:crankycoder,项目名称:demoapp,代码行数:27,代码来源:__init__.py
示例14: includeme
def includeme(config):
try:
reset = load_and_register('reset_codes', config)
except Exception, e:
logger.error(traceback.format_exc())
logger.error("unable to load reset codes. Problem? %s" % e)
reset = None
开发者ID:rfk,项目名称:moz-account-portal,代码行数:7,代码来源:console.py
示例15: test_nopool_is_disabled_when_using_memory_database
def test_nopool_is_disabled_when_using_memory_database(self):
config = get_test_configurator(__file__, "tests-nopool.ini")
# Using no_pool=True will give you a NullPool when using file db.
storage = load_and_register("storage-file", config)
self.assertEqual(storage.dbconnector.engine.pool.__class__.__name__, "NullPool")
# Using no_pool=True will give you an error when using :memory: db.
self.assertRaises(ValueError, load_and_register, "storage-memory", config)
开发者ID:jrconlin,项目名称:server-syncstorage,代码行数:7,代码来源:test_sql.py
示例16: setUp
def setUp(self):
logger.debug("TestPowerService.setUp")
self.config = testing.setUp()
settings = {}
try:
fileConfig(self.get_ini())
except NoSectionError:
pass
load_into_settings(self.get_ini(), settings)
self.config.add_settings(settings)
self.config.include("tokenserver")
load_and_register("tokenserver", self.config)
self.backend = self.config.registry.getUtility(INodeAssignment)
wsgiapp = self.config.make_wsgi_app()
wsgiapp = CatchErrors(wsgiapp)
self.app = TestApp(wsgiapp)
time.sleep(1.)
开发者ID:almet,项目名称:tokenserver,代码行数:17,代码来源:test_powerhose.py
示例17: includeme
def includeme(config):
config.include("cornice")
config.include("mozsvc")
config.scan("tokenserver.views")
# initializes the assignment backend
load_and_register("tokenserver", config)
# initialize the powerhose and browserid backends if they exist
for section in ("powerhose", "browserid"):
try:
load_and_register(section, config)
except NoSectionError:
pass
# load apps and set them up back in the setting
settings = config.registry.settings
key = 'tokenserver.applications'
applications = defaultdict(list)
for element in settings.get(key, '').split(','):
element = element.strip()
if element == '':
continue
element = element.split('-')
if len(element) != 2:
continue
app, version = element
applications[app].append(version)
settings[key] = applications
# load the secrets file(s)
key = 'tokenserver.secrets_file'
secret_file = settings[key]
if not isinstance(secret_file, list):
secret_file = [secret_file]
files = []
for line in secret_file:
secret_file = [file for file in [file.strip() for file in line.split()]
if file != '']
files.extend(secret_file)
settings[key] = Secrets(files)
read_endpoints(config)
开发者ID:jrgm,项目名称:tokenserver,代码行数:45,代码来源:__init__.py
示例18: includeme
def includeme(config):
# adds cornice
config.include("cornice")
# adds Mozilla default views
config.include("mozsvc")
# adds local views
config.scan("appsync.views")
# initializes the storage backend
load_and_register("storage", config)
# initializes the cache tool
try:
load_and_register("cache", config)
except NoSectionError:
pass
开发者ID:mozilla,项目名称:appsync,代码行数:18,代码来源:__init__.py
示例19: test_no_create
def test_no_create(self):
# Storage with no create_tables option; it should default to false.
# This should fail because the table is absent
config = get_test_configurator(__file__, 'tests-nocreate.ini')
storage = load_and_register("storage", config)
bsos = [{"id": "TEST", "payload": _PLD}]
self.assertRaises(BackendError, storage.set_items, _UID, "test", bsos)
# Storage with create_tables explicitly set to false.
# This should fail because the table is absent
config = get_test_configurator(__file__, 'tests-dontcreate.ini')
storage = load_and_register("storage", config)
self.assertRaises(BackendError, storage.set_items, _UID, "test", bsos)
# Storage with create_tables explicit set to true.
# This should succeed because the table gets created.
config = get_test_configurator(__file__, 'tests-docreate.ini')
storage = load_and_register("storage", config)
storage.set_items(_UID, "test", bsos)
开发者ID:return42,项目名称:server-syncstorage,代码行数:19,代码来源:test_sql.py
示例20: test_loading_several_plugins
def test_loading_several_plugins(self):
settings = {
"test1.backend": "mozsvc.tests.test_plugin.Test1",
"test1.hello": "world",
"test2.backend": "mozsvc.tests.test_plugin.Test2",
}
config = Configurator(settings=settings)
plugin1 = load_and_register("test1", config)
plugin2 = load_and_register("test2", config)
config.commit()
self.failUnless(verifyObject(ITest1, plugin1))
self.failUnless(isinstance(plugin1, Test1))
self.assertEquals(plugin1.kwds["hello"], "world")
self.assertEquals(len(plugin1.kwds), 1)
self.failUnless(config.registry.queryUtility(ITest1) is plugin1)
self.failUnless(verifyObject(ITest2, plugin2))
self.failUnless(isinstance(plugin2, Test2))
self.assertEquals(len(plugin2.kwds), 0)
self.failUnless(config.registry.queryUtility(ITest2) is plugin2)
开发者ID:mozilla-services,项目名称:mozservices,代码行数:21,代码来源:test_plugin.py
注:本文中的mozsvc.plugin.load_and_register函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论