本文整理汇总了Python中tornado.util.import_object函数的典型用法代码示例。如果您正苦于以下问题:Python import_object函数的具体用法?Python import_object怎么用?Python import_object使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了import_object函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: __call__
def __call__(self, request):
if self._sync_id != cache.client.get(self._sync_key,0):
# 重新加载 app handlers
app_handlers = self.settings['app_path'].split(os.path.sep).pop() + '.handlers'
handlers = import_object(app_handlers)
Route._routes = {}
for name in handlers.__all__:
handler_module = import_object(app_handlers + '.' + name)
reload(handler_module)
for v in dir(handler_module):
o = getattr(handler_module,v)
if type(o) is types.ModuleType:
reload(o)
# 重新加载 plugins
from xcat.models import Plugins
for plugin in Plugins.select(Plugins.handlers).where(Plugins.handlers != '[]'):
for v in Json.decode(plugin.handlers):
plugin_module = v.split('.handlers.')[0] + '.handlers'
reload(import_object(str(plugin_module)))
self.handlers = []
self.named_handlers = {}
Route.routes(self)
# 标记已同步
self._sync_id = cache.client.get(self._sync_key)
return super(Application,self).__call__(request)
开发者ID:dloveff,项目名称:BlogCatke,代码行数:30,代码来源:web.py
示例2: install
def install(plugin_name):
register = import_object(plugin_name.strip() + '.register')
name = register._handler.__module__ + \
'.' + register._handler.__name__
if models.Plugins.filter(models.Plugins.name == name).count() == 0 :
plugin = import_object(name)()
plugin.install()
# 尝试自加加载 ui_modules.py
try:
ui_modules = import_object(plugin_name + '.uimodules')
for v in dir(ui_modules):
if issubclass(getattr(ui_modules,v), UIModule) \
and v != 'UIModule':
plugin.add_ui_module(v)
except Exception, e:
pass
# 尝试自加加载 handlers.py
try:
handlers = import_object(plugin_name + '.handlers')
reload(handlers)
for v in dir(handlers):
if issubclass(getattr(handlers,v), RequestHandler) \
and v != 'RequestHandler':
plugin.add_handler(v)
except Exception, e:
pass
开发者ID:dloveff,项目名称:BlogCatke,代码行数:34,代码来源:plugins.py
示例3: reset
def reset():
global _list , _plugins_key , _cache_key
_work_plugins = []
_config = {}
_list = {}
for plugin in models.Plugins.select().order_by(models.Plugins.id.desc()):
_work_plugins.append(plugin.name)
_config[plugin.name] = Json.decode(plugin.config)
# 注册插件路由
for handler in Json.decode(plugin.handlers,[]):
import_object(handler)
binds = Json.decode(plugin.bind,{})
for event in binds:
_list.setdefault(event,[])
for v in binds[event]:
v['handler'] = import_object(str(plugin.name))
v['name'] = plugin.name
_list[event].append(v)
_plugins_key = '|'.join(_work_plugins)
cache.client.set(_cache_key,_plugins_key)
cache.client.set('xcat.plugins.work_plugins',_work_plugins)
cache.client.set('xcat.plugins.config',_config)
开发者ID:dloveff,项目名称:BlogCatke,代码行数:28,代码来源:plugins.py
示例4: start
def start():
from tornado.log import enable_pretty_logging
enable_pretty_logging()
tornado.options.parse_command_line()
import_object('devsniff.proxy')
import_object('devsniff.admin')
server_root = dirname(__file__)
proxy_settings = dict(
debug=tornado_options.debug,
template_path=path_join(server_root, "templates"),
static_path=path_join(server_root, "static"),
)
proxy_app = TornadoWebApplication(route.get_routes(), **proxy_settings)
proxy_bind = parse_bind_address(tornado_options.bind)
if tornado_options.debug:
proxy_app.listen(proxy_bind[1], proxy_bind[0])
else:
server = tornado.httpserver.HTTPServer(proxy_app)
server.bind(proxy_bind[1], proxy_bind[0])
server.start(0)
io_loop = tornado.ioloop.IOLoop.instance()
io_loop.add_callback(init_app)
io_loop.start()
开发者ID:jianingy,项目名称:devsniff,代码行数:27,代码来源:cmd.py
示例5: install
def install(plugin_name, config=None, callback=None):
register = import_object(str(plugin_name).strip() + '.register')
name = register._handler.__module__ + \
'.' + register._handler.__name__
plugin_configs = yield gen.Task(_application.cache.get, _cache_key, [])
for plugin_data in plugin_configs:
if plugin_data.get('name') == name:
if callback:
callback(False)
return
plugin = import_object(name)()
plugin.install()
# 尝试自加加载 ui_modules.py
try:
ui_modules = import_object(plugin_name + '.uimodules')
for v in dir(ui_modules):
if issubclass(getattr(ui_modules,v), UIModule) \
and v != 'UIModule':
plugin.add_ui_module(v)
except Exception, e:
pass
开发者ID:fudong1127,项目名称:xcat,代码行数:26,代码来源:plugins.py
示例6: render
def render(self, **prop):
self.dom_id = prop.get("id")
self.cols = prop.get("cols")
self.sort_sql = prop.get("sort_sql")
self.entity_full_name = prop.get("entity")
self.query_class = prop.get("query_class") # obj prop `data` func return [(k,v),(k,v)...]
self.allow_blank = prop.get("allow_blank")
html = list()
html.append("<select id='%s' name='%s' class='form-control'>" % (self.dom_id, self.dom_id))
if self.allow_blank:
html.append("<option value=''> </option>")
if not self.query_class:
if not self.entity_full_name:
return "<small>Require entity full name.</small>"
if self.entity_full_name:
cls = import_object(self.entity_full_name)
cnn = SessionFactory.new()
q = cnn.query(cls)
if self.sort_sql:
q = q.order_by(self.sort_sql)
items = q.all()
all = list()
for item in items:
all.append([(getattr(item, col)) for col in self.cols.split(",")])
for opt in all:
html.append("<option value='%s'>%s</option>" % (opt[0], opt[1]))
else:
obj = import_object(self.query_class)()
if hasattr(obj, "data"):
items = getattr(obj, "data")()
for item in items:
html.append("<option value='%s'>%s</option>" % (item[0], item[1]))
html.append("</select>")
return "".join(html)
开发者ID:tinyms,项目名称:Matty,代码行数:34,代码来源:widgets.py
示例7: choice_module_
def choice_module_(m):
if m.startswith(EXCLUDE_PREFIX):
import_m = import_object(m.lstrip(EXCLUDE_PREFIX))
check_baseclass_(import_m)
if import_m not in non_modules:
non_modules.append(import_m)
else:
import_m = import_object(m)
check_baseclass_(import_m)
inst_import_m = import_m()
if inst_import_m not in modules_lst:
modules_lst.append(inst_import_m)
开发者ID:1060460048,项目名称:torngas,代码行数:13,代码来源:httpmodule.py
示例8: execute
def execute(self):
if type(self.action) == str:
obj = import_object(self.action)()
if hasattr(obj, "execute"):
obj.execute()
elif isfunction(self.action):
self.action()
开发者ID:tinyms,项目名称:Matty,代码行数:7,代码来源:nodes.py
示例9: __init__
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:bdarnell,项目名称:tornado,代码行数:32,代码来源:routing.py
示例10: load_application
def load_application(self, application=None):
#加载app,进行初始化配置,如无ap参数,则使用内置app初始化
#加载本地化配置
if self.settings.TRANSLATIONS:
try:
from tornado import locale
locale.load_translations(self.settings.TRANSLATIONS_CONF.translations_dir)
except:
warnings.warn('locale dir load failure,maybe your config file is not set correctly.')
if not application:
if not self.urls:
raise TorngasError("urls not found.")
self.application = application_module.Application(handlers=self.urls,
default_host='',
transforms=None, wsgi=False,
**self.settings.TORNADO_CONF)
else:
if isinstance(application, tornado.web.Application):
self.application = application
else:
self.application = application(handlers=self.urls,
default_host='',
transforms=None, wsgi=False,
**self.settings.TORNADO_CONF)
self.application.project_path = self.proj_path \
if self.proj_path.endswith('/') else self.proj_path + '/'
tmpl = self.settings.TEMPLATE_CONFIG.template_engine
self.application.tmpl = import_object(tmpl) if tmpl else None
return self
开发者ID:zongbingwang,项目名称:torngas,代码行数:35,代码来源:webserver.py
示例11: valid
def valid(self, http_req):
obj = None
if type(self.action) == str:
obj = import_object(self.action)()
if hasattr(obj, "valid"):
return obj.valid()
return ""
开发者ID:tinyms,项目名称:Matty,代码行数:7,代码来源:nodes.py
示例12: include
def include(pattern, handlers, prefix_name=None):
try:
if prefix_name:
new_name = '%s-%s' % (prefix_name, '%s')
else:
new_name = '%s'
warnings.warn("you should give a 'prefix_name' for include urls,to avoid naming conflicts")
if handlers and isinstance(handlers, str):
handlers = import_object(handlers)
else:
handlers = handlers
urlspecs = []
if not pattern.endswith('/'):
pattern += '/'
if handlers and isinstance(handlers, (tuple, list)):
for handler in handlers:
if handler and isinstance(handler, urlspec):
patt = pattern + handler.repr_pattern \
.lstrip('^').lstrip('//').lstrip('/')
urlspecs.append(urlspec(patt,
handler.handler_class,
kwargs=handler.kwargs,
name=new_name % handler.name
if handler.name else handler.name))
return urlspecs
else:
raise UrlError('url error,it is must be an tuple or list')
except Exception:
raise
开发者ID:henghu-bai,项目名称:torngas-1,代码行数:30,代码来源:urlhelper.py
示例13: load_interceptor
def load_interceptor(self):
self.interceptor_intercept = []
for interceptor_path in settings.INTERCEPTOR_CLASSES:
ic_class = import_object(interceptor_path)
ic = ic_class()
if hasattr(ic, 'intercept'):
self.interceptor_intercept.append(ic.intercept)
开发者ID:356108814,项目名称:tornado-coffeebean,代码行数:7,代码来源:application.py
示例14: configure
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:velsa,项目名称:edtr.me,代码行数:25,代码来源:httpclient.py
示例15: get
def get(self):
'''停用/启用 分类'''
if False == self.validator.success:
self.jsonify(
success=False,
msg=self.validator.error.msg,
)
return
form_name = self.validator.data.form
if form_name.find('app.') != 0 or form_name.find('..') != -1:
self.jsonify(success=False, msg='Not Form Name')
return
locale_code = 'en_US'
if hasattr(self, 'locale') and hasattr(self.locale, 'code'):
locale_code = self.locale.code
form_obj = import_object(form_name)(locale_code=locale_code)
#try:
#form_obj = import_object(form_name)(locale_code=locale_code)
#except Exception, e:
#self.jsonify(success=False, msg=str(e))
#return
form_obj.xsrf_form_html = self.xsrf_form_html
yield gen.Task(form_obj.load_field_data)
form_obj.load_data(self.request.arguments)
self.jsonify(form=form_obj.to_dict())
开发者ID:FashtimeDotCom,项目名称:QcoreCMS,代码行数:32,代码来源:__init__.py
示例16: wrapper
def wrapper(self, *args, **kwargs):
#print self._locale.code
form_name = name
if name.find('.') == 0 :
module_name = self.__class__.__module__
if len(module_name.split('.')) == 4 :
arr = module_name.split('.')
arr.pop()
module_name = '.'.join(arr)
form_name = module_name + '.forms' + name
translate = None
if hasattr(self,'_'):
translate = self._
# 加载表单
self.form = import_object(form_name)(
translate = translate ,
handler = self
)
# 封装 form.validate
def get_form_data():
form = self.form
args = self.request.arguments
if form.validate(args):
return form.values()
return False
self.get_form_data = get_form_data
return method(self, *args, **kwargs)
开发者ID:2life,项目名称:wiki.catke,代码行数:35,代码来源:web.py
示例17: load
def load(self):
if hasattr(settings_module.settings, 'MIDDLEWARE_CLASSES') and len(
settings_module.settings.MIDDLEWARE_CLASSES) > 0:
for mclass in settings_module.settings.MIDDLEWARE_CLASSES:
try:
cls = import_object(mclass)
except ImportError, ex:
raise
try:
inst = cls()
except Exception, ex:
raise
if hasattr(inst, 'process_init'):
self.init_middleware.append(inst)
if hasattr(inst, 'process_request'):
self.request_middleware.append(inst)
if hasattr(inst, 'process_response'):
self.response_middleware.append(inst)
if hasattr(inst, 'process_call'):
self.call_middleware.append(inst)
if hasattr(inst, 'process_endcall'):
self.endcall_middleware.append(inst)
开发者ID:houziwty,项目名称:torngas,代码行数:28,代码来源:middleware_manager.py
示例18: load_application
def load_application(self, application=None):
if self.settings.TRANSLATIONS:
try:
from tornado import locale
locale.load_translations(self.settings.TRANSLATIONS_CONF.translations_dir)
except:
warnings.warn('locale dir load failure,maybe your config file is not set correctly.')
if not application:
if not self.urls:
raise BaseError("urls not found.")
from torngas.application import Application
self.application = Application(handlers=self.urls,
default_host='',
transforms=None, wsgi=False,
**self.settings.TORNADO_CONF)
else:
self.application = application
tmpl = self.settings.TEMPLATE_CONFIG.template_engine
self.application.tmpl = import_object(tmpl) if tmpl else None
return self
开发者ID:1060460048,项目名称:torngas,代码行数:26,代码来源:webserver.py
示例19: load
def load(self):
if hasattr(settings_module.settings, 'MIDDLEWARE_CLASSES') and len(
settings_module.settings.MIDDLEWARE_CLASSES) > 0:
for mclass in settings_module.settings.MIDDLEWARE_CLASSES:
try:
cls = import_object(mclass)
except ImportError, ex:
logger.getlogger.error('middleware error. module __import__ failed,msg:', ex)
try:
inst = cls()
except Exception, ex:
logger.getlogger.error('middleware error. cant instantiate cls(),msg:', ex)
if hasattr(inst, 'process_init'):
self.init_middleware.append(inst)
if hasattr(inst, 'process_request'):
self.request_middleware.append(inst)
if hasattr(inst, 'process_response'):
self.response_middleware.append(inst)
if hasattr(inst, 'process_call'):
self.call_middleware.append(inst)
if hasattr(inst, 'process_endcall'):
self.endcall_middleware.append(inst)
开发者ID:Nilom,项目名称:torngas,代码行数:29,代码来源:middleware_manager.py
示例20: load_middleware
def load_middleware(self):
if hasattr(settings, 'MIDDLEWARE_CLASSES') \
and len(settings.MIDDLEWARE_CLASSES):
for midd_class in settings.MIDDLEWARE_CLASSES:
try:
cls = import_object(midd_class)
except ImportError:
raise
try:
inst = cls()
if not isinstance(inst, BaseMiddleware):
raise TorngasError(
"middleware '%s' must inherit from the BaseMiddleware" % str(midd_class))
except Exception:
raise
if hasattr(inst, 'process_init'):
self.init_middleware.append(inst)
if hasattr(inst, 'process_request'):
self.request_middleware.append(inst)
if hasattr(inst, 'process_response'):
self.response_middleware.append(inst)
if hasattr(inst, 'process_call'):
self.call_middleware.append(inst)
if hasattr(inst, 'process_endcall'):
self.endcall_middleware.append(inst)
self.response_middleware.reverse()
self.endcall_middleware.reverse()
开发者ID:qloog,项目名称:torngas,代码行数:33,代码来源:__init__.py
注:本文中的tornado.util.import_object函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论