示例#1
0
    class WriterService(WriterServiceBase):
        @rpc(M(T),
             _returns=UnsignedInteger32,
             _in_message_name='put_%s' % T_name,
             _in_variable_names={'obj': T_name})
        def put(ctx, obj):
            if obj.id is None:
                ctx.udc.session.add(obj)
                ctx.udc.session.flush()  # so that we get the obj.id value

            else:
                if ctx.udc.session.query(T).get(obj.id) is None:
                    # this is to prevent the client from setting the primary key
                    # of a new object instead of the database's own primary-key
                    # generator.
                    # Instead of raising an exception, you can also choose to
                    # ignore the primary key set by the client by silently doing
                    # obj.id = None in order to have the database assign the
                    # primary key the traditional way.
                    put_not_found(obj.id)

                else:
                    ctx.udc.session.merge(obj)

            return obj.id

        @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()
示例#2
0
    class ReaderService(ReaderServiceBase):
        @rpc(M(UnsignedInteger32),
             _returns=T,
             _in_message_name='get_%s' % T_name,
             _in_variable_names={'obj_id': "%s_id" % T_name})
        def get(ctx, obj_id):
            return ctx.udc.session.query(T).filter_by(id=obj_id).one()

        @rpc(_returns=Iterable(T), _in_message_name='get_all_%s' % T_name)
        def get_all(ctx):
            return ctx.udc.session.query(T).order_by(T.id)
示例#3
0
 class C(ComplexModel):
     __namespace__ = "aa"
     foo = XmlAttribute(M(Unicode))
示例#4
0
        class ExampleService(ServiceBase):
            __tns__ = 'http://xml.company.com/ns/example/'

            @rpc(M(Uuid), _returns=Unicode)
            def say_my_uuid(ctx, uuid):
                return 'Your UUID: %s' % uuid
示例#5
0
 class Action (ComplexModel):
     data = XmlAttribute(M(Unicode))
示例#6
0
 class C(ComplexModel):
     bar = XmlAttribute(M(Unicode))
示例#7
0
 class C(ComplexModel):
     foo = M(Unicode)
示例#8
0
 class SomeService(Service):
     @srpc(M(Unicode), _returns=Unicode)
     def some_call(s):
         assert s == 'hello'
         return s