コード例 #1
0
ファイル: decorator.py プロジェクト: mediainteractiva/spyne
def _produce_input_message(f, params, kparams, _in_message_name,
                           _in_variable_names, no_ctx, no_self, args):
    _body_style = _validate_body_style(kparams)

    arg_start = 0
    if no_ctx is False:
        arg_start += 1
    if no_self is False:
        arg_start += 1

    if args is None:
        try:
            argcount = f.__code__.co_argcount
            args = f.__code__.co_varnames[arg_start:argcount]

        except AttributeError:
            raise TypeError(
                "It's not possible to instrospect builtins. You must pass a "
                "sequence of argument names as the '_args' argument to the "
                "rpc decorator to manually denote the arguments that this "
                "function accepts."
            )

        if len(params) != len(args):
            raise Exception("%r function has %d argument(s) but its decorator "
                            "has %d." % (f.__name__, len(args), len(params)))

    else:
        args = copy(args)
        if len(params) != len(args):
            raise Exception("%r function has %d argument(s) but the _args "
                            "argument has %d." % (f.__name__, len(args), len(params)))

    in_params = TypeInfo()
    for k, v in zip(args, params):
        k = _in_variable_names.get(k, k)
        in_params[k] = v

    ns = spyne.const.xml_ns.DEFAULT_NS
    if _in_message_name.startswith("{"):
        ns, _, _in_message_name = _in_message_name[1:].partition("}")

    if _body_style == 'bare':
        if len(in_params) > 1:
            raise Exception("body_style='bare' can handle at most one function "
                            "argument.")
        if len(in_params) == 0:
            message = ComplexModel.produce(type_name=_in_message_name,
                                           namespace=ns, members=in_params)
        else:
            message, = in_params.values()
            message = message.customize(sub_name=_in_message_name, sub_ns=ns)
            assert message.Attributes.sub_name is not None

    else:
        message = ComplexModel.produce(type_name=_in_message_name,
                                       namespace=ns, members=in_params)
        message.__namespace__ = ns

    return message
コード例 #2
0
ファイル: test_soap.py プロジェクト: listestalo/spyne
    def test_to_parent_element_nested(self):
        m = ComplexModel.produce(
            namespace=None,
            type_name='myMessage',
            members={'p':Person}
        )

        m.resolve_namespace(m, "m")

        p = Person()
        p.name = 'steve-o'
        p.age = 2
        p.addresses = []

        for i in range(0, 100):
            a = Address()
            a.street = '123 happy way'
            a.zip = i
            a.laditude = '45.22'
            a.longitude = '444.234'
            p.addresses.append(a)

        m_inst = m(p=p)

        element=etree.Element('test')
        Soap11().to_parent_element(m, m_inst, m.get_namespace(), element)
        element=element[0]

        self.assertEquals('{%s}myMessage' % m.get_namespace(), element.tag)

        addresses = element[0].find('{%s}addresses' % Person.get_namespace())
        self.assertEquals(100, len(addresses))
        self.assertEquals('0', addresses[0].find('{%s}zip' % Address.get_namespace()).text)
コード例 #3
0
ファイル: test_soap.py プロジェクト: listestalo/spyne
    def test_class_to_parent_element(self):
        m = ComplexModel.produce(
            namespace=None,
            type_name='myMessage',
            members={'p': Person}
        )

        m.resolve_namespace(m, "punk")

        m_inst = m()
        m_inst.p = Person()
        m_inst.p.name = 'steve-o'
        m_inst.p.age = 2
        m_inst.p.addresses = []

        element=etree.Element('test')
        Soap11().to_parent_element(m, m_inst, m.get_namespace(), element)
        element=element[0]

        self.assertEquals(element.tag, '{%s}myMessage' % m.get_namespace())
        self.assertEquals(element[0].find('{%s}name' % Person.get_namespace()).text,
                                                                    'steve-o')
        self.assertEquals(element[0].find('{%s}age' % Person.get_namespace()).text, '2')
        self.assertEquals(
              len(element[0].find('{%s}addresses' % Person.get_namespace())), 0)

        p1 = Soap11().from_element(m,element)[0]

        self.assertEquals(p1.name, m_inst.p.name)
        self.assertEquals(p1.age, m_inst.p.age)
        self.assertEquals(p1.addresses, [])
