How to use the spyne.rpc function in spyne

To help you get started, we’ve selected a few spyne examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github arskom / spyne / examples / tfb / app.py View on Github external
    @rpc(NumQueriesType, _returns=Array(World))
    def updates(ctx, queries):
        """Test 5: Database Updates"""

        if queries is None:
            queries = 1

        retval = []
        q = ctx.udc.session.query(World)
        for id in (randint(1, 10000) for _ in xrange(queries)):
            world = q.get(id)
            world.randomNumber = randint(1, 10000)
            retval.append(world)

        ctx.udc.session.commit()

        return retval
github arskom / spyne / examples / complex.py View on Github external
    @rpc(User, _returns=Integer)
    def add_user(ctx, user):
        add_user(user)
        return user.userid
github arskom / spyne / examples / complex.py View on Github external
    @rpc(Integer)
    def delete_user(ctx, userid):
        global user_database

        if not (userid in user_database):
            raise ResourceNotFoundError(userid)

        del user_database[userid]
github arskom / spyne / examples / tfb / app.py View on Github external
    @rpc(_returns=World)
    def dbraw(ctx):
        conn = ctx.udc.conn

        wid = randint(1, 10000)
        return conn.execute(
                     "SELECT id, randomNumber FROM world WHERE id = %s", wid) \
                                                                     .fetchone()
github arskom / spyne / examples / tfb / app.py View on Github external
    @rpc(_returns=Array(Fortune, html_cloth=T_INDEX), _body_style='out_bare')
    def fortunesraw(ctx):
        # This is normally specified at the application level as it's a good
        # practice to group rpc endpoints with similar return types under the
        # same url fragment. eg. https://example.com/api/json
        ctx.out_protocol = HtmlCloth()
        ctx.outprot_ctx = ctx.out_protocol.get_context(ctx, ctx.transport)

        res = ctx.udc.conn.execute("SELECT id, message FROM fortune")
        fortunes = res.fetchall()

        fortunes.append(Fortune(
            id=0,
            message=u"Additional fortune added at request time."
        ))

        fortunes.sort(key=lambda x: x.message)
github arskom / spyne / spyne / util / web.py View on Github external
        @rpc(M(UnsignedInteger32),
                    _in_message_name='del_%s' % T_name,
                    _in_variable_names={'obj_id': '%s_id' % T_name})
        def del_(ctx, obj_id):
            count = ctx.udc.session.query(T).filter_by(id=obj_id).count()
            if count == 0:
                raise ResourceNotFoundError(obj_id)

            ctx.udc.session.query(T).filter_by(id=obj_id).delete()
github arskom / spyne / examples / sql_crud.py View on Github external
        @rpc(M(UnsignedInteger32),
                    _in_message_name='del_%s' % T_name,
                    _in_variable_names={'obj_id': '%s_id' % T_name})
        def del_(ctx, obj_id):
            count = ctx.udc.session.query(T).filter_by(id=obj_id).count()
            if count == 0:
                raise ResourceNotFoundError(obj_id)

            ctx.udc.session.query(T).filter_by(id=obj_id).delete()
github arskom / spyne / examples / response_as_file_dynamic.py View on Github external
    @rpc(Unicode, Integer, _returns=File)
    def say_hello_as_binary_file(ctx, name, times):
        # WARNING!: the native value for data is an iterable of bytes, not just
        # bytes! If you forget this you may return data using 1-byte http chunks
        # which is incredibly inefficient.

        # WARNING!: don't forget to encode your data! This is the binary
        # output mode! You can't just write unicode data to socket!

        mime_type = HttpTransportContext.gen_header("text/plain",
                                                                 charset="utf8")

        return File.Value(type=mime_type,
            data=['\n'.join(s.encode('utf8') for s in
                                           _say_hello(ctx, name, times, 'txt'))]
        )