• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python compat.register函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中psycopg2cffi.compat.register函数的典型用法代码示例。如果您正苦于以下问题:Python register函数的具体用法?Python register怎么用?Python register使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: boostrap_from_config

def boostrap_from_config(config_file_name):
    """
    just a small wrapper that does the same as uwsgi with the ``*.ini`` file, via ``setup.py``
    take the given filename, bootstrap an app and configure lgging for it

    see http://stackoverflow.com/a/19058365

    :param config_file_name:
    :return:
    """
    assert config_file_name is not None
    if not os.path.exists(config_file_name):
        raise RuntimeError('file does not exist: %s' % config_file_name)
    config_file_name = os.path.realpath(config_file_name)

    # monkeypatching psycopg2 compatibility
    # https://github.com/chtd/psycopg2cffi
    from psycopg2cffi import compat
    compat.register()

    # dont use paste, but pyramid to also configure logging http://stackoverflow.com/a/19058365
    # from paste.deploy import loadapp
    # loadapp("config:%s" % config_file)
    pyramid.paster.setup_logging(config_file_name)
    app = pyramid.paster.get_app(config_file_name)

    log.debug('used configfile: %s', config_file_name)
    return app
开发者ID:pansen,项目名称:gonzales,代码行数:28,代码来源:__init__.py


示例2: hack_psycopg2cffi

def hack_psycopg2cffi():  # pragma: nocover
    try:
        from psycopg2cffi import compat
    except ImportError:
        pass
    else:
        compat.register()
    finally:
        import psycopg2
    return
开发者ID:unit9,项目名称:boilerplate-python,代码行数:10,代码来源:hacks.py


示例3: make_wsgi_application

def make_wsgi_application(global_config, **local_conf):
    """
    generic function to create a wsgi application out of a given paster config

    :param global_config:
    :param local_conf:
    :return:
    """

    # monkeypatching psycopg2 compatibility
    # https://github.com/chtd/psycopg2cffi
    from psycopg2cffi import compat
    compat.register()

    # Do something before importing Django and your settings have been applied.
    if global_config['__file__'] not in __apps_by_ini_configuration__:
        log.debug('create django wsgi app from ini-file %s...', global_config['__file__'])
        app = get_configured_django_wsgi_app(global_config, **local_conf)

        # Do something right after your application has been set up (e.g., add WSGI middleware).
        # http://rhodesmill.org/brandon/2011/wsgi-under-cherrypy/

        # non-standard customization: we want to be able to switch a function via ini-configuration
        from django.conf import settings as django_settings

        # TODO amb: tiny hack: cookie-domain must be a string. dunno where this becomes a unicode
        django_settings.SESSION_COOKIE_DOMAIN = str(django_settings.SESSION_COOKIE_DOMAIN)

        log.debug('FIXTURE_DIRS:    %s', getattr(django_settings, 'FIXTURE_DIRS', None))

        debug_flag = global_config['debug'] == 'true' or False
        if debug_flag:
            log.debug('add `TransLogger` to see all requests')
            app = TransLogger(app)
        __apps_by_ini_configuration__[global_config['__file__']] = app
    else:
        log.warn('reuse django wsgi app from ini-file %s to avoid ``django.conf`` collisions',
                 global_config['__file__'])
    return __apps_by_ini_configuration__[global_config['__file__']]
开发者ID:pansen,项目名称:gonzales,代码行数:39,代码来源:__init__.py


示例4: greenify

def greenify():
    """Patch threading and psycopg2 modules for green threads."""
    # don't greenify twice.
    if _GREEN:
        return
    _GREEN[True] = True

    from gevent.monkey import patch_all, saved
    if ('threading' in sys.modules) and ('threading' not in saved):
        raise Exception('threading module loaded before patching!')
    patch_all()

    from psycogreen.gevent import patch_psycopg
    patch_psycopg()

    try:
        # Use psycopg2 by default
        import psycopg2
        del psycopg2
    except ImportError:
        # Fallback to psycopg2cffi if required (eg: pypy)
        from psycopg2cffi import compat
        compat.register()
开发者ID:rajvansia,项目名称:django-ddp,代码行数:23,代码来源:__init__.py


示例5: init_sa

def init_sa(config, **connect_kwargs):
    settings = config.registry.settings

    pc_name = settings.pop('sqlalchemy.poolclass', '')
    if pc_name:
        resolver = DottedNameResolver()
        pool_class = resolver.maybe_resolve(pc_name)
        settings['sqlalchemy.poolclass'] = pool_class

    # http://stackoverflow.com/a/15691283
    engine = engine_from_config(settings, 'sqlalchemy.',
                                connect_args=connect_kwargs)

    db_session = get_db_session(None, settings)
    db_session.configure(bind=engine)
    model_paths = config.registry.setdefault('bowab.models', set())
    for emp in model_paths:
        config.scan(emp)

    if '__pypy__' in sys.builtin_module_names:
        from psycopg2cffi import compat
        compat.register()

    return db_session
开发者ID:davidblewett,项目名称:sixfeetup.bowab,代码行数:24,代码来源:base.py


示例6:

# Flask-Restless is distributed under both the GNU Affero General Public
# License version 3 and under the 3-clause BSD license. For more
# information, see LICENSE.AGPL and LICENSE.BSD.
"""Unit tests for filtering resources in client requests."""
from datetime import date
from datetime import datetime
from datetime import time
from operator import itemgetter

# This import is unused but is required for testing on PyPy. CPython can
# use psycopg2, but PyPy can only use psycopg2cffi.
try:
    import psycopg2
except ImportError:
    from psycopg2cffi import compat
    compat.register()
