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


Python util.import_object方法代碼示例

本文整理匯總了Python中tornado.util.import_object方法的典型用法代碼示例。如果您正苦於以下問題:Python util.import_object方法的具體用法?Python util.import_object怎麽用?Python util.import_object使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在tornado.util的用法示例。


在下文中一共展示了util.import_object方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _install_application

# 需要導入模塊: from tornado import util [as 別名]
# 或者: from tornado.util import import_object [as 別名]
def _install_application(self, application):
        if not self.urls:
            raise UrlError("urls not found.")
        if application:
            app_class = application
        else:
            app_class = Application

        tornado_conf = settings.TORNADO_CONF
        if 'default_handler_class' in tornado_conf and \
                isinstance(tornado_conf['default_handler_class'], basestring):
            tornado_conf['default_handler_class'] = import_object(tornado_conf['default_handler_class'])

        else:
            tornado_conf['default_handler_class'] = import_object('torngas.handler.ErrorHandler')

        tornado_conf['debug'] = settings.DEBUG
        self.application = app_class(handlers=self.urls,
                                     default_host='',
                                     transforms=None, wsgi=False,
                                     middlewares=settings.MIDDLEWARE_CLASSES,
                                     **tornado_conf) 
開發者ID:mqingyn,項目名稱:torngas,代碼行數:24,代碼來源:webserver.py

示例2: register

# 需要導入模塊: from tornado import util [as 別名]
# 或者: from tornado.util import import_object [as 別名]
def register(self, name):
        if isinstance(name, (str, unicode,)):
            name = import_object(name)
        obj = name()

        if self._ismd(obj, 'process_init'):
            self._INIT_LIST.append(obj.process_init)
        if self._ismd(obj, 'process_call'):
            self._CALL_LIST.appendleft(obj.process_call)
        if self._ismd(obj, 'process_request'):
            self._REQUEST_LIST.appendleft(obj.process_request)
        if self._ismd(obj, 'process_render'):
            self._RENDER_LIST.append(obj.process_render)

        if self._ismd(obj, 'process_response'):
            self._RESPONSE_LIST.append(obj.process_response)

        if self._ismd(obj, 'process_endcall'):
            self._ENDCALL_LIST.append(obj.process_endcall)

        if self._ismd(obj, 'process_exception'):
            self._EXCEPTION_LIST.appendleft(obj.process_exception) 
開發者ID:mqingyn,項目名稱:torngas,代碼行數:24,代碼來源:manager.py

示例3: _create_cache

# 需要導入模塊: from tornado import util [as 別名]
# 或者: from tornado.util import import_object [as 別名]
def _create_cache(backend, **kwargs):
    try:
        # Try to get the CACHES entry for the given backend name first
        try:
            conf = settings.CACHES[backend]
        except KeyError:
            try:
                # Trying to import the given backend, in case it's a dotted path
                import_object(backend)
            except ImportError as e:
                raise InvalidCacheBackendError("Could not find backend '%s': %s" % (
                    backend, e))
            location = kwargs.pop('LOCATION', '')
            params = kwargs
        else:
            params = conf.copy()
            params.update(kwargs)
            backend = params.pop('BACKEND')
            location = params.pop('LOCATION', '')
        backend_cls = import_object(backend)
    except ImportError as e:
        raise InvalidCacheBackendError(
            "Could not find backend '%s': %s" % (backend, e))
    return backend_cls(location, params) 
開發者ID:mqingyn,項目名稱:torngas,代碼行數:26,代碼來源:__init__.py

示例4: configure

# 需要導入模塊: from tornado import util [as 別名]
# 或者: from tornado.util import import_object [as 別名]
def configure(impl, **kwargs):
        """Configures the AsyncHTTPClient subclass to use.

        AsyncHTTPClient() actually creates an instance of a subclass.
        This method may be called with either a class object or the
        fully-qualified name of such a class (or None to use the default,
        SimpleAsyncHTTPClient)

        If additional keyword arguments are given, they will be passed
        to the constructor of each subclass instance created.  The
        keyword argument max_clients determines the maximum number of
        simultaneous fetch() operations that can execute in parallel
        on each IOLoop.  Additional arguments may be supported depending
        on the implementation class in use.

        Example::

           AsyncHTTPClient.configure("tornado.curl_httpclient.CurlAsyncHTTPClient")
        """
        if isinstance(impl, (unicode, bytes_type)):
            impl = import_object(impl)
        if impl is not None and not issubclass(impl, AsyncHTTPClient):
            raise ValueError("Invalid AsyncHTTPClient implementation")
        AsyncHTTPClient._impl_class = impl
        AsyncHTTPClient._impl_kwargs = kwargs 
