예제 #1
0
파일: test_i18n.py 프로젝트: 984958198/tg2
def test_get_unaccessible_translator():
    def _fake_find(*args, **kwargs):
        return '/fake_file'

    real_find = _gettext.find
    _gettext.find = _fake_find
    try:
        i18n._get_translator(['de'], tg_config={'localedir': '',
                                                'package': _FakePackage()})
    finally:
        _gettext.find = real_find
예제 #2
0
def test_get_unaccessible_translator():
    def _fake_find(*args, **kwargs):
        return '/fake_file'

    real_find = _gettext.find
    _gettext.find = _fake_find
    try:
        i18n._get_translator(['de'], tg_config={'localedir': '',
                                                'package': _FakePackage()})
    finally:
        _gettext.find = real_find
예제 #3
0
파일: wsgiapp.py 프로젝트: hhy5277/tg2
    def _setup_app_env(self, environ):
        """Setup Request, Response and TurboGears context objects.

        Is also in charge of pushing TurboGears context into the
        paste registry and detect test mode. Returns whenever
        the testmode is enabled or not and the TurboGears context.
        """
        conf = self.config
        testing = False

        # Setup the basic global objects
        req = Request(environ)
        req._fast_setattr('_language', self.lang)
        req._fast_setattr('_response_type', None)

        resp_options = self.resp_options
        response = Response(content_type=resp_options['content_type'],
                            charset=resp_options['charset'],
                            headers=resp_options['headers'])

        # Setup the translator object
        translator = _get_translator(self.lang, tg_config=conf)

        if self.strict_tmpl_context:
            tmpl_context = TemplateContext()
        else:
            tmpl_context = AttribSafeTemplateContext()

        app_globals = self.globals

        locals = RequestLocals()
        locals.response = response
        locals.request = req
        locals.app_globals = app_globals
        locals.config = conf
        locals.tmpl_context = tmpl_context
        locals.translator = translator
        locals.session = environ.get(
            'beaker.session')  # Usually None, unless middleware in place
        locals.cache = environ.get(
            'beaker.cache')  # Usually None, unless middleware in place

        environ['tg.locals'] = locals

        # Register Global objects
        registry = environ['paste.registry']
        registry.register(request_local.config, conf)
        registry.register(request_local.context, locals)

        if 'paste.testing_variables' in environ:
            testing = True
            testenv = environ['paste.testing_variables']
            testenv['req'] = req
            testenv['response'] = response
            testenv['tmpl_context'] = tmpl_context
            testenv['app_globals'] = self.globals
            testenv['config'] = conf
            testenv['session'] = locals.session
            testenv['cache'] = locals.cache

        return testing, locals, registry
예제 #4
0
파일: test_i18n.py 프로젝트: 984958198/tg2
 def test_null_translator(self):
     assert i18n._get_translator(None).gettext('Hello') == 'Hello'
예제 #5
0
 def test_null_translator(self):
     assert i18n._get_translator(None).gettext('Hello') == 'Hello'
예제 #6
0
    def setup_app_env(self, environ):
        """Setup Request, Response and TurboGears context objects.

        Is also in charge of pushing TurboGears context into the
        paste registry and detect test mode. Returns whenever
        the testmode is enabled or not and the TurboGears context.
        """
        conf = self.config

        # Setup the basic global objects
        req = Request(environ)
        req._fast_setattr('_language', conf['lang'])
        req._fast_setattr('_response_type', None)

        resp_options = self.resp_options
        response = Response(content_type=resp_options['content_type'],
                            charset=resp_options['charset'],
                            headers=resp_options['headers'])

        # Setup the translator object
        lang = conf['lang']
        translator = _get_translator(lang, tg_config=conf)

        if self.strict_tmpl_context:
            tmpl_context = ContextObj()
        else:
            tmpl_context = AttribSafeContextObj()

        app_globals = self.globals
        session = environ.get('beaker.session')
        cache = environ.get('beaker.cache')

        locals = RequestLocals()
        locals.response = response
        locals.request = req
        locals.app_globals = app_globals
        locals.config = conf
        locals.tmpl_context = tmpl_context
        locals.translator = translator
        locals.session = session
        locals.cache = cache

        if self.enable_routes:  #pragma: no cover
            url = environ.get('routes.url')
            locals.url = url

        environ['tg.locals'] = locals

        #Register Global objects
        registry = environ['paste.registry']
        registry.register(request_local.config, conf)
        registry.register(request_local.context, locals)

        if 'paste.testing_variables' in environ:
            testenv = environ['paste.testing_variables']
            testenv['req'] = req
            testenv['response'] = response
            testenv['tmpl_context'] = tmpl_context
            testenv['app_globals'] = self.globals
            testenv['config'] = conf
            testenv['session'] = locals.session
            testenv['cache'] = locals.cache
            return True, locals

        return False, locals
