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


Python Configurator.maybe_dotted方法代码示例

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


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

示例1: set_authorization_policy

# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import maybe_dotted [as 别名]
    def set_authorization_policy(config: Configurator, policy: Any) -> None:
        policy = config.maybe_dotted(policy)
        if isinstance(policy, INewAuthorizationPolicy):
            policy = AuthorizationPolicyWrapper(policy)

        # noinspection PyCallByClass
        SecurityConfiguratorMixin.set_authorization_policy(config, policy)
开发者ID:tetframework,项目名称:tet,代码行数:9,代码来源:authorization.py

示例2: main

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

    json_renderer = JSON()

    def datetime_adapter(obj, request):
        return obj.isoformat()

    json_renderer.add_adapter(datetime, datetime_adapter)
    config.add_renderer('json', json_renderer)

    config.include('pyramid_jinja2')
    config.include('.models')
    config.include('.routes')
    config.set_authentication_policy(MixedTokenAuthenticationPolicy())
    config.set_authorization_policy(
        AlwaysPassAuthenticatedAuthorizationPolicy()
    )

    enabled_registration_modules = settings.get(
        'pydiditpyramidgateway.enabled_registration_modules'
    )
    if enabled_registration_modules is not None:
        enabled_registration_modules = config.maybe_dotted(
            enabled_registration_modules.split(',')
        )
        for module in enabled_registration_modules:
            config.include(module)

    config.scan()
    pydiditbackend.initialize(json.loads(settings['backend_settings']))
    return config.make_wsgi_app()
开发者ID:adamlincoln,项目名称:PydiditPyramidGateway,代码行数:36,代码来源:__init__.py

示例3: main

# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import maybe_dotted [as 别名]
def main(global_config, **settings):
    """ This function returns a Pyramid WSGI application.
    """
    config = Configurator(root_factory=Root, settings=settings)
    config.add_static_view('static', 'pyramid_registration:static')
    backend_factory = settings.get('pyramid_registration.backend_factory',
                                   'pyramid_registration.mongodb.MongoDBRegistrationBackend')
    backend_factory = config.maybe_dotted(backend_factory)
    backend = backend_factory(settings, config)
    # Seems standard to keep "Registration" and "Login" separate, although
    # with external auth providers (e.g. Facebook) this isn't stricly necessary.
    # "Registration" is to create a new account.
    # "Login" is to exchange some credentials for a valid access token
    config.add_route('facebook_registration', '/registration/facebook',
            view=facebook_registration, factory=backend)
    config.add_route('facebook_login', '/login/facebook', view=facebook_login, factory=backend)
    config.add_route('simple_registration_post', '/registration/simple',
            view=simple_registration_post, factory=backend,
            renderer="pyramid_registration:templates/simple_reg.mak",
            request_method="POST")
    config.add_route('simple_registration_get', '/registration/simple',
            view=simple_registration_get, factory=backend,
            renderer="pyramid_registration:templates/simple_reg.mak",
            request_method="GET")
    config.add_route('simple_login_post', '/login/simple', view=simple_login_post,
            factory=backend, request_method="POST")
    config.add_route('simple_login_get', '/login/simple', view=simple_login_get,
            factory=backend, request_method="GET")
    # XXX _set_authentication_policy will be made public as
    # set_authentication_policy soon.
    config._set_authentication_policy(PyramidRegistrationAuthenticationPolicy(backend))

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

示例4: get_engine_factory

# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import maybe_dotted [as 别名]
    def get_engine_factory(self, request, filename=False):
        """Return engine factory (class) for request.

        If ``filename`` is ``True`` (defaults to ``False``),
        then return the engine to render filenames. It may differ from the
        engine to render files.

        """
        # Try engine from request's GET.
        try:
            engine_slug = request.GET['engine']
        except KeyError:
            engine_type = 'diecutter.filename_engine' if filename \
                else 'diecutter.engine'
            engine_slug = request.registry.settings[engine_type]
        if not hasattr(request, 'cache'):
            request.cache = {}
        if filename:
            request.cache['diecutter_filename_engine_slug'] = engine_slug
        else:
            request.cache['diecutter_engine_slug'] = engine_slug
        try:
            engine_path_setting = 'diecutter.engine.{0}'.format(engine_slug)
            engine_path = request.registry.settings[engine_path_setting]
        except KeyError:
            raise HTTPNotAcceptable(
                'Supported template engines: %s'
                % ', '.join(sorted(supported_engines(request))))
        config = Configurator(request.registry.settings)
        engine_factory = config.maybe_dotted(engine_path)
        return engine_factory
