本文整理汇总了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)
示例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)
示例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)
示例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
示例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)
示例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)
示例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)
示例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)
示例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)
示例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
示例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
示例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
示例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)
示例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)
示例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