開發者ID:omererdem,項目名稱:honeything,代碼行數:27,代碼來源:httpclient.py

示例5: test_import_member

# 需要導入模塊: from tornado import util [as 別名]
# 或者: from tornado.util import import_object [as 別名]
def test_import_member(self):
        self.assertIs(import_object('tornado.escape.utf8'), utf8) 
開發者ID:tao12345666333,項目名稱:tornado-zh,代碼行數:4,代碼來源:util_test.py

示例6: test_import_member_unicode

# 需要導入模塊: from tornado import util [as 別名]
# 或者: from tornado.util import import_object [as 別名]
def test_import_member_unicode(self):
        self.assertIs(import_object(u('tornado.escape.utf8')), utf8) 
開發者ID:tao12345666333,項目名稱:tornado-zh,代碼行數:4,代碼來源:util_test.py

示例7: test_import_module

# 需要導入模塊: from tornado import util [as 別名]
# 或者: from tornado.util import import_object [as 別名]
def test_import_module(self):
        self.assertIs(import_object('tornado.escape'), tornado.escape) 
開發者ID:tao12345666333,項目名稱:tornado-zh,代碼行數:4,代碼來源:util_test.py

示例8: test_import_module_unicode

# 需要導入模塊: from tornado import util [as 別名]
# 或者: from tornado.util import import_object [as 別名]
def test_import_module_unicode(self):
        # The internal implementation of __import__ differs depending on
        # whether the thing being imported is a module or not.
        # This variant requires a byte string in python 2.
        self.assertIs(import_object(u('tornado.escape')), tornado.escape) 
開發者ID:tao12345666333,項目名稱:tornado-zh,代碼行數:7,代碼來源:util_test.py

示例9: configure

# 需要導入模塊: from tornado import util [as 別名]
# 或者: from tornado.util import import_object [as 別名]
def configure(
        cls, impl: "Union[None, str, Type[Configurable]]", **kwargs: Any
    ) -> None:
        if asyncio is not None:
            from tornado.platform.asyncio import BaseAsyncIOLoop

            if isinstance(impl, str):
                impl = import_object(impl)
            if isinstance(impl, type) and not issubclass(impl, BaseAsyncIOLoop):
                raise RuntimeError(
                    "only AsyncIOLoop is allowed when asyncio is available"
                )
        super(IOLoop, cls).configure(impl, **kwargs) 
開發者ID:opendevops-cn,項目名稱:opendevops,代碼行數:15,代碼來源:ioloop.py

示例10: __init__

# 需要導入模塊: from tornado import util [as 別名]
# 或者: from tornado.util import import_object [as 別名]
def __init__(
        self,
        matcher: "Matcher",
        target: Any,
        target_kwargs: Dict[str, Any] = None,
        name: str = None,
    ) -> None:
        """Constructs a Rule instance.

        :arg Matcher matcher: a `Matcher` instance used for determining
            whether the rule should be considered a match for a specific
            request.
        :arg target: a Rule's target (typically a ``RequestHandler`` or
            `~.httputil.HTTPServerConnectionDelegate` subclass or even a nested `Router`,
            depending on routing implementation).
        :arg dict target_kwargs: a dict of parameters that can be useful
            at the moment of target instantiation (for example, ``status_code``
            for a ``RequestHandler`` subclass). They end up in
            ``target_params['target_kwargs']`` of `RuleRouter.get_target_delegate`
            method.
        :arg str name: the name of the rule that can be used to find it
            in `ReversibleRouter.reverse_url` implementation.
        """
        if isinstance(target, str):
            # import the Module and instantiate the class
            # Must be a fully qualified name (module.ClassName)
            target = import_object(target)

        self.matcher = matcher  # type: Matcher
        self.target = target
        self.target_kwargs = target_kwargs if target_kwargs else {}
        self.name = name 