コード例 #4
0
ファイル: test_soap.py プロジェクト: mfkaptan/spyne
    def test_to_parent_element_nested(self):
        m = ComplexModel.produce(namespace=None,
                                 type_name='myMessage',
                                 members={'p': Person})

        m.resolve_namespace(m, "m")

        p = Person()
        p.name = 'steve-o'
        p.age = 2
        p.addresses = []

        for i in range(0, 100):
            a = Address()
            a.street = '123 happy way'
            a.zip = i
            a.laditude = '45.22'
            a.longitude = '444.234'
            p.addresses.append(a)

        m_inst = m(p=p)

        element = etree.Element('test')
        Soap11().to_parent_element(m, m_inst, m.get_namespace(), element)
        element = element[0]

        self.assertEquals('{%s}myMessage' % m.get_namespace(), element.tag)

        addresses = element[0].find('{%s}addresses' % Person.get_namespace())
        self.assertEquals(100, len(addresses))
        self.assertEquals(
            '0', addresses[0].find('{%s}zip' % Address.get_namespace()).text)
コード例 #5
0
ファイル: test_soap.py プロジェクト: mfkaptan/spyne
    def test_class_to_parent_element(self):
        m = ComplexModel.produce(namespace=None,
                                 type_name='myMessage',
                                 members={'p': Person})

        m.resolve_namespace(m, "punk")

        m_inst = m()
        m_inst.p = Person()
        m_inst.p.name = 'steve-o'
        m_inst.p.age = 2
        m_inst.p.addresses = []

        element = etree.Element('test')
        Soap11().to_parent_element(m, m_inst, m.get_namespace(), element)
        element = element[0]

        self.assertEquals(element.tag, '{%s}myMessage' % m.get_namespace())
        self.assertEquals(
            element[0].find('{%s}name' % Person.get_namespace()).text,
            'steve-o')
        self.assertEquals(
            element[0].find('{%s}age' % Person.get_namespace()).text, '2')
        self.assertEquals(
            len(element[0].find('{%s}addresses' % Person.get_namespace())), 0)

        p1 = Soap11().from_element(m, element)[0]

        self.assertEquals(p1.name, m_inst.p.name)
        self.assertEquals(p1.age, m_inst.p.age)
        self.assertEquals(p1.addresses, [])
コード例 #6
0
ファイル: decorator.py プロジェクト: jpunwin/spyne
def _produce_output_message(func_name, kparams):
    """Generate an output message for "rpc"-style API methods.

    This message is a wrapper to the declared return type.
    """

    _returns = kparams.get('_returns')
    _body_style = _validate_body_style(kparams)
    _out_message_name = kparams.get(
        '_out_message', '%s%s' % (func_name, spyne.const.RESPONSE_SUFFIX))

    out_params = TypeInfo()

    if _returns and _body_style == 'wrapped':
        if isinstance(_returns, (list, tuple)):
            default_names = [
                '%s%s%d' % (func_name, spyne.const.RESULT_SUFFIX, i)
                for i in range(len(_returns))
            ]

            _out_variable_names = kparams.get('_out_variable_names',
                                              default_names)

            assert (len(_returns) == len(_out_variable_names))

            var_pair = zip(_out_variable_names, _returns)
            out_params = TypeInfo(var_pair)

        else:
            _out_variable_name = kparams.get(
                '_out_variable_name',
                '%s%s' % (func_name, spyne.const.RESULT_SUFFIX))

            out_params[_out_variable_name] = _returns

    ns = spyne.const.xml_ns.DEFAULT_NS
    if _out_message_name.startswith("{"):
        ns = _out_message_name[1:].partition("}")[0]

    if _body_style == 'bare' and _returns is not None:
        message = _returns.customize(sub_name=_out_message_name, sub_ns=ns)

    else:
        message = ComplexModel.produce(type_name=_out_message_name,
                                       namespace=ns,
                                       members=out_params)

        message.Attributes._wrapper = True
        message.__namespace__ = ns  # FIXME: is this necessary?

    return message
コード例 #7
0
ファイル: test_soap.py プロジェクト: listestalo/spyne
    def test_namespaces(self):
        m = ComplexModel.produce(
            namespace="some_namespace",
            type_name='myMessage',
            members={'s': String, 'i': Integer},
        )

        mi = m()
        mi.s = 'a'

        e = etree.Element('test')
        Soap11().to_parent_element(m, mi, m.get_namespace(), e)
        e=e[0]

        self.assertEquals(e.tag, '{some_namespace}myMessage')