from sqlalchemy import Column
from sqlalchemy import Date
from sqlalchemy import DateTime
from sqlalchemy import ForeignKey
from sqlalchemy import Integer
from sqlalchemy import Time
from sqlalchemy import Unicode
from sqlalchemy.dialects.postgresql import INET
from sqlalchemy.ext.associationproxy import association_proxy
from sqlalchemy.orm import backref
from sqlalchemy.orm import relationship
from testing.postgresql import PostgresqlFactory as PGFactory

from .helpers import check_sole_error
from .helpers import dumps
开发者ID:PlotWatt,项目名称:flask-restless,代码行数:31,代码来源:test_filtering.py


示例7: app_factory

def app_factory():
    """Factory function for the WSGI application object.

    Reads config, initializes Flask extensions that are part of the core,
    loads pg-config drivers and extensions, and configures core views.
    """
    # Use psycopg2cffi if PYPY
    if _compat.PYPY:  # pragma: no cover
        pg2cfficompat.register()

    # Flask application
    app = flask.Flask('pg-discuss')
    app.root_path = os.path.abspath(os.path.dirname(__file__))

    # Load default config values from pg_discuss.config module
    app.config.from_object(config)

    # Load custom config from user-defined PG_DISCUSS_SETTINGS_FILE
    custom_settings = os.environ.get('PG_DISCUSS_SETTINGS_FILE',
                                     '/opt/pg-discuss/local_settings.py')
    if custom_settings and os.path.isfile(custom_settings):
        app.config.from_pyfile(custom_settings)

    # Set the recursion limit
    sys.setrecursionlimit(app.config['PYTHON_RECURSION_LIMIT'])

    # Flask-SQLAlchemy
    db.init_app(app)

    # Flask-Migrate
    app.migrate = flask_migrate.Migrate(app, db)

    # Flask-Script
    app.script_manager = flask_script.Manager(app)
    app.script_manager.add_command('db', flask_migrate.MigrateCommand)
    app.script_manager.add_command('createadminuser',
                                   auth_forms.CreateAdminUser)

    # Flask-Login, for Admin users.
    app.admin_login_manager = flask_login.LoginManager(app)
    # Set up callback to load user objects`
    app.admin_login_manager.user_loader(
        lambda user_id: db.session.query(models.AdminUser).get(user_id))

    # Use stevedore to load drivers/extensions.
    # Discover all drivers/extensions, but do not load any.
    # Used for logging found extensions.
    app.ext_mgr_all = stevedore.ExtensionManager(namespace='pg_discuss.ext')

    # Load configured IdentityPolicy driver
    app.identity_policy_loader = stevedore.DriverManager(
        namespace='pg_discuss.ext',
        name=app.config['DRIVER_IDENTITY_POLICY'],
    )
    # Initialize IdentityPolicyManager with configured IdentityManager
    app.identity_policy_mgr = identity.IdentityPolicyManager(
        app,
        app.identity_policy_loader.driver,
    )

    # Load configured CommentRenderer driver
    app.comment_renderer_loader = stevedore.DriverManager(
        namespace='pg_discuss.ext',
        name=app.config['DRIVER_COMMENT_RENDERER'],
    )
    app.comment_renderer = app.comment_renderer_loader.driver(app)

    # Load configured JSONEncoder driver
    app.json_encoder_loader = stevedore.DriverManager(
        namespace='pg_discuss.ext',
        name=app.config['DRIVER_JSON_ENCODER'],
    )
    app.json_encoder = app.json_encoder_loader.driver

    # Exempt public read-only views from IdentityPolicy
    app.identity_policy_mgr.exempt(views.fetch)
    app.identity_policy_mgr.exempt(views.view)

    # Default routes. Other routes must be added through App extensions.
    # Default routes are set up before app extensions are loaded so extensions
    # can introspect/modify view functions.
    app.route('/threads/<thread_cid>/comments', methods=['GET'])(views.fetch)
    app.route('/threads/<thread_cid>/comments', methods=['POST'])(views.new)
    app.route('/comments/<int:comment_id>', methods=['GET'])(views.view)
    app.route('/comments/<int:comment_id>', methods=['PATCH'])(views.edit)
    app.route('/comments/<int:comment_id>', methods=['DELETE'])(views.delete)
    app.route('/login', methods=['GET', 'POST'])(views.admin_login)
    app.route('/logout', methods=['GET'])(views.admin_logout)

    # Load all extensions explicitly enabled via `ENABLE_EXT_*` parameters.
    app.ext_mgr = stevedore.NamedExtensionManager(
        namespace='pg_discuss.ext',
        names=config.get_enabled_extensions(app.config),
        name_order=True,
        invoke_on_load=True,
        invoke_kwds={'app': app},
        on_load_failure_callback=ext.fail_on_ext_load,
        propagate_map_exceptions=True,
    )
    # Create hook map
#.........这里部分代码省略.........
开发者ID:sprin,项目名称:pg-discuss,代码行数:101,代码来源:app.py


示例8:

VERSION = '0.1.0.dev1'

try:
    from psycopg2cffi import compat as _compat
except ImportError:
    pass
else:
    _compat.register()
开发者ID:smartstudy,项目名称:midauth,代码行数:8,代码来源:__init__.py


示例9: register

""":mod:`favien` --- Favien
~~~~~~~~~~~~~~~~~~~~~~~~~~~

"""
import platform


if platform.python_implementation() == 'PyPy':
    # Monkey patches for PyPy
    from psycopg2cffi.compat import register
    register()
开发者ID:limeburst,项目名称:favien,代码行数:11,代码来源:__init__.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python ptah.check_permission函数代码示例发布时间:2022-05-25
下一篇:
Python pool.ThreadedConnectionPool类代码示例发布时间:2022-05-25
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap