本文整理汇总了Python中spyne.interface.Interface._has_callbacks方法的典型用法代码示例。如果您正苦于以下问题:Python Interface._has_callbacks方法的具体用法?Python Interface._has_callbacks怎么用?Python Interface._has_callbacks使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类spyne.interface.Interface
的用法示例。
在下文中一共展示了Interface._has_callbacks方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Application
# 需要导入模块: from spyne.interface import Interface [as 别名]
# 或者: from spyne.interface.Interface import _has_callbacks [as 别名]
#.........这里部分代码省略.........
if e.faultcode == 'Client' or e.faultcode.startswith('Client.'):
logger_client.exception(e)
else:
logger.exception(e)
ctx.out_error = e
# fire events
self.event_manager.fire_event('method_exception_object', ctx)
if ctx.service_class is not None:
ctx.service_class.event_manager.fire_event(
'method_exception_object', ctx)
# we don't catch BaseException because we actually don't want to catch
# "system-exiting" exceptions. See:
# https://docs.python.org/2/library/exceptions.html#exceptions.Exception
except Exception as e:
logger_server.critical(e, **{'exc_info': 1})
ctx.out_error = Fault('Server', get_fault_string_from_exception(e))
# fire events
self.event_manager.fire_event('method_exception_object', ctx)
if ctx.service_class is not None:
ctx.service_class.event_manager.fire_event(
'method_exception_object', ctx)
def call_wrapper(self, ctx):
"""This method calls the call_wrapper method in the service definition.
This can be overridden to make an application-wide custom exception
management.
"""
retval = None
# service rpc
if ctx.descriptor.no_self:
retval = ctx.descriptor.service_class.call_wrapper(ctx)
# class rpc
else:
cls = ctx.descriptor.parent_class
if cls.__orig__ is not None:
cls = cls.__orig__
inst = cls.__respawn__(ctx)
if inst is None:
raise RespawnError('{%s}%s' %
(cls.get_namespace(), cls.get_type_name()))
in_cls = ctx.descriptor.in_message
args = ctx.in_object
if args is None:
args = []
elif ctx.descriptor.body_style is BODY_STYLE_WRAPPED and \
len(in_cls.get_flat_type_info(in_cls)) <= 1:
args = []
else:
args = args[1:]
if ctx.descriptor.service_class is not None:
ctx.in_object = [inst, ctx]
ctx.in_object.extend(args)
# hack to make sure inst goes first
ctx.descriptor.no_ctx = True
retval = ctx.descriptor.service_class.call_wrapper(ctx)
elif ctx.function is not None:
if ctx.descriptor.no_ctx:
retval = ctx.function(inst, *args)
else:
retval = ctx.function(inst, ctx, *args)
return retval
def _has_callbacks(self):
return self.interface._has_callbacks()
def reinitialize(self, server):
"""This is normally called on transport instantiation by ServerBase"""
seen = set()
from spyne import MethodDescriptor
for d in self.interface.method_id_map.values():
assert isinstance(d, MethodDescriptor)
if d.aux is not None and not id(d.aux) in seen:
d.aux.initialize(server)
seen.add(id(d.aux))
if d.service_class is not None and not id(d.service_class) in seen:
d.service_class.initialize(server)
seen.add(id(d.service_class))
def __hash__(self):
return hash(tuple((id(s) for s in self.services)))
示例2: Application
# 需要导入模块: from spyne.interface import Interface [as 别名]
# 或者: from spyne.interface.Interface import _has_callbacks [as 别名]
#.........这里部分代码省略.........
"""Takes a MethodContext instance. Returns the response to the request
as a native python object. If the function throws an exception, it
returns None and sets the exception object to ctx.out_error.
Overriding this method would break event management. So this is not
meant to be overridden unless you know what you're doing.
"""
try:
# fire events
self.event_manager.fire_event('method_call', ctx)
if ctx.service_class is not None:
ctx.service_class.event_manager.fire_event('method_call', ctx)
# call the method
ctx.out_object = self.call_wrapper(ctx)
# out object is always an iterable of return values. see
# MethodContext docstrings for more info
if ctx.descriptor.body_style is not BODY_STYLE_WRAPPED or \
len(ctx.descriptor.out_message._type_info) <= 1:
# the return value should already be wrapped by a sequence.
ctx.out_object = [ctx.out_object]
# fire events
self.event_manager.fire_event('method_return_object', ctx)
if ctx.service_class is not None:
ctx.service_class.event_manager.fire_event(
'method_return_object', ctx)
except Fault as e:
if e.faultcode == 'Client' or e.faultcode.startswith('Client.'):
logger_client.exception(e)
else:
logger.exception(e)
ctx.out_error = e
# fire events
self.event_manager.fire_event('method_exception_object', ctx)
if ctx.service_class is not None:
ctx.service_class.event_manager.fire_event(
'method_exception_object', ctx)
except Exception as e:
logger.exception(e)
ctx.out_error = Fault('Server', get_fault_string_from_exception(e))
# fire events
self.event_manager.fire_event('method_exception_object', ctx)
if ctx.service_class is not None:
ctx.service_class.event_manager.fire_event(
'method_exception_object', ctx)
def call_wrapper(self, ctx):
"""This method calls the call_wrapper method in the service definition.
This can be overridden to make an application-wide custom exception
management.
"""
if ctx.descriptor.body_style is BODY_STYLE_BARE:
ctx.in_object = [ctx.in_object]
elif ctx.descriptor.body_style is BODY_STYLE_EMPTY:
ctx.in_object = []
# service rpc
if ctx.descriptor.service_class is not None:
return ctx.descriptor.service_class.call_wrapper(ctx)
# class rpc
cls = ctx.descriptor.parent_class
if cls.__orig__ is not None:
cls = cls.__orig__
inst = cls.__respawn__(ctx)
if inst is None:
raise ResourceNotFoundError('{%s}%s' %
(cls.get_namespace(), cls.get_type_name()))
args = ctx.in_object[1:]
if ctx.function is not None:
if ctx.descriptor.no_ctx:
return ctx.function(inst, *args)
else:
return ctx.function(inst, ctx, *args)
def _has_callbacks(self):
return self.interface._has_callbacks()
def reinitialize(self):
from spyne.server import ServerBase
server = ServerBase(self)
aux_memo = set()
for d in self.interface.method_id_map.values():
if d.aux is not None and not id(d.aux) in aux_memo:
d.aux.initialize(server)
aux_memo.add(id(d.aux))
def __hash__(self):
return hash(tuple((id(s) for s in self.services)))