本文整理汇总了Python中spyne.auxproc.process_contexts函数的典型用法代码示例。如果您正苦于以下问题:Python process_contexts函数的具体用法?Python process_contexts怎么用?Python process_contexts使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了process_contexts函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _cb_deferred
def _cb_deferred(ret, prot, p_ctx, others, nowrap=False):
# if there is one return value or the output is bare (which means there
# can't be anything other than 1 return value case) use the enclosing list.
# otherwise, the return value is a tuple anyway, so leave it alone.
if nowrap:
p_ctx.out_object = ret
else:
if p_ctx.descriptor.is_out_bare():
p_ctx.out_object = [ret]
else:
if len(p_ctx.descriptor.out_message._type_info) > 1:
p_ctx.out_object = ret
else:
p_ctx.out_object = [ret]
try:
prot.spyne_tpt.get_out_string(p_ctx)
prot.spyne_tpt.pack(p_ctx)
out_string = b''.join(p_ctx.out_string)
p_ctx.transport.resp_length = len(out_string)
prot.enqueue_outresp_data(id(p_ctx), out_string)
except Exception as e:
logger.exception(e)
prot.handle_error(p_ctx, others, InternalError(e))
finally:
p_ctx.close()
process_contexts(prot.spyne_tpt, others, p_ctx)
示例2: handle_error
def handle_error(self, p_ctx, others, exc):
self.spyne_tpt.get_out_string(p_ctx)
if isinstance(exc, InternalError):
error = self.spyne_tpt.OUT_RESPONSE_SERVER_ERROR
else:
error = self.spyne_tpt.OUT_RESPONSE_CLIENT_ERROR
data = p_ctx.out_document[0]
if isinstance(data, dict):
data = list(data.values())
out_string = msgpack.packb([
error, msgpack.packb(data),
])
self.enqueue_outresp_data(id(p_ctx), out_string)
p_ctx.transport.resp_length = len(out_string)
p_ctx.close()
try:
process_contexts(self, others, p_ctx, error=error)
except Exception as e:
# Report but ignore any exceptions from auxiliary methods.
logger.exception(e)
示例3: handle_error
def handle_error(self, p_ctx, others, error, start_response):
"""Serialize errors to an iterable of strings and return them.
:param p_ctx: Primary (non-aux) context.
:param others: List if auxiliary contexts (can be empty).
:param error: One of ctx.{in,out}_error.
:param start_response: See the WSGI spec for more info.
"""
if p_ctx.transport.resp_code is None:
p_ctx.transport.resp_code = \
p_ctx.out_protocol.fault_to_http_response_code(error)
self.get_out_string(p_ctx)
# consume the generator to get the length
p_ctx.out_string = list(p_ctx.out_string)
p_ctx.transport.resp_headers['Content-Length'] = \
str(sum((len(s) for s in p_ctx.out_string)))
self.event_manager.fire_event('wsgi_exception', p_ctx)
start_response(p_ctx.transport.resp_code,
_gen_http_headers(p_ctx.transport.resp_headers))
try:
process_contexts(self, others, p_ctx, error=error)
except Exception as e:
# Report but ignore any exceptions from auxiliary methods.
logger.exception(e)
return chain(p_ctx.out_string, self.__finalize(p_ctx))
示例4: _cb_deferred
def _cb_deferred(ret, request, p_ctx, others, resource, cb=True):
resp_code = p_ctx.transport.resp_code
# If user code set its own response code, don't touch it.
if resp_code is None:
resp_code = HTTP_200
request.setResponseCode(int(resp_code[:3]))
_set_response_headers(request, p_ctx.transport.resp_headers)
om = p_ctx.descriptor.out_message
if cb and ((not issubclass(om, ComplexModelBase)) or len(om._type_info) <= 1):
p_ctx.out_object = [ret]
else:
p_ctx.out_object = ret
retval = None
if isinstance(ret, PushBase):
retval = _init_push(ret, request, p_ctx, others, resource)
else:
resource.http_transport.get_out_string(p_ctx)
producer = Producer(p_ctx.out_string, request)
producer.deferred.addCallback(_cb_request_finished, request, p_ctx)
producer.deferred.addErrback(_eb_request_finished, request, p_ctx)
request.registerProducer(producer, False)
process_contexts(resource.http_transport, others, p_ctx)
return retval
示例5: response
def response(self, response, p_ctx, others, error=None):
"""Populate response with transport headers and finalize it.
:param response: Django HttpResponse.
:param p_ctx: Primary (non-aux) context.
:param others: List if auxiliary contexts (can be empty).
:param error: One of ctx.{in,out}_error.
:returns: Django HttpResponse
"""
for h, v in p_ctx.transport.resp_headers.items():
if v is not None:
response[h] = v
if p_ctx.transport.resp_code:
response.status_code = int(p_ctx.transport.resp_code[:3])
try:
process_contexts(self, others, p_ctx, error=error)
except Exception as e:
# Report but ignore any exceptions from auxiliary methods.
logger.exception(e)
p_ctx.close()
return response
示例6: serve_forever
def serve_forever(self):
"""Runs the ZeroMQ server."""
while True:
error = None
initial_ctx = ZmqMethodContext(self)
initial_ctx.in_string = [self.zmq_socket.recv()]
contexts = self.generate_contexts(initial_ctx)
p_ctx, others = contexts[0], contexts[1:]
if p_ctx.in_error:
p_ctx.out_object = p_ctx.in_error
error = p_ctx.in_error
else:
self.get_in_object(p_ctx)
if p_ctx.in_error:
p_ctx.out_object = p_ctx.in_error
error = p_ctx.in_error
else:
self.get_out_object(p_ctx)
if p_ctx.out_error:
p_ctx.out_object = p_ctx.out_error
error = p_ctx.out_error
self.get_out_string(p_ctx)
process_contexts(self, others, error)
self.zmq_socket.send(''.join(p_ctx.out_string))
p_ctx.close()
示例7: handle_rpc_error
def handle_rpc_error(self, p_ctx, others, error, request):
logger.error(error)
resp_code = p_ctx.transport.resp_code
# If user code set its own response code, don't touch it.
if resp_code is None:
resp_code = p_ctx.out_protocol.fault_to_http_response_code(error)
request.setResponseCode(int(resp_code[:3]))
_set_response_headers(request, p_ctx.transport.resp_headers)
# In case user code set its own out_* attributes before failing.
p_ctx.out_document = None
p_ctx.out_string = None
p_ctx.out_object = error
self.http_transport.get_out_string(p_ctx)
retval = ''.join(p_ctx.out_string)
p_ctx.close()
process_contexts(self.http_transport, others, p_ctx, error=error)
return retval
示例8: _cb_push
def _cb_push():
process_contexts(self.http_transport, others, p_ctx)
producer = _Producer(p_ctx.out_string, request)
producer.deferred.addCallbacks(_cb_request_finished,
_eb_request_finished)
request.registerProducer(producer, False)
示例9: handle_rpc
def handle_rpc(self, request):
initial_ctx = HttpMethodContext(self.http_transport, request,
self.http_transport.app.out_protocol.mime_type)
initial_ctx.in_string = [request.content.getvalue()]
contexts = self.http_transport.generate_contexts(initial_ctx)
p_ctx, others = contexts[0], contexts[1:]
if p_ctx.in_error:
return self.handle_error(p_ctx, others, p_ctx.in_error, request)
else:
self.http_transport.get_in_object(p_ctx)
if p_ctx.in_error:
return self.handle_error(p_ctx, others, p_ctx.in_error, request)
else:
self.http_transport.get_out_object(p_ctx)
if p_ctx.out_error:
return self.handle_error(p_ctx, others, p_ctx.out_error,
request)
self.http_transport.get_out_string(p_ctx)
process_contexts(self.http_transport, others, p_ctx)
def _cb_request_finished(request):
request.finish()
producer = _Producer(p_ctx.out_string, request)
producer.deferred.addErrback(err).addCallback(_cb_request_finished)
request.registerProducer(producer, False)
return NOT_DONE_YET
示例10: handle_error
def handle_error(self, p_ctx, others, error):
self.get_out_string(p_ctx)
try:
process_contexts(self, others, p_ctx, error=error)
except Exception as e:
# Report but ignore any exceptions from auxiliary methods.
logger.exception(e)
示例11: _cb_deferred
def _cb_deferred(retval, cb=True):
if cb and len(p_ctx.descriptor.out_message._type_info) <= 1:
p_ctx.out_object = [retval]
else:
p_ctx.out_object = retval
tpt.get_out_string(p_ctx)
self.sendFrame(opcode, ''.join(p_ctx.out_string), fin)
p_ctx.close()
process_contexts(tpt, others, p_ctx)
示例12: _cb_deferred
def _cb_deferred(ret, request, p_ctx, others, resource, cb=True):
resp_code = p_ctx.transport.resp_code
# If user code set its own response code, don't touch it.
if resp_code is None:
resp_code = HTTP_200
request.setResponseCode(int(resp_code[:3]))
_set_response_headers(request, p_ctx.transport.resp_headers)
om = p_ctx.descriptor.out_message
single_class = None
if cb and ((not issubclass(om, ComplexModelBase)) or len(om._type_info) <= 1):
p_ctx.out_object = [ret]
if len(om._type_info) == 1:
single_class, = om._type_info.values()
else:
p_ctx.out_object = ret
retval = NOT_DONE_YET
if isinstance(ret, PushBase):
retval = _init_push(ret, request, p_ctx, others, resource)
elif ((isclass(om) and issubclass(om, File)) or
(isclass(single_class) and issubclass(single_class, File))) and \
isinstance(p_ctx.out_protocol, HttpRpc) and \
getattr(ret, 'abspath', None) is not None:
file = static.File(ret.abspath,
defaultType=str(ret.type) or 'application/octet-stream')
retval = _render_file(file, request)
if retval != NOT_DONE_YET and cb:
request.write(retval)
request.finish()
p_ctx.close()
else:
def _close_only_context(ret):
p_ctx.close()
request.notifyFinish().addCallback(_close_only_context)
request.notifyFinish().addErrback(_eb_request_finished, request, p_ctx)
else:
resource.http_transport.get_out_string(p_ctx)
producer = Producer(p_ctx.out_string, request)
producer.deferred.addCallback(_cb_request_finished, request, p_ctx)
producer.deferred.addErrback(_eb_request_finished, request, p_ctx)
request.registerProducer(producer, False)
process_contexts(resource.http_transport, others, p_ctx)
return retval
示例13: handle_error
def handle_error(self, p_ctx, others, error, request):
resp_code = self.http_transport.app.out_protocol \
.fault_to_http_response_code(error)
request.setResponseCode(int(resp_code[:3]))
p_ctx.out_object = error
self.http_transport.get_out_string(p_ctx)
process_contexts(self.http_transport, others, p_ctx, error=error)
return ''.join(p_ctx.out_string)
示例14: _cb_deferred
def _cb_deferred(retval, request):
if len(p_ctx.descriptor.out_message._type_info) <= 1:
p_ctx.out_object = [retval]
else:
p_ctx.out_object = retval
self.http_transport.get_out_string(p_ctx)
process_contexts(self.http_transport, others, p_ctx)
producer = _Producer(p_ctx.out_string, request)
producer.deferred.addCallbacks(_cb_request_finished,
_eb_request_finished)
request.registerProducer(producer, False)
示例15: _cb_deferred
def _cb_deferred(retval, request, p_ctx, others, resource, cb=True):
if cb and len(p_ctx.descriptor.out_message._type_info) <= 1:
p_ctx.out_object = [retval]
else:
p_ctx.out_object = retval
resource.http_transport.get_out_string(p_ctx)
process_contexts(resource.http_transport, others, p_ctx)
producer = Producer(p_ctx.out_string, request)
producer.deferred.addCallback(_cb_request_finished, p_ctx, others, resource)
producer.deferred.addErrback(_eb_request_finished, p_ctx, others, resource)
request.registerProducer(producer, False)