当前位置: 首页>>代码示例>>Python>>正文


Python Configurator.commit方法代码示例

本文整理汇总了Python中pyramid.config.Configurator.commit方法的典型用法代码示例。如果您正苦于以下问题:Python Configurator.commit方法的具体用法?Python Configurator.commit怎么用?Python Configurator.commit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyramid.config.Configurator的用法示例。


在下文中一共展示了Configurator.commit方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import commit [as 别名]
def main(argv=sys.argv):
	if len(argv) != 2:
		usage(argv)
	config_uri = argv[1]
	setup_logging(config_uri)
	settings = get_appsettings(config_uri)
	engine = engine_from_config(settings, 'sqlalchemy.')
	DBSession.configure(bind=engine)
	cache.cache = cache.configure_cache(settings)

	config = Configurator(
		settings=settings,
		root_factory=RootFactory,
		locale_negotiator=locale_neg
	)
	config.add_route_predicate('vhost', VHostPredicate)
	config.add_view_predicate('vhost', VHostPredicate)
	config.commit()

	mmgr = config.registry.getUtility(IModuleManager)
	mmgr.load('core')
	mmgr.load_enabled()

	rts = rt.configure(mmgr, config.registry)
	return rt.run(rts)
开发者ID:annndrey,项目名称:npui,代码行数:27,代码来源:rtd.py

示例2: make_app

# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import commit [as 别名]
 def make_app(cls, settings=None, config=None):
     settings = cls.get_app_settings(settings)
     config = Configurator(settings=settings)
     for event_cls in cls.subscribed:
         config.add_subscriber(cls.listener, event_cls)
     config.commit()
     return super().make_app(settings=settings, config=config)
开发者ID:ljakimczuk,项目名称:kinto,代码行数:9,代码来源:test_events.py

示例3: registerDummySecurityPolicy

# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import commit [as 别名]
def registerDummySecurityPolicy(userid=None, groupids=(), permissive=True):
    """ Registers a pair of faux :app:`Pyramid` security policies:
    a :term:`authentication policy` and a :term:`authorization
    policy`.

    The behavior of the registered :term:`authorization policy`
    depends on the ``permissive`` argument.  If ``permissive`` is
    true, a permissive :term:`authorization policy` is registered;
    this policy allows all access.  If ``permissive`` is false, a
    nonpermissive :term:`authorization policy` is registered; this
    policy denies all access.

    The behavior of the registered :term:`authentication policy`
    depends on the values provided for the ``userid`` and ``groupids``
    argument.  The authentication policy will return the userid
    identifier implied by the ``userid`` argument and the group ids
    implied by the ``groupids`` argument when the
    :func:`pyramid.security.authenticated_userid` or
    :func:`pyramid.security.effective_principals` APIs are used.

    This function is most useful when testing code that uses the APIs named
    :func:`pyramid.security.has_permission`,
    :func:`pyramid.security.authenticated_userid`,
    :func:`pyramid.security.unauthenticated_userid`,
    :func:`pyramid.security.effective_principals`, and
    :func:`pyramid.security.principals_allowed_by_permission`.
    """
    registry = get_current_registry()
    config = Configurator(registry=registry)
    result = config.testing_securitypolicy(userid=userid, groupids=groupids,
                                           permissive=permissive)
    config.commit()
    return result
开发者ID:araymund,项目名称:karl,代码行数:35,代码来源:testing.py

示例4: _apply_parent_actions

# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import commit [as 别名]
def _apply_parent_actions(parent_registry):
    toolbar_app = parent_registry.queryUtility(IToolbarWSGIApp)
    if toolbar_app is None:
        # this registry does not have a debugtoolbar attached
        return

    toolbar_registry = toolbar_app.registry

    # inject the BeforeRender subscriber after the application is created
    # and all other subscribers are registered in hopes that this will be
    # the last subscriber in the chain and will be able to see the effects
    # of all previous subscribers on the event
    parent_config = Configurator(registry=parent_registry, introspection=False)

    parent_config.add_subscriber(
        'pyramid_debugtoolbar.toolbar.beforerender_subscriber',
        'pyramid.events.BeforeRender',
    )

    actions = toolbar_registry.queryUtility(IParentActions, default=[])
    for action in actions:
        action(parent_config)

    # overwrite actions after they have been applied to avoid applying them
    # twice - but leave it as a new list incase someone adds more actions later
    # and calls config.make_wsgi_app() again... this would mainly be necessary
    # for tests that call config.make_wsgi_app() multiple times.
    toolbar_registry.registerUtility([], IParentActions)

    parent_config.commit()
