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


Python cli.MockTranslator方法代码示例

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


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

示例1: _register_translator

# 需要导入模块: from ckan.lib import cli [as 别名]
# 或者: from ckan.lib.cli import MockTranslator [as 别名]
def _register_translator():
    """
    Register a translator in this thread.
    """
    global registry
    try:
        registry
    except NameError:
        registry = Registry()
    registry.prepare()
    global translator_obj
    try:
        translator_obj
    except NameError:
        translator_obj = MockTranslator()
    registry.register(translator, translator_obj) 
开发者ID:stadt-karlsruhe,项目名称:ckanext-extractor,代码行数:18,代码来源:config.py

示例2: register_translator

# 需要导入模块: from ckan.lib import cli [as 别名]
# 或者: from ckan.lib.cli import MockTranslator [as 别名]
def register_translator():
    # https://github.com/ckan/ckanext-archiver/blob/master/ckanext/archiver/bin/common.py
    # If not set (in cli access), patch the a translator with a mock, so the
    # _() functions in logic layer don't cause failure.
    from paste.registry import Registry
    from pylons import translator
    from ckan.lib.cli import MockTranslator
    if 'registery' not in globals():
        global registry
        registry = Registry()
        registry.prepare()

    if 'translator_obj' not in globals():
        global translator_obj
        translator_obj = MockTranslator()
        registry.register(translator, translator_obj) 
开发者ID:datadotworld,项目名称:ckanext-datadotworld,代码行数:18,代码来源:tasks.py

示例3: setup_class

# 需要导入模块: from ckan.lib import cli [as 别名]
# 或者: from ckan.lib.cli import MockTranslator [as 别名]
def setup_class(cls):
        cls.registry=Registry()
        cls.registry.prepare()

        cls.context_obj=AttribSafeContextObj()
        cls.registry.register(pylons.c, cls.context_obj)

        cls.app_globals_obj = app_globals.app_globals
        cls.registry.register(pylons.g, cls.app_globals_obj)

        cls.request_obj=Request(dict(HTTP_HOST="nohost", REQUEST_METHOD="GET"))
        cls.registry.register(pylons.request, cls.request_obj)

        cls.translator_obj=MockTranslator()
        cls.registry.register(pylons.translator, cls.translator_obj)

        cls.registry.register(pylons.response, Response())
        mapper = make_map()
        cls.registry.register(pylons.url, URLGenerator(mapper, {}))
        cls.registry.register(pylons.session, TestPylonsSession())

        # Templates often want to find out the request's routes info, so put
        # some dummy values into the routes_dict, so the templates that do
        # this don't cause an exception.
        pylons.request.environ.update({'pylons.routes_dict': {
            'action': 'test-action',
            'controller': 'test-package::',
        }})
        pylons.c.environ = pylons.request.environ 
开发者ID:italia,项目名称:dati-ckan-docker,代码行数:31,代码来源:pylons_controller.py

示例4: authenticate

# 需要导入模块: from ckan.lib import cli [as 别名]
# 或者: from ckan.lib.cli import MockTranslator [as 别名]
def authenticate(self, environ, identity):
        """A username/password authenticator that throttles login request by IP."""
        try:
            login = identity['login']
        except KeyError:
            return None

        environ['paste.registry'].register(pylons.translator, MockTranslator())

        try:
            remote_addr = Request(environ).headers['X-Forwarded-For']
        except KeyError:
            log.critical('X-Forwarded-For header missing from request.')
            return None

        throttle = LoginThrottle(User.by_name(login), remote_addr)
        if not ('login' in identity and 'password' in identity):
            return None

        # Run through the CKAN auth sequence first, so we can hit the DB
        # in every case and make timing attacks a little more difficult.
        auth_user = super(CKANLoginThrottle, self).authenticate(environ, identity)

        # Check if there is a lock on the requested user, and return None if
        # we have a lock.
        if throttle.check_attempts() is False:
            log.info('User %r (%s) locked out by brute force protection.' % (login, remote_addr))
            throttle.increment()  # Increment so we only send an email the first time around
            return None

        # If the CKAN authenticator as successfully authenticated the request
        # and the user wasn't locked out above, reset the throttle counter and
        # return the user object.
        if auth_user is not None:
            throttle.reset()
            return auth_user

        # Increment the throttle counter if the login failed.
        throttle.increment() 
开发者ID:data-govt-nz,项目名称:ckanext-security,代码行数:41,代码来源:authenticator.py


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