コード例 #8
0
    def test_namespaces(self):
        m = ComplexModel.produce(
            namespace="some_namespace",
            type_name='myMessage',
            members={'s': String, 'i': Integer},
        )

        mi = m()
        mi.s = 'a'

        e = etree.Element('test')
        Soap11().to_parent(None, m, mi, e, m.get_namespace())
        e=e[0]

        self.assertEquals(e.tag, '{some_namespace}myMessage')
コード例 #9
0
ファイル: decorator.py プロジェクト: DXist/spyne
def _produce_output_message(func_name, kparams):
    """Generate an output message for "rpc"-style API methods.

    This message is a wrapper to the declared return type.
    """

    _returns = kparams.get('_returns')
    _body_style = _validate_body_style(kparams)
    _out_message_name = kparams.get('_out_message', '%s%s' %
                                               (func_name, RESPONSE_SUFFIX))

    out_params = TypeInfo()

    if _returns and _body_style == 'wrapped':
        if isinstance(_returns, (list, tuple)):
            default_names = ['%s%s%d' % (func_name, RESULT_SUFFIX, i) for i in
                                                          range(len(_returns))]

            _out_variable_names = kparams.get('_out_variable_names',
                                                                 default_names)

            assert (len(_returns) == len(_out_variable_names))

            var_pair = zip(_out_variable_names, _returns)
            out_params = TypeInfo(var_pair)

        else:
            _out_variable_name = kparams.get('_out_variable_name',
                                           '%s%s' % (func_name, RESULT_SUFFIX))

            out_params[_out_variable_name] = _returns

    ns = DEFAULT_NS
    if _out_message_name.startswith("{"):
        ns = _out_message_name[1:].partition("}")[0]

    if _body_style == 'bare' and _returns is not None:
        message = _returns.customize(sub_name=_out_message_name, sub_ns=ns)

    else:
        message = ComplexModel.produce(type_name=_out_message_name,
                                        namespace=ns,
                                        members=out_params)

        message.Attributes._wrapper = True
        message.__namespace__ = ns # FIXME: is this necessary?

    return message
コード例 #10
0
ファイル: test_soap.py プロジェクト: listestalo/spyne
    def test_simple_message(self):
        m = ComplexModel.produce(
            namespace=None,
            type_name='myMessage',
            members={'s': String, 'i': Integer}
        )
        m.resolve_namespace(m, 'test')

        m_inst = m(s="a", i=43)

        e = etree.Element('test')
        Soap11().to_parent_element(m, m_inst, m.get_namespace(), e)
        e=e[0]

        self.assertEquals(e.tag, '{%s}myMessage' % m.get_namespace())

        self.assertEquals(e.find('{%s}s' % m.get_namespace()).text, 'a')
        self.assertEquals(e.find('{%s}i' % m.get_namespace()).text, '43')

        values = Soap11().from_element(m, e)

        self.assertEquals('a', values.s)
        self.assertEquals(43, values.i)
コード例 #11
0
    def test_simple_message(self):
        m = ComplexModel.produce(
            namespace=None,
            type_name='myMessage',
            members={'s': String, 'i': Integer}
        )
        m.resolve_namespace(m, 'test')

        m_inst = m(s="a", i=43)

        e = etree.Element('test')
        Soap11().to_parent(None, m, m_inst, e, m.get_namespace())
        e=e[0]

        self.assertEquals(e.tag, '{%s}myMessage' % m.get_namespace())

        self.assertEquals(e.find('{%s}s' % m.get_namespace()).text, 'a')
        self.assertEquals(e.find('{%s}i' % m.get_namespace()).text, '43')

        values = Soap11().from_element(None, m, e)

        self.assertEquals('a', values.s)
        self.assertEquals(43, values.i)
コード例 #12
0
ファイル: decorator.py プロジェクト: DXist/spyne
    message = None
    if _body_style == 'bare':
        if len(in_params) > 1:
            raise Exception("body_style='bare' can handle at most one function "
                                                                    "argument.")
        in_param = None

        if len(in_params) == 1:
            message, = in_params.values()
            message = message.customize(sub_name=_in_message_name, sub_ns=ns)
            assert message.Attributes.sub_name is not None

        # This dates from a time when body_style='bare' could support more
        # than one parameter. Maybe one day someone will bring that back.
        else:
            message = ComplexModel.produce(type_name=_in_message_name,
                                               namespace=ns, members=in_params)

    else:
        message = ComplexModel.produce(type_name=_in_message_name,
                                               namespace=ns, members=in_params)
        message.__namespace__ = ns

    return message