开发者ID:Pylons,项目名称:pyramid_debugtoolbar,代码行数:32,代码来源:__init__.py

示例5: registerResources

# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import commit [as 别名]
def registerResources(resources):
    """ Registers a dictionary of :term:`resource` objects that can be
    resolved via the :func:`pyramid.traversal.find_resource` API.

    The :func:`pyramid.traversal.find_resource` API is called with a
    path as one of its arguments.  If the dictionary you register when
    calling this method contains that path as a string key
    (e.g. ``/foo/bar`` or ``foo/bar``), the corresponding value will
    be returned to ``find_resource`` (and thus to your code) when
    :func:`pyramid.traversal.find_resource` is called with an
    equivalent path string or tuple.

    .. warning:: This API is deprecated as of :app:`Pyramid` 1.0.
       Instead use the
       :meth:`pyramid.config.Configurator.testing_resources`
       method in your unit and integration tests.

    .. note:: For ancient backward compatibility purposes, this API can also
       be accessed as :func:`pyramid.testing.registerModels`.
    """
    registry = get_current_registry()
    config = Configurator(registry=registry)
    result = config.testing_resources(resources)
    config.commit()
    return result
开发者ID:jkrebs,项目名称:pyramid,代码行数:27,代码来源:testing.py

示例6: main

# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import commit [as 别名]
def main(global_config, **settings):  # pylint: disable=unused-argument
    """Main function of the application."""
    settings = dict(settings)
    settings.setdefault('jinja2.i18n.domain', 'pylf')

    config = Configurator(
        settings=settings,
    )
    config.add_translation_dirs('pylf:locale/')

    config.add_request_method(
        lambda request: request.registry.settings,
        "settings",
        property=True,
        reify=True,
    )

    config.add_static_view('static', 'static')
    config.commit()

    config.include(".auth")
    config.include(".i18n")
    config.include(".root")
    config.include(".mounts")
    config.include(".directory")
    config.include(".file")
    config.include(".util")
    config.include(".icons")

    return config.make_wsgi_app()
开发者ID:MarcSchmitzer,项目名称:pylf,代码行数:32,代码来源:__init__.py

示例7: get_registry

# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import commit [as 别名]
def get_registry(settings):
    registry = Registry('testing')
    config = Configurator(registry=registry)
    if getattr(registry, 'settings', None) is None:
        config._set_settings(settings)
    config.commit()
    return registry
开发者ID:Ushhud,项目名称:pyramid_swagger,代码行数:9,代码来源:response_test.py

示例8: main

# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import commit [as 别名]
def main(global_config, **local_config):
    """ This function returns a Pyramid WSGI application.
    """
    settings = global_config
    settings.update(local_config)

    # TODO: move to dcicutils
    set_logging(settings.get('elasticsearch.server'), settings.get('production'))

    # TODO - these need to be set for dummy app
    # settings['snovault.jsonld.namespaces'] = json_asset('snovault:schemas/namespaces.json')
    # settings['snovault.jsonld.terms_namespace'] = 'https://www.encodeproject.org/terms/'
    settings['snovault.jsonld.terms_prefix'] = 'snovault'

    config = Configurator(settings=settings)
    from snovault.elasticsearch import APP_FACTORY
    config.registry[APP_FACTORY] = main  # used by mp_indexer
    config.include(app_version)

    config.include('pyramid_multiauth')  # must be before calling set_authorization_policy
    from pyramid_localroles import LocalRolesAuthorizationPolicy
    # Override default authz policy set by pyramid_multiauth
    config.set_authorization_policy(LocalRolesAuthorizationPolicy())
    config.include(session)

    config.include(configure_dbsession)
    config.include('snovault')
    config.commit()  # commit so search can override listing

    # Render an HTML page to browsers and a JSON document for API clients
    config.include('snowflakes.renderers')
    # these two should be application specific
    config.include('.authentication')
    config.include('snowflakes.root')

    if 'elasticsearch.server' in config.registry.settings:
        config.include('snovault.elasticsearch')
        # needed for /search/?
        config.include('snowflakes.search')

    config.include(static_resources)
    config.include(changelogs)

    # TODO This is optional AWS only - possibly move to a plug-in
    aws_ip_ranges = json_from_path(settings.get('aws_ip_ranges_path'), {'prefixes': []})
    config.registry['aws_ipset'] = netaddr.IPSet(
        record['ip_prefix'] for record in aws_ip_ranges['prefixes'] if record['service'] == 'AMAZON')

    if asbool(settings.get('testing', False)):
        config.include('.tests.testing_views')

    # Load upgrades last so that all views (including testing views) are
    # registered.
    # TODO we would need a generic upgrade audit PACKAGE (__init__)
    # config.include('.audit)
    # config.include('.upgrade')

    app = config.make_wsgi_app()

    return app