開發者ID:opendevops-cn,項目名稱:opendevops,代碼行數:34,代碼來源:routing.py

示例11: load_application

# 需要導入模塊: from tornado import util [as 別名]
# 或者: from tornado.util import import_object [as 別名]
def load_application(self, application=None):
        """

        :type application: torngas.application.Application subclass or instance
        :return:
        """
        self._patch_httpserver()
        if settings.TRANSLATIONS:
            try:
                from tornado import locale

                locale.load_translations(settings.TRANSLATIONS_CONF.translations_dir)
            except:
                warnings.warn('locale dir load failure,maybe your config file is not set correctly.')

        if not application:
            self._install_application(application)
        elif isinstance(application, Application):
            self.application = application
        elif issubclass(application, Application):
            self._install_application(application)
        else:
            raise ArgumentError('need torngas.application.Application instance object or subclass.')

        tmpl = settings.TEMPLATE_CONFIG.template_engine
        self.application.tmpl = import_object(tmpl) if tmpl else None

        return self.application 
開發者ID:mqingyn,項目名稱:torngas,代碼行數:30,代碼來源:webserver.py

示例12: load_urls

# 需要導入模塊: from tornado import util [as 別名]
# 或者: from tornado.util import import_object [as 別名]
def load_urls(self):
        urls = []
        if settings.INSTALLED_APPS:
            for app_name in settings.INSTALLED_APPS:
                app_urls = import_object(app_name + '.urls.urls')
                urls.extend(app_urls)
        else:
            raise ConfigError('load urls error,INSTALLED_APPS not found!')
        self.urls = urls
        return self.urls 
開發者ID:mqingyn,項目名稱:torngas,代碼行數:12,代碼來源:webserver.py

示例13: __getattr__

# 需要導入模塊: from tornado import util [as 別名]
# 或者: from tornado.util import import_object [as 別名]
def __getattr__(self, func_name):
        if self.module is None:
            self.module = import_object(self.module_name)
        return getattr(self.module, func_name) 
開發者ID:mqingyn,項目名稱:torngas,代碼行數:6,代碼來源:utils.py

示例14: create_session

# 需要導入模塊: from tornado import util [as 別名]
# 或者: from tornado.util import import_object [as 別名]
def create_session(engine=None, scopefunc=None, twophase=False, **kwargs):
    def import_(param):
        if isinstance(param, string_types):
            return import_object(param)
        else:
            return param

    if scopefunc:
        scopefunc = import_(scopefunc)

    if 'extension' in kwargs:
        kwargs['extension'] = import_(kwargs['extension'])

    if 'class_' in kwargs:
        kwargs['class_'] = import_(kwargs['class_'])

    if 'query_cls' in kwargs:
        kwargs['query_cls'] = import_(kwargs['query_cls'])

    session = sessionmaker(autoflush=kwargs.pop('autoflush', True),
                           autocommit=kwargs.pop('autocommit', False),
                           expire_on_commit=kwargs.pop('expire_on_commit', True),
                           info=kwargs.pop('expire_on_commit', None),
                           **kwargs)

    if not twophase:
        session.configure(bind=engine)

    else:
        # eg:binds = {User:engine1, Account:engine2}
        session.configure(binds=engine, twophase=twophase)

    return scoped_session(session, scopefunc) 
開發者ID:mqingyn,項目名稱:torngas,代碼行數:35,代碼來源:dbalchemy.py

示例15: get_key_func

# 需要導入模塊: from tornado import util [as 別名]
# 或者: from tornado.util import import_object [as 別名]
def get_key_func(key_func):
    """
    Function to decide which key function to use.

    Defaults to ``default_key_func``.
    """
    if key_func is not None:
        if callable(key_func):
            return key_func
        else:
            return import_object(key_func)
    return default_key_func 
開發者ID:mqingyn,項目名稱:torngas,代碼行數:14,代碼來源:base.py


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