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


Python Configurator.set_root_factory方法代码示例

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


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

示例1: create_app

# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import set_root_factory [as 别名]
def create_app(global_config, **settings):
    """Configure and add static routes and views. Return the WSGI app."""
    settings = get_settings(global_config, **settings)

    config = Configurator(settings=settings)

    config.set_root_factory('h.resources.create_root')

    config.add_subscriber('h.subscribers.add_renderer_globals',
                          'pyramid.events.BeforeRender')
    config.add_subscriber('h.subscribers.set_user_from_oauth',
                          'pyramid.events.NewRequest')

    config.add_tween('h.tweens.csrf_tween_factory')
    config.add_tween('h.tweens.auth_token')

    config.include(__name__)

    app = config.make_wsgi_app()
    app = permit_cors(app,
                      allow_headers=(
                          'Authorization',
                          'Content-Type',
                          'X-Annotator-Auth-Token',
                          'X-Client-Id',
                      ),
                      allow_methods=('HEAD', 'GET', 'POST', 'PUT', 'DELETE'))

    return app
开发者ID:stuk88,项目名称:h,代码行数:31,代码来源:app.py

示例2: main

# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import set_root_factory [as 别名]
def main(global_config, **settings):
    """ This function returns a Pyramid WSGI application.
    """
    config = Configurator(settings=settings)
    config.include('s4u.sqlalchemy')
    config.include('s4u.image')
    config.set_root_factory(DefaultRoot)
    config.set_authentication_policy(
            AuthTktAuthenticationPolicy('photoshare',
                include_ip=False,
                max_age=60 * 60 * 24 * 7,
                timeout=60 * 60 * 24 * 7,
                reissue_time=60 * 60 * 24,
                http_only=True))
    config.set_authorization_policy(
            ACLAuthorizationPolicy())
    config.add_static_view('static', 'static', cache_max_age=3600)
    config.add_route('home', '/')
    config.add_route('login', '/login')
    config.add_route('upload', '/upload')
    config.add_route('browse', '/browse')
    config.add_route('browse-user', '/browse/{id:\d+}',
            factory=user_factory)
    config.add_route('download-user', '/browse/{id:\d+}/download',
            factory=user_factory)
    config.add_route('download-photo', '/api/photo/{id:\d+}/download',
            factory=photo_factory)
    config.add_route('delete-photo', '/api/photo/{id:\d+}/delete',
            factory=photo_factory)
    config.scan()
    return config.make_wsgi_app()
开发者ID:wichert,项目名称:photoshare,代码行数:33,代码来源:__init__.py

示例3: main

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

    config.include('pyramid_mako')

    # create the model based on the .ini
    engine = engine_from_config(configuration=settings, prefix='sqlalchemy.')
    bind_engine(engine, create_all=True)

    # add current authenticated user as request.user
    config.add_request_method(request_user, 'user', reify=True)

    # get auth kwargs from .ini file
    auth_cfg = {k[5:]: v for k, v in settings.items() if k.startswith('auth.')}

    # set authentication policy from auth_app.auth:authn_policy()
    authentication_policy = authn_policy(callback=auth_callback, **auth_cfg)
    config.set_authentication_policy(authentication_policy)

    # set authorization policy from auth_app.auth:authz_policy()
    authorization_policy = authz_policy()
    config.set_authorization_policy(authorization_policy)

    # set the root factory w/ __acl__ permissions
    config.set_root_factory(RootFactory)

    config.add_route('index', '/')
    config.add_route('home', '/home')
    config.add_route('login', '/login')
    config.add_route('logout', '/logout')
    config.scan()

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

示例4: main

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

    engine = engine_from_config(settings, "sqlalchemy.")
    db.DBSession.configure(bind=engine)
    db.Base.metadata.bind = engine

    config = Configurator(settings=settings)
    config.set_root_factory(RootFactory)
    config.set_default_permission("all")

    config.include("pyramid_jwtauth")

    config.add_route("home", "/")
    config.add_route("states", "/states/")

    config.add_route("auth.register", "/auth/register/")
    config.add_route("auth.login", "/auth/login/")
    config.add_route("auth.logout", "/auth/logout/")

    config.add_route("girias", "/girias/")

    config.scan()
    return config.make_wsgi_app()
开发者ID:marioidival,项目名称:giriapedia,代码行数:28,代码来源:__init__.py

示例5: create_api

# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import set_root_factory [as 别名]
def create_api(global_config, **settings):
    settings = get_settings(global_config, **settings)

    config = Configurator(settings=settings)

    config.set_authentication_policy(remote_authn)
    config.set_authorization_policy(acl_authz)
    config.set_root_factory('h.api.resources.create_root')

    config.add_renderer('json', JSON(indent=4))
    config.add_subscriber('h.api.subscribers.set_user_from_oauth',
                          'pyramid.events.ContextFound')
    config.add_tween('h.api.tweens.auth_token')

    config.include('h.features')

    config.include('h.auth')
    config.include('h.api.db')
    config.include('h.api.views')

    if config.registry.feature('queue'):
        config.include('h.queue')
        config.include('h.api.queue')

    app = config.make_wsgi_app()
    app = permit_cors(app,
                      allow_headers=('Authorization',
                                     'X-Annotator-Auth-Token'),
                      allow_methods=('HEAD', 'GET', 'POST', 'PUT', 'DELETE'))

    return app
开发者ID:juli-so,项目名称:h,代码行数:33,代码来源:app.py

示例6: create_api

# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import set_root_factory [as 别名]
def create_api(global_config, **settings):
    settings = get_settings(global_config, **settings)

    config = Configurator(settings=settings)

    config.set_authentication_policy(remote_authn)
    config.set_authorization_policy(acl_authz)
    config.set_root_factory('h.api.resources.create_root')

    config.add_renderer('json', JSON(indent=4))
    config.add_subscriber('h.api.subscribers.set_user_from_oauth',
                          'pyramid.events.ContextFound')
    config.add_tween('h.api.tweens.auth_token')

    config.include('h.features')

    config.include('h.auth')
    config.include('h.api.db')
    config.include('h.api.views')

    if config.registry.feature('queue'):
        config.include('h.queue')
        config.include('h.api.queue')

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

示例7: main

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

    backends.Servers = backends.ServerList(settings['sqlalchemy.urls'])

    #MySession.configure(bind=mysql_engine)
    #MyBase.metadata.bind = mysql_engine
    #Base.metadata.create_all(engine)

    #e("show tables").fetchall()

    config = Configurator(settings=settings)
    config.set_root_factory(get_root)
    my_session_factory = SignedCookieSessionFactory('itsaseekreet')
    config.set_session_factory(my_session_factory)
    config.set_request_factory(CustomRequest)


    config.include('pyramid_chameleon')

    config.add_static_view('static', 'static', cache_max_age=3600)
    #config.add_route('home', '/')
    #config.add_route('left_menu', '/')
    config.scan()
    return config.make_wsgi_app()
开发者ID:kalkehcoisa,项目名称:pharao,代码行数:28,代码来源:__init__.py

示例8: main

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

    authn_policy = AuthTktAuthenticationPolicy(
        settings['auth.secret'],
        callback=groupfinder,
    )
    authz_policy = ACLAuthorizationPolicy()

    config.set_authentication_policy(authn_policy)
    config.set_authorization_policy(authz_policy)
    config.set_root_factory(Root)

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

    config.add_route('users', '/users')
    config.add_route('user', '/user/{login}')

    config.add_route('pages', '/pages')
    config.add_route('create_page', '/create_page')
    config.add_route('page', '/page/{title}')
    config.add_route('edit_page', '/page/{title}/edit')

    config.include('pyramid_mako')
    config.scan(__name__)
    return config.make_wsgi_app()
开发者ID:mmerickel,项目名称:pyramid_auth_demo,代码行数:30,代码来源:demo.py

示例9: main

# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import set_root_factory [as 别名]
def main(global_config, **settings):
    """ This function returns a Pyramid WSGI application."""
    my_session_factory = SignedCookieSessionFactory('itsaseekreet', timeout=None)
    my_authentication_policy = SessionAuthenticationPolicy(callback=groupfinder, debug=False)
    my_authorization_policy = ACLAuthorizationPolicy()
    
    config = Configurator(settings=settings)
    config.set_root_factory(Root)
    config.set_session_factory(my_session_factory)
    config.set_authentication_policy(my_authentication_policy)
    config.set_authorization_policy(my_authorization_policy)

    # add mongo db
    config.add_subscriber(add_mongo_db, NewRequest)
    # add cors headers
    config.add_subscriber(add_cors_headers_response_callback, NewRequest)
    # add csrf token header
    config.add_subscriber(add_csrf_token_header, NewRequest)
    # add toaster notification header
    config.add_subscriber(add_toaster_notification_header, NewRequest)

    # override default json renderer
    config.add_renderer('json', MongoJSONRenderer) 

    config.add_route('options', '/*foo', request_method='OPTIONS') # matches any path OPTIONS method
    config.add_route('login', '/login')
    config.add_route('logout', '/logout')
    config.add_route('auth', '/auth')
    config.add_route('search', '/search')
    config.scan()
    return config.make_wsgi_app()