开发者ID:j1z0,项目名称:snovault,代码行数:62,代码来源:__init__.py

示例9: folder

# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import commit [as 别名]
def folder(request):
    folder_path = request.POST.get('folder_path')
    recurse = request.POST.get('recurse', 0)

    found = []
    for root, dirs, files in os.walk(folder_path):
        for f in files:
            for ext in SUPPORTED_FILES:
                if f.endswith(ext):
                    full_path = os.path.join(root, f)
                    relative_path = full_path[len(folder_path):]

                    entry = ('http://127.0.0.1:6543/folder/%s' % relative_path,
                             full_path)

                    if recurse:
                        found.append(entry)
                    else:
                        if root == folder_path:
                            found.append(entry)

    #add a dynamic route to the content, (not thread safe!)
    config = Configurator(registry=request.registry)
    config.add_static_view('folder', folder_path, cache_max_age=3600)
    config.commit()

    return {'found': found,
            'folder_path': folder_path}
开发者ID:oscillot,项目名称:vdscrypter,代码行数:30,代码来源:folder.py

示例10: main

# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import commit [as 别名]
def main(init=True):
    import gevent.monkey
    gevent.monkey.patch_all()

    args = BackendCommand.parser.parse_args()

    # logging config
    def fileConfig(f, defaults):
        from logging.config import fileConfig
        return fileConfig(f, defaults, disable_existing_loggers = False)

    paster.setup_logging(args.config.split('#', 1)[0], fileConfig)

    # read settings
    parser = configparser.SafeConfigParser()
    parser.read((args.config,))
    settings = parser.items(configparser.DEFAULTSECT, vars={'here': './'})

    # run configuration
    config = Configurator(settings=settings)
    config.include('ptah')
    config.include('smxq')

    # ptah
    config.ptah_init_sql()
    config.ptah_init_settings()

    config.commit()

    # run command
    cmd = BackendCommand(args, config.registry, config)
    cmd.run()

    ptah.shutdown()
开发者ID:fafhrd91,项目名称:pyramid_smxq,代码行数:36,代码来源:start.py

示例11: make_app

# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import commit [as 别名]
 def make_app(self, settings=None, config=None):
     settings = self.get_app_settings(settings)
     config = Configurator(settings=settings)
     config.add_subscriber(self.listener, ServerFlushed)
     config.commit()
     return super(FlushViewTest, self).make_app(settings=settings,
                                                config=config)
开发者ID:tfroehlich82,项目名称:kinto,代码行数:9,代码来源:test_views_flush.py

示例12: main

# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import commit [as 别名]
def main(global_config, **settings):
    """ This is your application startup."""

    config = Configurator(settings=settings, session_factory=session_factory, authentication_policy=auth_policy)

    config.add_static_view("ptah_models", "ptah_models:static")

    # we love them routes
    config.add_route("root", "/")
    config.add_route("contact-us", "/contact-us.html")
    config.add_route("edit-links", "/links/{id}/edit", factory=models.factory, use_global_views=True)
    config.add_route("add-link", "/links/add.html")

    config.include("ptah")
    config.scan()

    # init ptah settings
    config.ptah_init_settings()

    # init sqlalchemy
    config.ptah_init_sql()

    # init ptah manage
    config.ptah_init_manage(managers=["*"], disable_modules=["rest", "introspect", "apps", "permissions", "settings"])

    config.commit()

    # Need to commit links to database manually.
    import transaction

    transaction.commit()

    return config.make_wsgi_app()
开发者ID:rainerwahnsinn,项目名称:examples,代码行数:35,代码来源:app.py