开发者ID:diecutter,项目名称:diecutter,代码行数:33,代码来源:service.py

示例5: main

# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import maybe_dotted [as 别名]
def main(global_config, **settings):
    """ This function returns a Pyramid WSGI application.
    """
    engine = engine_from_config(settings, 'sqlalchemy.')
    initialize_sql(engine)
    config = Configurator(settings=settings)
    config.add_static_view('static', 'pyramidapp:static')
    config.add_route('home', '/', view='pyramidapp.views.my_view',
                     view_renderer='templates/mytemplate.pt')
    config.load_zcml('formalchemy:configure.zcml')
    config.add_route('fa_admin', '/admin/*traverse',
                     factory='formalchemy.ext.pyramid.admin.AdminView')
    config.registry.settings.update({
        'fa.models': config.maybe_dotted('pyramidapp.models'),
        'fa.forms': config.maybe_dotted('pyramidapp.forms'),
        'fa.session_factory': config.maybe_dotted('pyramidapp.models.DBSession'),
        })

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

示例6: add_command

# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import maybe_dotted [as 别名]
def add_command(config: Configurator, command: Union[str, click.Command]):
    """
    Add command.

    :param config: Configurator
    :param command: Command dotted path or Command object
    :param name:  Command name
    """
    command = config.maybe_dotted(command)

    cli = config.registry.getUtility(ICli)  # type: Cli
    cli.add_command(command)
开发者ID:antonrh,项目名称:pyramid_cli,代码行数:14,代码来源:__init__.py

示例7: get_resource

# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import maybe_dotted [as 别名]
def get_resource(request):
    """Return the resource matching request.

    Return value is a :py:class:`FileResource` or :py:class`DirResource`.

    """
    path = get_resource_path(request)
    settings = request.registry.settings
    config = Configurator(settings)

    engine = config.maybe_dotted(settings['diecutter.template_engine'])()
    filename_engine = config.maybe_dotted(
        settings['diecutter.filename_template_engine'])()

    if isdir(path):
        resource = resources.DirResource(path=path, engine=engine,
                                         filename_engine=filename_engine)
    else:
        resource = resources.FileResource(path=path, engine=engine,
                                          filename_engine=filename_engine)
    return resource
开发者ID:palkeo,项目名称:diecutter,代码行数:23,代码来源:views.py

示例8: main

# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import maybe_dotted [as 别名]
def main(global_config, **settings):
    Service.cors_origins = ('*',)

    config = Configurator(settings=settings)
    config.include("cornice")
    config.scan("daybed.views")

    # backend initialisation
    backend = config.maybe_dotted(settings['daybed.backend'])
    config.registry.backend = backend(config)

    config.add_renderer('jsonp', JSONP(param_name='callback'))
    return config.make_wsgi_app()
开发者ID:numahell,项目名称:daybed,代码行数:15,代码来源:__init__.py

示例9: main

# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import maybe_dotted [as 别名]
def main(global_config, **settings):
    """ This function returns a Pyramid WSGI application.
    """
    config = Configurator(settings=settings)
    config.include('.models')
    config.add_static_view('static', 'static', cache_max_age=3600)
    config.include('.views')
    config.include('.api')

    config.add_request_method(request_hashfs, 'hashfs', reify=True)
    AuthorizedUser = config.maybe_dotted('.models.AuthorizedUser')
    authn_policy = AuthTktAuthenticationPolicy(
        secret=settings['authtkt_secret'], hashalg='sha512', callback=AuthorizedUser.check)
    authz_policy = ACLAuthorizationPolicy()
    config.set_authentication_policy(authn_policy)
    config.set_authorization_policy(authz_policy)

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