开发者ID:T0MASD,项目名称:keel,代码行数:33,代码来源:__init__.py

示例10: main

# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import set_root_factory [as 别名]
def main(global_config, **settings):  # pragma: no cover
    """ This function returns a Pyramid WSGI application.
    """
    engine = engine_from_config(settings, 'sqlalchemy.')
    DBSession.configure(bind=engine)
    Base.metadata.bind = engine
    session_factory = session_factory_from_settings(settings)
    config = Configurator(settings=settings)
    config.set_session_factory(session_factory)
    config.set_root_factory(RootFactory)
    config.set_request_property(remote_addr)
    config.add_request_method(tagged_static_path)
    config.include(pyramid_jinja2)

    # Redis setup.
    redis_conn = redis.StrictRedis.from_url(settings['redis.url'])
    config.registry.settings['redis_conn'] = redis_conn
    def _add_redis(event):
        settings = event.request.registry.settings
        event.request.redis = settings['redis_conn']
    config.add_subscriber(_add_redis, NewRequest)

    jinja2_env = config.get_jinja2_environment()
    jinja2_env.filters['datetime'] = format_datetime
    jinja2_env.filters['formatpost'] = format_post
    jinja2_env.filters['isotime'] = format_isotime
    jinja2_env.filters['markdown'] = format_markdown
    jinja2_env.filters['markup'] = format_text

    config.add_static_view('static', path='static', cache_max_age=3600)
    config.scan()
    return config.make_wsgi_app()
开发者ID:nat3738,项目名称:fanboi2,代码行数:34,代码来源:__init__.py

示例11: main

# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import set_root_factory [as 别名]
def main(global_config, **settings):
    """ This function returns a Pyramid WSGI application.
    """
    settings['sqlalchemy.url'] = settings['cn.dialect'] + quote_plus(settings['sqlalchemy.url'])
    engine = engine_from_config(settings, 'sqlalchemy.')
    dbConfig['url'] = settings['sqlalchemy.url']

    """ Configuration de la connexion à la BDD """
    # DBSession.configure(bind=engine)
    Base.metadata.bind = engine
    Base.metadata.create_all(engine)
    Base.metadata.reflect(views=True)

    """ Configuration du serveur pyramid"""
    config = Configurator(settings=settings)
    # Add renderer for datetime objects
    json_renderer = JSON()
    json_renderer.add_adapter(datetime, datetime_adapter)
    json_renderer.add_adapter(date, date_adapter)
    json_renderer.add_adapter(Decimal, decimal_adapter)
    json_renderer.add_adapter(bytes, bytes_adapter)
    config.add_renderer('json', json_renderer)
    config.registry.dbmaker = scoped_session(sessionmaker(bind=engine))
    config.add_request_method(db, name='dbsession', reify=True)
    # Set up authentication and authorization

    config.set_root_factory(SecurityRoot)
    config.add_subscriber(add_cors_headers_response_callback, NewRequest)

    # Set the default permission level to 'read'
    config.set_default_permission('read')
    config.include('pyramid_tm')
    add_routes(config)
    config.scan()
    return config.make_wsgi_app()
开发者ID:NaturalSolutions,项目名称:notification,代码行数:37,代码来源:__init__.py

示例12: main

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

    # Configure SQLAlchemy
    engine = engine_from_config(settings, 'sqlalchemy.')
    DBSession.configure(bind=engine)
    Base.metadata.bind = engine

    # Configure ElasticSearch
    configure_es_from_config(settings)

    config = Configurator(settings=settings)
    config.include('cornice')
    config.registry.queue_config = get_queue_config(settings)

    bypass_auth = False
    if 'noauthorization' in settings:
        bypass_auth = asbool(settings['noauthorization'])

    if not bypass_auth:
        config.include("pyramid_jwtauth")
        # Intercept request handling to validate token against the database
        config.add_tween('c2corg_api.jwt_database_validation_tween_factory')
        # Inject ACLs
        config.set_root_factory(RootFactory)
    else:
        log.warning('Bypassing authorization')

    # Scan MUST be the last call otherwise ACLs will not be set
    # and the permissions would be bypassed
    config.scan(ignore='c2corg_api.tests')
    return config.make_wsgi_app()
