本文整理匯總了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)
示例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)
示例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
示例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()