示例10: setup_configuration

# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import maybe_dotted [as 别名]
def setup_configuration(settings):
    config = Configurator(settings=settings)
    backend_class = config.maybe_dotted(settings["addonreg.backend"])
    backend = backend_class(settings)

    if settings.get("populate_backend"):
        logger.info("Populating the database")
        populate_backend(backend)

    def _add_backend_to_request(event):
        event.request.backend = backend

    # Attach the backend to each request and put it in the registry.
    config.add_subscriber(_add_backend_to_request, NewRequest)
    config.registry.backend = backend

    app = app_or_default()
    app.registry = config.registry
    return config
开发者ID:jasonthomas,项目名称:addon-registration,代码行数:21,代码来源:__init__.py

示例11: main

# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import maybe_dotted [as 别名]
def main(global_config, **settings):
    """ This function returns a Pyramid WSGI application. """
    create_dir(settings['convertit.converted_path'])
    create_dir(settings['convertit.downloads_path'])

    config = Configurator(settings=settings)

    config.registry.convertit = {}

    for namespace in settings['convertit.converters'].split():
        package = config.maybe_dotted(namespace)
        config.registry.convertit.update(package.converters())

    config.add_static_view('static', 'static', cache_max_age=3600)
    config.add_static_view(settings['convertit.converted_url'],
                           settings['convertit.converted_path'],
                           cache_max_age=3600)

    config.add_route('home', '/')

    config.scan(ignore='convertit.tests')
    return config.make_wsgi_app()
开发者ID:D3f0,项目名称:convertit,代码行数:24,代码来源:__init__.py

示例12: main

# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import maybe_dotted [as 别名]
def main(global_config, **settings):
    # We need to disable cornice's exception handling views
    settings.setdefault("handle_exceptions", False)

    config = Configurator(settings=settings)
    config.include("pyramid_hawkauth")
    config.include("cornice")
    config.include("pyramid_jinja2")
    config.add_jinja2_search_path("pants:templates")

    config.scan("pants.views")

    token_manager = TokenManager(secret=settings['token-secret'])
    config.registry.token_manager = token_manager

    backend_class = config.maybe_dotted(settings['storage'])
    config.registry.storage = storage = backend_class(config)

    def attach_services_to_request(event):
        event.request.token_manager = token_manager
        event.request.storage = storage
    config.add_subscriber(attach_services_to_request, NewRequest)

    return config.make_wsgi_app()
开发者ID:almet,项目名称:pants-server,代码行数:26,代码来源:__init__.py

示例13: main

# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import maybe_dotted [as 别名]
def main(global_config, **settings):
    """ This function returns a Pyramid WSGI application.
    """
    config = Configurator(settings=settings)
    config.hook_zca()
    config.include('pyramid_zcml')
    config.load_zcml('pysiphae:configure.zcml')
    config.include('pyramid_chameleon')
    config.include('pyramid_viewgroup')

    sessionfactory = SignedCookieSessionFactory(uuid.uuid4().hex)

    config.set_session_factory(sessionfactory)

    pconfig = yaml.load(
            open(settings.get('pysiphae.config')).read())
    config.registry.settings['pysiphae'] = pconfig
    default_permission = pconfig.get('default_permission', None)
    if default_permission:
        config.set_default_permission(default_permission)
    config.set_root_factory(root_factory)

    # register process managers
    processmgrs = pconfig.get('processmanagers', [])
    if not processmgrs:
        processmgrs.append({'name': 'defaut', 
                            'address': 'http://localhost:8888'})

    for pm in processmgrs:
        name = pm['name']
        address = pm['address']
        if name == 'default':
            config.registry.registerUtility(ProcessManager(address))
        else:
            config.registry.registerUtility(ProcessManager(address), name=name)

    # viewgroups
    for vg in pconfig.get('viewgroups', []):
        vg['context'] = vg.get('context', 'pysiphae.interfaces.ISiteRoot')
        config.add_viewgroup(**vg)

    config.add_static_view('++static++', 'static', cache_max_age=3600)
    config.add_request_method(requestmethods.main_template, 'main_template', reify=True)
    config.add_request_method(requestmethods.vars, 'template_vars', property=True)
    config.add_request_method(requestmethods.main_navigation, 'main_navigation',
            property=True)
    config.add_request_method(requestmethods.viewgroup_provider, 'provider',
            property=True)
    config.add_request_method(requestmethods.pconfig, 'pconfig', property=True)
    config.add_route('home','/')
    config.add_route('login','/login')
    config.add_route('logout','/logout')
    config.scan()

    plugins = pconfig.get('plugins', [])
    for plugin in plugins:
        package = config.maybe_dotted(plugin)
        if getattr(package, 'configure', None):
            package.configure(config, settings)
        config.load_zcml(plugin + ':configure.zcml')
        config.scan(plugin)

    return config.make_wsgi_app()
