當前位置: 首頁>>代碼示例>>Python>>正文


Python pylons.translator方法代碼示例

本文整理匯總了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) 
開發者ID:stadt-karlsruhe,項目名稱:ckanext-extractor,代碼行數:18,代碼來源:config.py

示例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) 
開發者ID:datadotworld,項目名稱:ckanext-datadotworld,代碼行數:18,代碼來源:tasks.py

示例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 
開發者ID:italia,項目名稱:dati-ckan-docker,代碼行數:34,代碼來源:cli.py

示例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) 
開發者ID:italia,項目名稱:dati-ckan-docker,代碼行數:17,代碼來源:i18n.py

示例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 
開發者ID:italia,項目名稱:dati-ckan-docker,代碼行數:31,代碼來源:pylons_controller.py

示例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 
開發者ID:ivpk,項目名稱:opendata.gov.lt-mysql-import,代碼行數:31,代碼來源:test_odgovlt.py

示例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() 
開發者ID:data-govt-nz,項目名稱:ckanext-security,代碼行數:41,代碼來源:authenticator.py


注:本文中的pylons.translator方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。