示例13: base_configure

# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import commit [as 别名]
def base_configure(global_config, **settings):
    """Resolve dotted names in settings, include plug-ins and create a
    Configurator.
    """
    from kotti.resources import appmaker

    for key, value in conf_defaults.items():
        settings.setdefault(key, value)

    for key, value in settings.items():
        if isinstance(settings[key], basestring):
            settings[key] = unicode(value, "utf8")

    # Allow extending packages to change 'settings' w/ Python:
    _resolve_dotted(settings, keys=("kotti.configurators",))
    for func in settings["kotti.configurators"]:
        func(settings)

    _resolve_dotted(settings)
    secret1 = settings["kotti.secret"]
    settings.setdefault("kotti.secret2", secret1)

    # BBB: Merge ``kotti.includes`` into pyramid.includes.
    if settings["kotti.includes"]:
        warnings.warn(
            "The 'kotti.includes' setting has been deprecated as of " "Kotti 0.6.1.  Use 'pyramid.includes' instead.",
            DeprecationWarning,
        )
        settings.setdefault("pyramid.includes", "")
        settings["pyramid.includes"] += " " + settings["kotti.includes"]

    # We'll process ``pyramid_includes`` later by hand, to allow
    # overrides of configuration from ``kotti.base_includes``:
    pyramid_includes = settings.pop("pyramid.includes", "")

    config = Configurator(settings=settings)
    config.begin()

    config.registry.settings["pyramid.includes"] = pyramid_includes

    # Include modules listed in 'kotti.base_includes':
    for module in settings["kotti.base_includes"]:
        config.include(module)
    config.commit()

    # Modules in 'pyramid.includes' may override 'kotti.base_includes':
    if pyramid_includes:
        for module in pyramid_includes.split():
            config.include(module)
    config.commit()

    engine = engine_from_config(settings, "sqlalchemy.")
    config._set_root_factory(appmaker(engine))

    # add the authenticated user to the request object
    from kotti.security import get_user

    config.set_request_property(get_user, name="user", reify=True)

    return config
开发者ID:Doik,项目名称:Kotti,代码行数:62,代码来源:__init__.py

示例14: main

# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import commit [as 别名]
def main(*args, **settings):
    """Initialize, and return a WSGI application."""
    logging.basicConfig(format="%(levelname)s:%(message)s", level=logging.WARNING)
    engine = engine_from_config(settings, "sqlalchemy.")
    DBSession.configure(bind=engine, expire_on_commit=False)
    settings = dict(settings)
    settings.setdefault("jinja2.i18n.domain", "arachcurator")

    authn_policy = AuthTktAuthenticationPolicy("sosecret", callback=groupfinder, hashalg="sha512")
    authz_policy = ACLAuthorizationPolicy()

    config = Configurator(settings=settings, root_factory=ROOTFACTORYSPEC)
    # config.add_translation_dirs('locale/')
    config.include("pyramid_jinja2")
    config.set_authentication_policy(authn_policy)
    config.set_authorization_policy(authz_policy)

    config.include(".models")
    config.include(".routes")
    config.scan()

    config.commit()

    jinja2_env = config.get_jinja2_environment()
    jinja2_env.filters["curie"] = field_curie

    return config.make_wsgi_app()
开发者ID:arachnolingua,项目名称:arachcurator,代码行数:29,代码来源:__init__.py

示例15: BaseEventTest

# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import commit [as 别名]
class BaseEventTest(BaseWebTest):

    subscribed = tuple()

    def setUp(self):
        super(BaseEventTest, self).setUp()
        self.events = []
        self.body = {'data': {'name': 'de Paris'}}

    def tearDown(self):
        self.events = []
        super(BaseEventTest, self).tearDown()

    def listener(self, event):
        self.events.append(event)

    def make_app(self, settings=None):
        settings = self.get_app_settings(settings)
        self.config = Configurator(settings=settings)
        for event_cls in self.subscribed:
            self.config.add_subscriber(self.listener, event_cls)
        self.config.commit()
        app = testapp(config=self.config)
        app = webtest.TestApp(app)
        app.RequestClass = get_request_class(self.api_prefix)
        return app
开发者ID:glasserc,项目名称:cliquet,代码行数:28,代码来源:test_events.py


注:本文中的pyramid.config.Configurator.commit方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。