开发者ID:koslab,项目名称:pysiphae,代码行数:65,代码来源:wsgi.py

示例14: main

# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import maybe_dotted [as 别名]
def main(global_config, **settings):
    Service.cors_origins = ("*",)

    settings = settings_expandvars(settings)
    config = Configurator(settings=settings, root_factory=RootFactory)
    config.include("cornice")

    # Redirect to the current version of the API if the prefix isn't used.
    config.add_route(name="redirect_to_version", pattern="/{path:(?!%s).*}" % API_VERSION)
    config.add_view(view=redirect_to_version, route_name="redirect_to_version")

    config.route_prefix = "/%s" % API_VERSION

    # Permission management

    policies = [
        BasicAuthAuthenticationPolicy(check_credentials),
        HawkAuthenticationPolicy(decode_hawk_id=get_credentials),
    ]
    authn_policy = MultiAuthenticationPolicy(policies)

    # Unauthorized view
    config.add_forbidden_view(forbidden_view)

    # Global permissions
    model_creators = settings.get("daybed.can_create_model", "Everyone")
    token_creators = settings.get("daybed.can_create_token", "Everyone")
    token_managers = settings.get("daybed.can_manage_token", None)

    authz_policy = DaybedAuthorizationPolicy(
        model_creators=build_list(model_creators),
        token_creators=build_list(token_creators),
        token_managers=build_list(token_managers),
    )
    config.set_authentication_policy(authn_policy)
    config.set_authorization_policy(authz_policy)

    # We need to scan AFTER setting the authn / authz policies
    config.scan("daybed.views")

    # Attach the token to the request, coming from Pyramid as userid
    def get_credentials_id(request):
        try:
            credentials_id, _ = get_credentials(request, request.authenticated_userid)
            return credentials_id
        except ValueError:
            return None

    config.add_request_method(get_credentials_id, "credentials_id", reify=True)

    # Events

    # Helper for notifying events
    def notify(request, event, *args):
        klass = config.maybe_dotted("daybed.events." + event)
        event = klass(*(args + (request,)))
        request.registry.notify(event)

    config.add_request_method(notify, "notify")

    # Backend

    config.registry.tokenHmacKey = settings["daybed.tokenHmacKey"]

    # backend initialisation
    backend_class = config.maybe_dotted(settings["daybed.backend"])
    config.registry.backend = backend_class.load_from_config(config)

    # Indexing

    # Connect client to hosts in conf
    index_hosts = build_list(settings.get("elasticsearch.hosts", "localhost:9200"))
    indices_prefix = settings.get("elasticsearch.indices_prefix", "daybed_")
    config.registry.index = index = indexer.ElasticSearchIndexer(index_hosts, indices_prefix)

    # Suscribe index methods to API events
    config.add_subscriber(index.on_model_created, events.ModelCreated)
    config.add_subscriber(index.on_model_updated, events.ModelUpdated)
    config.add_subscriber(index.on_model_deleted, events.ModelDeleted)
    config.add_subscriber(index.on_record_created, events.RecordCreated)
    config.add_subscriber(index.on_record_updated, events.RecordUpdated)
    config.add_subscriber(index.on_record_deleted, events.RecordDeleted)

    # Renderers

    # Force default accept header to JSON
    def add_default_accept(event):
        json_mime = "application/json"
        accept = event.request.headers.get("Accept", json_mime)
        if json_mime in accept:
            accept = json_mime
        event.request.headers["Accept"] = accept

    config.add_subscriber(add_default_accept, NewRequest)

    # JSONP
    config.add_renderer("jsonp", JSONP(param_name="callback"))

    # Geographic data renderer
    config.add_renderer("geojson", GeoJSON())
