本文整理汇总了Python中pylons.translator方法的典型用法代码示例。如果您正苦于以下问题:Python pylons.translator方法的具体用法?Python pylons.translator怎么用?Python pylons.translator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pylons
的用法示例。
在下文中一共展示了pylons.translator方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _register_translator
# 需要导入模块: import pylons [as 别名]
# 或者: from pylons import translator [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
# 需要导入模块: import pylons [as 别名]
# 或者: from pylons import translator [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: _load_config
# 需要导入模块: import pylons [as 别名]
# 或者: from pylons import translator [as 别名]
def _load_config(self, load_site_user=True):
conf = self._get_config()
assert 'ckan' not in dir() # otherwise loggers would be disabled
# We have now loaded the config. Now we can import ckan for the
# first time.
from ckan.config.environment import load_environment
load_environment(conf.global_conf, conf.local_conf)
self.registry = Registry()
self.registry.prepare()
import pylons
self.translator_obj = MockTranslator()
self.registry.register(pylons.translator, self.translator_obj)
if model.user_table.exists() and load_site_user:
# If the DB has already been initialized, create and register
# a pylons context object, and add the site user to it, so the
# auth works as in a normal web request
c = pylons.util.AttribSafeContextObj()
self.registry.register(pylons.c, c)
self.site_user = logic.get_action('get_site_user')({'ignore_auth': True}, {})
pylons.c.user = self.site_user['name']
pylons.c.userobj = model.User.get(self.site_user['name'])
## give routes enough information to run url_for
parsed = urlparse.urlparse(conf.get('ckan.site_url', 'http://0.0.0.0'))
request_config = routes.request_config()
request_config.host = parsed.netloc + parsed.path
request_config.protocol = parsed.scheme
示例4: _add_extra_translations
# 需要导入模块: import pylons [as 别名]
# 或者: from pylons import translator [as 别名]
def _add_extra_translations(dirname, locales, domain):
translator = Translations.load(dirname=dirname, locales=locales,
domain=domain)
try:
pylons.translator.merge(translator)
except AttributeError:
# this occurs when an extension has 'en' translations that
# replace the default strings. As set_lang has not been run,
# pylons.translation is the NullTranslation, so we have to
# replace the StackedObjectProxy ourselves manually.
environ = pylons.request.environ
environ['pylons.pylons'].translator = translator
if 'paste.registry' in environ:
environ['paste.registry'].replace(pylons.translator,
translator)
示例5: setup_class
# 需要导入模块: import pylons [as 别名]
# 或者: from pylons import translator [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
示例6: app
# 需要导入模块: import pylons [as 别名]
# 或者: from pylons import translator [as 别名]
def app(postgres, mocker, caplog):
caplog.set_level(logging.WARNING, logger='ckan.lib.i18n')
caplog.set_level(logging.WARNING, logger='migrate')
caplog.set_level(logging.WARNING, logger='pyutilib')
caplog.set_level(logging.WARNING, logger='vdm')
caplog.set_level(logging.WARNING, logger='pysolr')
global_config = {
'__file__': '',
'here': os.path.dirname(__file__),
'ckan.site_url': 'http://localhost',
'ckan.plugins': 'harvest odgovlt_harvester',
'sqlalchemy.url': postgres,
'ckanext.harvest.user_name': 'harvest',
# 'solr_url': 'http://127.0.0.1:8983/solr/ckan',
}
app_config = {
'who.config_file': pres.resource_filename('ckan.config', 'who.ini'),
'beaker.session.secret': 'secret',
}
app = ckan.config.middleware.make_app(global_config, **app_config)
app = CKANTestApp(app)
ckan.model.repo.init_db()
ckanext.harvest.model.setup()
pylons.translator = gettext.NullTranslations()
return app
示例7: authenticate
# 需要导入模块: import pylons [as 别名]
# 或者: from pylons import translator [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()