开发者ID:arnaud-morvan,项目名称:v6_api,代码行数:35,代码来源:__init__.py

示例13: main

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

    db = get_couchdb(settings['couchdb.db'], settings['couchdb.uri'])
    view_registry.sync(db)

    def get_db(request):
        return db

    config.add_request_method(get_db, 'db', reify=True)

    def get_user_object(request):
        userid = unauthenticated_userid(request)
        if userid is not None:
            return get_user(db, userid)

    config.add_request_method(get_user_object, 'user', reify=True)

    config.set_root_factory(Root)

    def check_password(username, password, request):
        user = request.user
        if user and user.check_password(password):
            # Return list of principals (other than username).
            return []
        return None
    config.set_authentication_policy(
        BasicAuthAuthenticationPolicy(check_password))
    config.set_authorization_policy(ACLAuthorizationPolicy())

    config.include("cornice")
    config.scan(".views")
    return config.make_wsgi_app()
开发者ID:sbrauer,项目名称:cornice_couch_demo,代码行数:35,代码来源:__init__.py

示例14: main

# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import set_root_factory [as 别名]
def main(global_config, **settings):
    """ This function returns a Pyramid WSGI application.
    """
    authentication_policy = AuthenticationPolicy(
        settings['auth.secret'], cookie_name='shike.im')
    authorization_policy = ACLAuthorizationPolicy() 
    config = Configurator(settings=settings)
    config.set_root_factory('hzsxactivitymanagesite.resources.RootFactory')
    config.set_authentication_policy(authentication_policy)
    config.set_authorization_policy(authorization_policy)
    
    jsonp = JSONP(param_name='callback')
    jsonp.add_adapter(ObjectId, objectid_adapter)
    jsonp.add_adapter(DBRef, dbref_adapter)
    jsonp.add_adapter(datetime.datetime, datetime_adapter)
    config.add_renderer('jsonp', jsonp)
    config.add_subscriber(real_ip_hook, NewRequest)
    config.set_request_property(get_db, "db", reify=True)
    config.set_request_property(get_fs, "fs", reify=True)
    config.set_request_property(get_user, "user", reify=True)
    
    config.add_static_view('static', 'static', cache_max_age=3600)
    config.include("hzsxactivitymanagesite.views.home")
    config.add_forbidden_view("hzsxactivitymanagesite.views.forbidden_view",  renderer="json")
    config.add_notfound_view("hzsxactivitymanagesite.views.notfound_view", renderer="json")
    config.add_view("hzsxactivitymanagesite.views.apierror_view", context='hzsxactivitymanagesite.exceptions.APIError', renderer='json')
    config.add_view("hzsxactivitymanagesite.views.pageerror_view", context='hzsxactivitymanagesite.exceptions.PageError', renderer='error.mako')
    return config.make_wsgi_app()
开发者ID:Jonekee,项目名称:bigscreen,代码行数:30,代码来源:__init__.py

示例15: main

# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import set_root_factory [as 别名]
def main(global_config, **settings):
    """ This function returns a Pyramid WSGI application.
    """
    settings['sqlalchemy.url'] = settings['cn.dialect'] + quote_plus(settings['sqlalchemy.url'])
    engine = engine_from_config(settings, 'sqlalchemy.')
    dbConfig['url'] = settings['sqlalchemy.url']
    DBSession.configure(bind=engine)
    Base.metadata.bind = engine
    Base.metadata.create_all(engine)
    Base.metadata.reflect(views=True, extend_existing=False)

    config = Configurator(settings=settings)
    # Add renderer for datetime objects
    json_renderer = JSON()
    json_renderer.add_adapter(datetime, datetime_adapter)
    json_renderer.add_adapter(Decimal, decimal_adapter)
    config.add_renderer('json', json_renderer)

    # Set up authentication and authorization
    includeme(config)
    config.set_root_factory(SecurityRoot)


    # Set the default permission level to 'read'
    config.set_default_permission('read')
    config.include('pyramid_tm')
    add_routes(config)
    config.scan()
    return config.make_wsgi_app()
开发者ID:gerald13,项目名称:NsPortal,代码行数:31,代码来源:__init__.py


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