• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python auxproc.process_contexts函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中spyne.auxproc.process_contexts函数的典型用法代码示例。如果您正苦于以下问题:Python process_contexts函数的具体用法?Python process_contexts怎么用?Python process_contexts使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了process_contexts函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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)
开发者ID:knoxsp,项目名称:spyne,代码行数:34,代码来源:msgpack.py


示例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)
开发者ID:knoxsp,项目名称:spyne,代码行数:26,代码来源:msgpack.py


示例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))
开发者ID:plq,项目名称:spyne,代码行数:32,代码来源:wsgi.py


示例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
开发者ID:lanwan,项目名称:spyne,代码行数:30,代码来源:http.py


示例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
开发者ID:josjevv,项目名称:spyne,代码行数:26,代码来源:django.py


示例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()
开发者ID:buldi,项目名称:spyne,代码行数:34,代码来源:zeromq.py


示例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
开发者ID:dikoufu,项目名称:spyne,代码行数:25,代码来源:http.py


示例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)
开发者ID:DXist,项目名称:spyne,代码行数:7,代码来源:http.py


示例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
开发者ID:drowolath,项目名称:spyne,代码行数:34,代码来源:__init__.py


示例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)
开发者ID:sunpoet,项目名称:spyne,代码行数:8,代码来源:msgpack.py


示例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)
开发者ID:ashleysommer,项目名称:spyne,代码行数:10,代码来源:websocket.py


示例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
开发者ID:josjevv,项目名称:spyne,代码行数:55,代码来源:http.py


示例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)
开发者ID:drowolath,项目名称:spyne,代码行数:12,代码来源:__init__.py


示例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)
开发者ID:amgibson,项目名称:spyne,代码行数:14,代码来源:twisted.py


示例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)
开发者ID:jpunwin,项目名称:spyne,代码行数:15,代码来源:http.py


示例16: handle_error

    def handle_error(self, p_ctx, others, error, start_response):
        if p_ctx.transport.resp_code is None:
            p_ctx.transport.resp_code = \
                self.app.out_protocol.fault_to_http_response_code(error)

        self.get_out_string(p_ctx)
        p_ctx.out_string = [''.join(p_ctx.out_string)]

        p_ctx.transport.resp_headers['Content-Length'] = str(len(p_ctx.out_string[0]))
        self.event_manager.fire_event('wsgi_exception', p_ctx)

        start_response(p_ctx.transport.resp_code,
                                             p_ctx.transport.resp_headers.items())
        try:
            process_contexts(self, others, p_ctx, error=error)
        except Exception,e:
            # Report but ignore any exceptions from auxiliary methods.
            logger.exception(e)
开发者ID:Juspeczyk,项目名称:spyne,代码行数:18,代码来源:wsgi.py


示例17: handle_error

    def handle_error(self, p_ctx, others, exc):
        self._transport.get_out_string(p_ctx)

        if isinstance(exc, InternalError):
            error = SERVER_ERROR
        else:
            error = CLIENT_ERROR

        out_string = msgpack.packb({error: msgpack.packb(p_ctx.out_document[0].values())})
        self.transport.write(out_string)
        print "HE", repr(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)
开发者ID:kolen,项目名称:spyne,代码行数:18,代码来源:msgpack.py


示例18: _cb_deferred

def _cb_deferred(retval, prot, p_ctx, others, nowrap=False):
    if len(p_ctx.descriptor.out_message._type_info) > 1 or nowrap:
        p_ctx.out_object = retval
    else:
        p_ctx.out_object = [retval]

    try:
        prot._transport.get_out_string(p_ctx)
        p_ctx.out_string = list(p_ctx.out_string)
        print "PC", p_ctx.out_string
        prot.transport.write(''.join(p_ctx.out_string))

    except:
        err(retval)

    finally:
        p_ctx.close()

    process_contexts(prot._transport, others, p_ctx)
开发者ID:jpunwin,项目名称:spyne,代码行数:19,代码来源:msgpack.py


示例19: _cb_deferred

def _cb_deferred(retval, prot, p_ctx, others, nowrap=False):
    if len(p_ctx.descriptor.out_message._type_info) > 1 or nowrap:
        p_ctx.out_object = retval
    else:
        p_ctx.out_object = [retval]

    try:
        prot._transport.get_out_string(p_ctx)
        out_string = msgpack.packb({NO_ERROR: "".join(p_ctx.out_string)})
        prot.transport.write(out_string)
        print "PC", repr(out_string)

    except Exception as e:
        logger.exception(e)
        prot.handle_error(p_ctx, others, InternalError(e))

    finally:
        p_ctx.close()

    process_contexts(prot._transport, others, p_ctx)
开发者ID:kolen,项目名称:spyne,代码行数:20,代码来源:msgpack.py


示例20: _cb_deferred

def _cb_deferred(ret, prot, p_ctx, others, nowrap=False):
    # this means callback is not invoked directly instead of as part of a
    # deferred chain
    if not nowrap:
        # 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 be.
        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]

    if p_ctx.oob_ctx is not None:
        assert isinstance(p_ctx.oob_ctx.d, Deferred)

        p_ctx.oob_ctx.d.callback(p_ctx.out_object)
        return

    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)
        logger.error("%r", p_ctx)
        prot.handle_error(p_ctx, others, InternalError(e))

    finally:
        p_ctx.close()

    process_contexts(prot.spyne_tpt, others, p_ctx)
开发者ID:plq,项目名称:spyne,代码行数:40,代码来源:msgpack.py



注:本文中的spyne.auxproc.process_contexts函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python interface.Interface类代码示例发布时间:2022-05-27
下一篇:
Python spyne.MethodContext类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap