当前位置: 首页>>代码示例>>Python>>正文


Python spyne.MethodContext类代码示例

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


在下文中一共展示了MethodContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _dry_me

    def _dry_me(services, d, ignore_wrappers=False, complex_as=dict,
                         just_ctx=False, just_in_object=False, validator=None,
                         polymorphic=False):

        app = Application(services, 'tns',
                in_protocol=_DictDocumentChild(
                    ignore_wrappers=ignore_wrappers, complex_as=complex_as,
                    polymorphic=polymorphic, validator=validator,
                ),
                out_protocol=_DictDocumentChild(
                     ignore_wrappers=ignore_wrappers, complex_as=complex_as,
                                                       polymorphic=polymorphic),
            )

        server = ServerBase(app)
        initial_ctx = MethodContext(server, MethodContext.SERVER)
        in_string = serializer.dumps(d, **dumps_kwargs)
        if not isinstance(in_string, bytes):
            in_string = in_string.encode('utf8')
        initial_ctx.in_string = [in_string]

        ctx, = server.generate_contexts(initial_ctx, in_string_charset='utf8')
        if not just_ctx:
            server.get_in_object(ctx)
            if not just_in_object:
                server.get_out_object(ctx)
                server.get_out_string(ctx)

        return ctx
开发者ID:1-bit,项目名称:spyne,代码行数:29,代码来源:_test_dictdoc.py

示例2: test_multiple_return_sd_0

    def test_multiple_return_sd_0(self):
        class SomeService(ServiceBase):
            @srpc(_returns=Iterable(Integer))
            def some_call():
                return 1, 2

        app = Application([SomeService], 'tns', JsonObject(), JsonObject(),
                                                                       Wsdl11())

        server = ServerBase(app)
        initial_ctx = MethodContext(server)
        initial_ctx.in_string = ['{"some_call":{}}']

        ctx, = server.generate_contexts(initial_ctx)
        server.get_in_object(ctx)
        server.get_out_object(ctx)
        server.get_out_string(ctx)

        assert list(ctx.out_string) == ['{"some_callResponse": {"some_callResult": {"integer": [1, 2]}}}' ]

        server = ServerBase(app)
        initial_ctx = MethodContext(server)
        initial_ctx.in_string = ['{"some_call":[]}']

        ctx, = server.generate_contexts(initial_ctx)
        server.get_in_object(ctx)
        server.get_out_object(ctx)
        server.get_out_string(ctx)

        assert list(ctx.out_string) == ['{"some_callResponse": {"some_callResult": {"integer": [1, 2]}}}']
开发者ID:leekchan,项目名称:spyne,代码行数:30,代码来源:test_json.py

示例3: test_soap_input_header_order

    def test_soap_input_header_order(self):
        """
        Tests supports for input headers whose elements are provided in
        different order than that defined in rpc declaration _in_header parameter.
        """
        server = ServerBase(self.app)
        initial_ctx = MethodContext(server)
        initial_ctx.in_string = [
            '<senv:Envelope xmlns:tns="tns"'
                'xmlns:wsa="http://www.w3.org/2005/08/addressing"'
                'xmlns:senv="http://schemas.xmlsoap.org/soap/envelope/">'
                '<senv:Header>'
                    '<wsa:MessageID>SomeMessageID</wsa:MessageID>'
                    '<wsa:RelatesTo>SomeRelatesToID</wsa:RelatesTo>'
                    '<wsa:Action>/SomeAction</wsa:Action>'
                '</senv:Header>'
                '<senv:Body>'
                    '<tns:someRequest>'
                        '<tns:status>OK</tns:status>'
                    '</tns:someRequest>'
                '</senv:Body>'
                '</senv:Envelope>'
        ]

        ctx, = server.generate_contexts(initial_ctx)
        server.get_in_object(ctx)

        self.assertEquals(ctx.in_header[0], '/SomeAction')
        self.assertEquals(ctx.in_header[1], 'SomeMessageID')
        self.assertEquals(ctx.in_header[2], 'SomeRelatesToID')
开发者ID:colons,项目名称:spyne,代码行数:30,代码来源:test_soap.py

示例4: test_soap_input_header

    def test_soap_input_header(self):
        server = ServerBase(self.app)
        initial_ctx = MethodContext(server)
        initial_ctx.in_string = [
            '<senv:Envelope xmlns:tns="tns"'
                'xmlns:wsa="http://www.w3.org/2005/08/addressing"'
                'xmlns:senv="http://schemas.xmlsoap.org/soap/envelope/">'
                '<senv:Header>'
                    '<wsa:Action>/SomeAction</wsa:Action>'
                    '<wsa:MessageID>SomeMessageID</wsa:MessageID>'
                    '<wsa:RelatesTo>SomeRelatesToID</wsa:RelatesTo>'
                '</senv:Header>'
                '<senv:Body>'
                    '<tns:someRequest>'
                        '<tns:status>OK</tns:status>'
                    '</tns:someRequest>'
                '</senv:Body>'
                '</senv:Envelope>'
        ]

        ctx, = server.generate_contexts(initial_ctx)
        server.get_in_object(ctx)

        self.assertEquals(ctx.in_header[0], '/SomeAction')
        self.assertEquals(ctx.in_header[1], 'SomeMessageID')
        self.assertEquals(ctx.in_header[2], 'SomeRelatesToID')