def _validate_body_style(kparams):
    _body_style = kparams.get('_body_style')
    _soap_body_style = kparams.get('_soap_body_style')

    if _body_style is None:
        _body_style = 'wrapped'
コード例 #13
0
ファイル: decorator.py プロジェクト: jpunwin/spyne
def _produce_input_message(f, params, kparams, _in_message_name,
                           _in_variable_names, no_ctx, no_self, args):
    _body_style = _validate_body_style(kparams)

    arg_start = 0
    if no_ctx is False:
        arg_start += 1
    if no_self is False:
        arg_start += 1

    if args is None:
        try:
            argcount = f.__code__.co_argcount
            args = f.__code__.co_varnames[arg_start:argcount]

        except AttributeError:
            raise TypeError(
                "It's not possible to instrospect builtins. You must pass a "
                "sequence of argument names as the '_args' argument to the "
                "rpc decorator to manually denote the arguments that this "
                "function accepts.")

        if len(params) != len(args):
            raise Exception("%r function has %d argument(s) but its decorator "
                            "has %d." % (f.__name__, len(args), len(params)))

    else:
        args = copy(args)
        if len(params) != len(args):
            raise Exception("%r function has %d argument(s) but the _args "
                            "argument has %d." %
                            (f.__name__, len(args), len(params)))

    in_params = TypeInfo()
    for k, v in zip(args, params):
        k = _in_variable_names.get(k, k)
        in_params[k] = v

    ns = spyne.const.xml_ns.DEFAULT_NS
    if _in_message_name.startswith("{"):
        ns, _, _in_message_name = _in_message_name[1:].partition("}")

    message = None
    if _body_style == 'bare':
        if len(in_params) > 1:
            raise Exception(
                "body_style='bare' can handle at most one function "
                "argument.")
        if len(in_params) == 0:
            message = ComplexModel.produce(type_name=_in_message_name,
                                           namespace=ns,
                                           members=in_params)
        else:
            message, = in_params.values()
            message = message.customize(sub_name=_in_message_name, sub_ns=ns)
            assert message.Attributes.sub_name is not None

    else:
        message = ComplexModel.produce(type_name=_in_message_name,
                                       namespace=ns,
                                       members=in_params)
        message.__namespace__ = ns

    return message
コード例 #14
0
ファイル: models.py プロジェクト: userpy/shift-planner
# Copyright 2018 ООО «Верме»
#
# Файл моделей Spyne
#

from spyne.model import primitive, complex
from spyne.model.complex import ComplexModel, Array
from spyne.util.odict import odict

NAMESPACE = "http://outsourcing.verme.ru/api/soap"

od = odict()
od['login'] = primitive.Mandatory.String
od['password'] = primitive.Mandatory.String

AuthDataHeader = ComplexModel.produce(NAMESPACE, 'authData', od)

od = odict()
od['code'] = primitive.Unicode(sub_name='code', min_occurs=1, nillable=False)
AgencySoapModel = ComplexModel.produce(NAMESPACE, 'agency', od)

od = odict()
od['code'] = primitive.Unicode(sub_name='code', min_occurs=1, nillable=False)
od['party'] = primitive.Unicode(sub_name='party', min_occurs=1, nillable=False)
AgencyEventSoapModel = ComplexModel.produce(NAMESPACE, 'agency_event', od)

od = odict()
od['code'] = primitive.Unicode(sub_name='code', min_occurs=1, nillable=False)
OrganizationSoapModel = ComplexModel.produce(NAMESPACE, 'organization', od)

od = odict()
コード例 #15
0
ファイル: decorator.py プロジェクト: mfkaptan/spyne
        ns = _in_message_name[1:].partition("}")[0]

    if _body_style == 'bare':
        if len(in_params) > 1:
            raise Exception(
                "body_style='bare' can handle at most one function "
                "argument.")
        in_param = None
        if len(in_params) == 1:
            in_param, = in_params.values()

        message = ComplexModel.alias(_in_message_name, ns, in_param)

    else:
        message = ComplexModel.produce(type_name=_in_message_name,
                                       namespace=ns,
                                       members=in_params)
        message.__namespace__ = ns

    return message


def _validate_body_style(kparams):
    _body_style = kparams.get('_body_style')
    _soap_body_style = kparams.get('_soap_body_style')

    if _body_style is None:
        _body_style = 'wrapped'
    elif not (_body_style in ('wrapped', 'bare')):
        raise ValueError("body_style must be one of ('wrapped', 'bare')")
    elif _soap_body_style == 'document':