예제 #7
0
파일: wsgiapp.py 프로젝트: antsfee/tg2
    def setup_app_env(self, environ):
        """Setup Request, Response and TurboGears context objects.

        Is also in charge of pushing TurboGears context into the
        paste registry and detect test mode. Returns whenever
        the testmode is enabled or not and the TurboGears context.
        """
        conf = self.config

        # Setup the basic global objects
        req = Request(environ)
        req._fast_setattr('_language', conf['lang'])
        req._fast_setattr('_response_type', None)

        resp_options = self.resp_options
        response = Response(
            content_type=resp_options['content_type'],
            charset=resp_options['charset'],
            headers=resp_options['headers'])

        # Setup the translator object
        lang = conf['lang']
        translator = _get_translator(lang, tg_config=conf)

        if self.strict_tmpl_context:
            tmpl_context = ContextObj()
        else:
            tmpl_context = AttribSafeContextObj()

        app_globals = self.globals
        session = environ.get('beaker.session')
        cache = environ.get('beaker.cache')

        locals = RequestLocals()
        locals.response = response
        locals.request = req
        locals.app_globals = app_globals
        locals.config = conf
        locals.tmpl_context = tmpl_context
        locals.translator = translator
        locals.session = session
        locals.cache = cache

        if self.enable_routes: #pragma: no cover
            url = environ.get('routes.url')
            locals.url = url

        environ['tg.locals'] = locals

        #Register Global objects
        registry = environ['paste.registry']
        registry.register(request_local.config, conf)
        registry.register(request_local.context, locals)

        if 'paste.testing_variables' in environ:
            testenv = environ['paste.testing_variables']
            testenv['req'] = req
            testenv['response'] = response
            testenv['tmpl_context'] = tmpl_context
            testenv['app_globals'] = self.globals
            testenv['config'] = conf
            testenv['session'] = locals.session
            testenv['cache'] = locals.cache
            return True, locals

        return False, locals
예제 #8
0
    def setup_app_env(self, environ, start_response):
        """Setup and register all the Pylons objects with the registry

        After creating all the global objects for use in the request,
        :meth:`~PylonsApp.register_globals` is called to register them
        in the environment.

        """
        conf = self.config

        # Setup the basic global objects
        req = Request(environ)
        req._fast_setattr('_language', conf['lang'])
        req._fast_setattr('_response_type', None)

        resp_options = self.resp_options
        response = Response(
            content_type=resp_options['content_type'],
            charset=resp_options['charset'],
            headers=resp_options['headers'])

        # Setup the translator object
        lang = conf['lang']
        translator = _get_translator(lang, tg_config=conf)

        if self.strict_tmpl_context:
            tmpl_context = ContextObj()
        else:
            tmpl_context = AttribSafeContextObj()

        app_globals = self.globals
        session = environ.get('beaker.session')
        cache = environ.get('beaker.cache')

        locals = RequestLocals()
        locals.response = response
        locals.request = req
        locals.app_globals = app_globals
        locals.config = conf
        locals.tmpl_context = tmpl_context
        locals.translator = translator
        locals.session = session
        locals.cache = cache

        if self.enable_routes: #pragma: no cover
            url = environ.get('routes.url')
            locals.url = url

        environ['tg.locals'] = locals

        #Register Global objects
        registry = environ['paste.registry']
        registry.register(request_local.config, conf)
        registry.register(request_local.context, locals)

        if 'paste.testing_variables' in environ:
            testenv = environ['paste.testing_variables']
            testenv['req'] = req
            testenv['response'] = response
            testenv['tmpl_context'] = tmpl_context
            testenv['app_globals'] = self.globals
            testenv['config'] = conf
            testenv['session'] = locals.session
            testenv['cache'] = locals.cache
            return True

        return False
예제 #9
0
파일: wsgiapp.py 프로젝트: TurboGears/tg2
    def _setup_app_env(self, environ):
        """Setup Request, Response and TurboGears context objects.

        Is also in charge of pushing TurboGears context into the
        paste registry and detect test mode. Returns whenever
        the testmode is enabled or not and the TurboGears context.
        """
        conf = self.config
        testing = False

        # Setup the basic global objects
        req = Request(environ)
        req._fast_setattr('_language', self.lang)
        req._fast_setattr('_response_type', None)

        resp_options = self.resp_options
        response = Response(
            content_type=resp_options['content_type'],
            charset=resp_options['charset'],
            headers=resp_options['headers']
        )

        # Setup the translator object
        translator = _get_translator(self.lang, tg_config=conf)

        if self.strict_tmpl_context:
            tmpl_context = TemplateContext()
        else:
            tmpl_context = AttribSafeTemplateContext()

        app_globals = self.globals

        locals = RequestLocals()
        locals.response = response
        locals.request = req
        locals.app_globals = app_globals
        locals.config = conf
        locals.tmpl_context = tmpl_context
        locals.translator = translator
        locals.session = environ.get('beaker.session')  # Usually None, unless middleware in place
        locals.cache = environ.get('beaker.cache')  # Usually None, unless middleware in place

        environ['tg.locals'] = locals

        # Register Global objects
        registry = environ['paste.registry']
        registry.register(request_local.config, conf)
        registry.register(request_local.context, locals)

        if 'paste.testing_variables' in environ:
            testing = True
            testenv = environ['paste.testing_variables']
            testenv['req'] = req
            testenv['response'] = response
            testenv['tmpl_context'] = tmpl_context
            testenv['app_globals'] = self.globals
            testenv['config'] = conf
            testenv['session'] = locals.session
            testenv['cache'] = locals.cache

        return testing, locals, registry