开发者ID:colons,项目名称:spyne,代码行数:26,代码来源:test_soap.py

示例5: test_multiple_return_sd_0

        def test_multiple_return_sd_0(self):
            class SomeService(ServiceBase):
                @srpc(_returns=Iterable(Integer))
                def some_call():
                    return 1, 2

            app = Application([SomeService], 'tns', in_protocol=_DictObjectChild(), out_protocol=_DictObjectChild())


            server = ServerBase(app)
            initial_ctx = MethodContext(server)
            initial_ctx.in_string = [serializer.dumps({"some_call":{}})]

            ctx, = server.generate_contexts(initial_ctx)
            server.get_in_object(ctx)
            server.get_out_object(ctx)
            server.get_out_string(ctx)

            assert list(ctx.out_string) == [serializer.dumps({"some_callResponse": {"some_callResult": {"integer": [1, 2]}}})]

            server = ServerBase(app)
            initial_ctx = MethodContext(server)
            initial_ctx.in_string = [serializer.dumps({"some_call":[]})]

            ctx, = server.generate_contexts(initial_ctx)
            server.get_in_object(ctx)
            server.get_out_object(ctx)
            server.get_out_string(ctx)

            assert list(ctx.out_string) == [serializer.dumps({"some_callResponse": {"some_callResult": {"integer": [1, 2]}}})]
开发者ID:leobispo,项目名称:spyne,代码行数:30,代码来源:_test_dictobj.py

示例6: test_soap_input_header_order_and_missing

    def test_soap_input_header_order_and_missing(self):
        """
        Test that header ordering logic also works when an input header
        element is missing.  Confirm that it returns None for the missing
        parameter.
        """
        server = ServerBase(self.app)
        initial_ctx = MethodContext(server)
        initial_ctx.in_string = [
            '<senv:Envelope xmlns:tns="tns"'
                'xmlns:wsa="http://www.w3.org/2005/08/addressing"'
                'xmlns:senv="http://schemas.xmlsoap.org/soap/envelope/">'
                '<senv:Header>'
                    '<wsa:MessageID>SomeMessageID</wsa:MessageID>'
                    '<wsa:Action>/SomeAction</wsa:Action>'
                '</senv:Header>'
                '<senv:Body>'
                    '<tns:someRequest>'
                        '<tns:status>OK</tns:status>'
                    '</tns:someRequest>'
                '</senv:Body>'
                '</senv:Envelope>'
        ]

        ctx, = server.generate_contexts(initial_ctx)
        server.get_in_object(ctx)

        self.assertEquals(ctx.in_header[0], '/SomeAction')
        self.assertEquals(ctx.in_header[1], 'SomeMessageID')
        self.assertEquals(ctx.in_header[2], None)
开发者ID:colons,项目名称:spyne,代码行数:30,代码来源:test_soap.py

示例7: test_decimal

    def test_decimal(self):
        d = decimal.Decimal('1e100')

        class SomeService(ServiceBase):
            @srpc(Decimal(120,4), _returns=Decimal)
            def some_call(p):
                print(p)
                print(type(p))
                assert type(p) == decimal.Decimal
                assert d == p
                return p

        app = Application([SomeService], "tns", in_protocol=XmlDocument(),
                                                out_protocol=XmlDocument())
        server = ServerBase(app)
        initial_ctx = MethodContext(server)
        initial_ctx.in_string = ['<some_call xmlns="tns"><p>%s</p></some_call>'
                                                                            % d]

        ctx, = server.generate_contexts(initial_ctx)
        server.get_in_object(ctx)
        server.get_out_object(ctx)
        server.get_out_string(ctx)

        elt = etree.fromstring(''.join(ctx.out_string))

        print(etree.tostring(elt, pretty_print=True))
        target = elt.xpath('//tns:some_callResult/text()',
                                              namespaces=app.interface.nsmap)[0]
        assert target == str(d)
开发者ID:DmitriyMoseev,项目名称:spyne,代码行数:30,代码来源:test_xml.py