#.........这里部分代码省略.........
开发者ID:chid,项目名称:daybed,代码行数:103,代码来源:__init__.py

示例15: main

# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import maybe_dotted [as 别名]
def main(global_config, **settings):
    Service.cors_origins = ('*',)

    config = Configurator(settings=settings, root_factory=RootFactory)
    config.include("cornice")
    config.include('pyramid_mako')

    # ACL management

    # Persona authentication
    secret = settings.get('persona.secret', None)

    policies = [
        BasicAuthAuthenticationPolicy(check_api_token),
        AuthTktAuthenticationPolicy(secret, hashalg='sha512',
                                    callback=build_user_principals)
    ]
    authn_policy = MultiAuthenticationPolicy(policies)

    session_factory = UnencryptedCookieSessionFactoryConfig(secret)
    config.set_session_factory(session_factory)

    verifier_factory = config.maybe_dotted(
        settings.get('persona.verifier', 'browserid.RemoteVerifier'))
    audiences = aslist(settings['persona.audiences'])
    config.registry['persona.verifier'] = verifier_factory(audiences)

    # Parameters for the request API call
    request_params = {}
    for option in ('privacyPolicy', 'siteLogo', 'siteName', 'termsOfService',
                   'backgroundColor'):
        setting_name = 'persona.%s' % option
        if setting_name in settings:
            request_params[option] = settings[setting_name]
    config.registry['persona.request_params'] = json.dumps(request_params)

    # Login and logout views.
    config.add_route('persona', '/persona')
    config.add_view(home, route_name='persona', renderer='home.mako')

    login_route = settings.get('persona.login_route', 'login')
    config.registry['persona.login_route'] = login_route
    login_path = settings.get('persona.login_path', '/login')
    config.add_route(login_route, login_path)
    config.add_view(login, route_name=login_route, check_csrf=True,
                    renderer='json', permission=NO_PERMISSION_REQUIRED)

    logout_route = settings.get('persona.logout_route', 'logout')
    config.registry['persona.logout_route'] = logout_route
    logout_path = settings.get('persona.logout_path', '/logout')
    config.add_route(logout_route, logout_path)
    config.add_view(logout, route_name=logout_route, check_csrf=True,
                    renderer='json',
                    permission=NO_PERMISSION_REQUIRED)

    config.add_request_method(button, 'persona_button', reify=True)
    config.add_request_method(js, 'persona_js', reify=True)

    # Unauthorized view
    config.add_forbidden_view(unauthorized_view)

    # Authorization policy
    authz_policy = DaybedAuthorizationPolicy()
    config.set_authentication_policy(authn_policy)
    config.set_authorization_policy(authz_policy)
    config.add_request_method(get_user, 'user', reify=True)

    # We need to scan AFTER setting the authn / authz policies
    config.scan("daybed.views")

    # backend initialisation
    backend_class = config.maybe_dotted(settings['daybed.backend'])
    config.registry.backend = backend = backend_class(config)

    def add_db_to_request(event):
        event.request.db = config.registry.backend.db()
    config.add_subscriber(add_db_to_request, NewRequest)

    config.add_renderer('jsonp', JSONP(param_name='callback'))

    # Here, define the default users / policies etc.
    database = backend.db()
    for name, policy in [('read-only', POLICY_READONLY),
                         ('anonymous', POLICY_ANONYMOUS),
                         ('admin-only', POLICY_ADMINONLY)]:
        try:
            database.set_policy(name, policy)
        except PolicyAlreadyExist:
            pass

    config.registry.default_policy = settings.get('daybed.default_policy',
                                                  'read-only')

    config.add_renderer('geojson', GeoJSON())
    return config.make_wsgi_app()
开发者ID:n1k0,项目名称:daybed,代码行数:97,代码来源:__init__.py


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