示例8: test_attribute_ns

    def test_attribute_ns(self):
        class a(ComplexModel):
            b = Unicode
            c = XmlAttribute(Unicode, ns="spam", attribute_of="b")

        class SomeService(ServiceBase):
            @srpc(_returns=a)
            def some_call():
                return a(b="foo",c="bar")

        app = Application([SomeService], "tns", in_protocol=XmlDocument(),
                                                out_protocol=XmlDocument())
        server = ServerBase(app)
        initial_ctx = MethodContext(server)
        initial_ctx.in_string = ['<some_call xmlns="tns"/>']

        ctx, = server.generate_contexts(initial_ctx)
        server.get_in_object(ctx)
        server.get_out_object(ctx)
        server.get_out_string(ctx)

        elt = etree.fromstring(''.join(ctx.out_string))
        target = elt.xpath('//s0:b', namespaces=app.interface.nsmap)[0]

        print(etree.tostring(elt, pretty_print=True))
        assert target.attrib['{%s}c' % app.interface.nsmap["s1"]] == "bar"
开发者ID:DmitriyMoseev,项目名称:spyne,代码行数:26,代码来源:test_xml.py

示例9: test_primitive_only

        def test_primitive_only(self):
            class SomeComplexModel(ComplexModel):
                i = Integer
                s = String

            class SomeService(ServiceBase):
                @srpc(SomeComplexModel, _returns=SomeComplexModel)
                def some_call(scm):
                    return SomeComplexModel(i=5, s='5x')

            app = Application([SomeService], 'tns',
                                    in_protocol=_DictObjectChild(),
                                    out_protocol=_DictObjectChild())

            server = ServerBase(app)
            initial_ctx = MethodContext(server)
            initial_ctx.in_string = [serializer.dumps({"some_call":[]})]

            ctx, = server.generate_contexts(initial_ctx)
            server.get_in_object(ctx)
            server.get_out_object(ctx)
            server.get_out_string(ctx)

            assert list(ctx.out_string) == [serializer.dumps(
                {"some_callResponse": {"some_callResult": {"i": 5, "s": "5x"}}})]
开发者ID:anthonyrisinger,项目名称:spyne,代码行数:25,代码来源:_test_dictobj.py

示例10: serve_forever

    def serve_forever(self):
        while True:
            last = self.session.query(WorkerStatus).with_lockmode("update") \
                          .filter_by(worker_id=self.id).one()

            task_queue = self.session.query(TaskQueue) \
                    .filter(TaskQueue.id > last.task_id) \
                    .order_by(TaskQueue.id)

            for task in task_queue:
                initial_ctx = MethodContext(self.app)
                initial_ctx.in_string = [task.data]
                initial_ctx.transport.consumer_id = self.id
                initial_ctx.transport.task_id = task.id

                for ctx in self.generate_contexts(initial_ctx, 'utf8'):
                    self.get_in_object(ctx)
                    if ctx.in_error:
                        self.get_out_string(ctx)
                        logging.error(''.join(ctx.out_string))
                        continue

                    self.get_out_object(ctx)
                    if ctx.out_error:
                        self.get_out_string(ctx)
                        logging.error(''.join(ctx.out_string))
                        continue

                    self.get_out_string(ctx)
                    logging.debug(''.join(ctx.out_string))

                    last.task_id = task.id
                    self.session.commit()

            time.sleep(10)
开发者ID:66ru,项目名称:spyne,代码行数:35,代码来源:queue.py

示例11: test_complex

        def test_complex(self):
            class CM(ComplexModel):
                i = Integer
                s = String

            class CCM(ComplexModel):
                c = CM
                i = Integer
                s = String

            class SomeService(ServiceBase):
                @srpc(CCM, _returns=CCM)
                def some_call(ccm):
                    return CCM(c=ccm.c, i=ccm.i, s=ccm.s)

            app = Application([SomeService], 'tns',
                                    in_protocol=_DictObjectChild(),
                                    out_protocol=_DictObjectChild())

            server = ServerBase(app)
            initial_ctx = MethodContext(server)
            initial_ctx.in_string = [serializer.dumps({"some_call":{"ccm": {"c":{"i":3, "s": "3x"}, "i":4, "s": "4x"}}})]

            ctx, = server.generate_contexts(initial_ctx)
            server.get_in_object(ctx)
            server.get_out_object(ctx)
            server.get_out_string(ctx)

            ret = serializer.loads(''.join(ctx.out_string))
            print(ret)

            assert ret['some_callResponse']['some_callResult']['i'] == 4
            assert ret['some_callResponse']['some_callResult']['s'] == '4x'
            assert ret['some_callResponse']['some_callResult']['c']['i'] == 3
            assert ret['some_callResponse']['some_callResult']['c']['s'] == '3x'
开发者ID:anthonyrisinger,项目名称:spyne,代码行数:35,代码来源:_test_dictobj.py

示例12: test_xml_data

    def test_xml_data(self):
        class C(ComplexModel):
            a = XmlData(Unicode)
            b = XmlAttribute(Unicode)

        class SomeService(ServiceBase):
            @srpc(C, _returns=C)
            def some_call(c):
                assert c.a == "a"
                assert c.b == "b"
                return c

        app = Application(
            [SomeService], "tns", name="test_xml_data", in_protocol=XmlDocument(), out_protocol=XmlDocument()
        )
        server = ServerBase(app)
        initial_ctx = MethodContext(server, MethodContext.SERVER)
        initial_ctx.in_string = [b'<some_call xmlns="tns">' b'<c b="b">a</c>' b"</some_call>"]

        ctx, = server.generate_contexts(initial_ctx)
        server.get_in_object(ctx)
        server.get_out_object(ctx)
        server.get_out_string(ctx)

        print(ctx.out_string)
        pprint(app.interface.nsmap)

        ret = etree.fromstring(b"".join(ctx.out_string)).xpath(
            "//tns:some_call" + RESULT_SUFFIX, namespaces=app.interface.nsmap
        )[0]

        print(etree.tostring(ret, pretty_print=True))

        assert ret.text == "a"
        assert ret.attrib["b"] == "b"
开发者ID:plq,项目名称:spyne,代码行数:35,代码来源:test_xml.py

示例13: test_basic

    def test_basic(self):
        class SomeService(ServiceBase):
            @srpc(String(pattern='a'))
            def some_method(s):
                pass

        application = Application([SomeService],
            in_protocol=Soap11(validator='soft'),
            out_protocol=Soap11(),
            name='Service', tns='tns',
        )
        server = ServerBase(application)

        ctx = MethodContext(server)
        ctx.in_string = [u"""
            <SOAP-ENV:Envelope xmlns:ns0="tns"
                               xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
               <SOAP-ENV:Body>
                  <ns0:some_method>
                     <ns0:s>OK</ns0:s>
                  </ns0:some_method>
               </SOAP-ENV:Body>
            </SOAP-ENV:Envelope>
        """]


        ctx, = server.generate_contexts(ctx)
        server.get_in_object(ctx)

        self.assertEquals(isinstance(ctx.in_error, ValidationError), True)
开发者ID:listestalo,项目名称:spyne,代码行数:30,代码来源:test_soft_validation.py

示例14: handle_rpc

    def handle_rpc(self, element, serviceId):

        log.debug('call handle_rpc')

        def _cb_deferred(ret, ctx):
            #             print('deferred: %s' % str(ret))
            log.debug('deferred result')
            om = ctx.descriptor.out_message
            if ((not issubclass(om, ComplexModelBase)) or
                    len(om._type_info) <= 1):
                ctx.out_object = (ret.encode('utf-8'))
            else:
                ctx.out_object = (r.decode('utf-8') for r in ret)
            self.get_out_string(ctx)
            return ctx.out_string[0]

        def _eb_deferred(error, ctx):
            ctx.out_error = error.value
            if isinstance(ctx.out_string, list):
                log.error(''.join(ctx.out_string))
            else:
                log.error(ctx.out_string)
            return ctx.out_string

        initial_ctx = MethodContext(self, MethodContext.SERVER)
        initial_ctx.in_string = element
        for ctx in self.generate_contexts(initial_ctx, 'utf8'):
            # This is standard boilerplate for invoking services.
            if ctx.in_error:
                print(ctx)
            try:
                self.get_in_object(ctx)
            except AttributeError:
                log.error(ctx.out_string)
                return defer.succeed(UPNP_ERROR % (serviceId,
                                                   ctx.in_error.faultcode,
                                                   ctx.in_error.faultstring))
            if ctx.in_error:
                self.get_out_string(ctx)
                log.error(''.join(ctx.out_string))
                continue
            self.get_out_object(ctx)
            if ctx.out_error:
                self.get_out_string(ctx)
                log.error(''.join(ctx.out_string))
                continue
            ret = ctx.out_object[0]
#             print(ret)
            if isinstance(ret, Deferred):
                if ret.called:
                    return defer.succeed(_cb_deferred(ret.result, ctx))
                ret.addCallback(_cb_deferred, ctx)
                ret.addErrback(_eb_deferred, ctx)
                return ret
            else:
                self.get_out_string(ctx)
#                 print('no deferred: %s' % ctx.out_string)
                log.debug('result type no deferred')
                return defer.succeed(ctx.out_string)
开发者ID:bverdu,项目名称:onDemand,代码行数:59,代码来源:xmpp.py

示例15: deserialize_request_string

def deserialize_request_string(string, app):
    """Deserialize request string using in_protocol in application definition.
    Returns the corresponding native python object.
    """

    server = ServerBase(app)
    initial_ctx = MethodContext(server)
    initial_ctx.in_string = [string]

    ctx = server.generate_contexts(initial_ctx)[0]
    server.get_in_object(ctx)
    return ctx.in_object
开发者ID:Bluehorn,项目名称:spyne,代码行数:12,代码来源:protocol.py


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