class Person(ClassSerializer): __namespace__ = "TestService" name = String birthdate = DateTime age = Integer addresses = Array(Address) titles = Array(String)
class NestedClass(ClassSerializer): __namespace__ = "punk.tunk" simple = Array(SimpleClass) s = String i = Integer f = Float other = OtherClass ai = Array(Integer)
class HelloWorldService(DefinitionBase): @rpc(Attachment, Integer, _returns=Array(String), _mtom=True) def say_hello(self, name, times): results = [] for i in range(0, times): results.append('Hello, %s' % name.data) return results
class User(ClassSerializer): __namespace__ = "user" userid = Integer username = String firstname = String lastname = String permissions = Array(Permission)
class UserManager(DefinitionBase): @rpc(User, _returns=Integer) def add_user(self, user): global user_database global userid_seq user.userid = userid_seq userid_seq = userid_seq + 1 user_database[user.userid] = user return user.userid @rpc(Integer, _returns=User) def get_user(self, userid): global user_database return user_database[userid] @rpc(User) def modify_user(self, user): global user_database user_database[user.userid] = user @rpc(Integer) def delete_user(self, userid): global user_database del user_database[userid] @rpc(_returns=Array(User)) def list_users(self): global user_database return [v for k, v in user_database.items()]
class InteropMisc(service.DefinitionBase): @rpc(_returns=[ Integer, String, Integer, Array(Enum("MEMBER", type_name="RoleEnum")) ], _out_variable_names=[ 'resultCode', 'resultDescription', 'transactionId', 'roles' ]) def complex_return(self): return [1, "Test", 123, ["MEMBER"]] @rpc() def huge_number(_returns=Integer): return 2**int(1e5) @rpc() def long_string(_returns=String): return len('0123456789abcdef' * 16384) @rpc() def test_empty(self): pass @rpc(String, Integer, DateTime) def multi_param(self, s, i, dt): pass @rpc(_returns=String) def return_only(self): return 'howdy' @rpc(NonNillableClass, _returns=String) def non_nillable(self, n): return "OK" @rpc(String, _returns=String, _public_name="do_something") def do_something_else(self, s): return s @rpc(Integer, _returns=Array(OtherClass)) def return_other_class_array(self, num): for i in xrange(num): yield OtherClass(dt=datetime(2010, 12, 06), d=3.0, b=True) @rpc(_returns=Attachment) def return_binary_data(self): return Attachment(data=''.join([chr(i) for i in xrange(256)]))
def test_class_nested_array(self): peeps = [] names = ['bob', 'jim', 'peabody', 'mumblesleves'] for name in names: a = Person() a.name = name a.birthdate = datetime.datetime(1979, 1, 1) a.age = 27 a.addresses = [] for i in range(0, 25): addr = Address() addr.street = '555 downtown' addr.city = 'funkytown' a.addresses.append(addr) peeps.append(a) type = Array(Person) type.resolve_namespace(type, __name__) element = etree.Element('test') type.to_parent_element(peeps, ns_test, element) element = element[0] self.assertEquals(4, len(element.getchildren())) peeps2 = type.from_xml(element) for peep in peeps2: self.assertEquals(27, peep.age) self.assertEquals(25, len(peep.addresses)) self.assertEquals('funkytown', peep.addresses[18].city)
class InteropClass(service.DefinitionBase): @rpc(SimpleClass, _returns=SimpleClass) def echo_simple_class(self, sc): return sc @rpc(Array(SimpleClass), _returns=Array(SimpleClass)) def echo_simple_class_array(self, sca): return sca @rpc(NestedClass, _returns=NestedClass) def echo_nested_class(self, nc): return nc @rpc(Array(NestedClass), _returns=Array(NestedClass)) def echo_nested_class_array(self, nca): return nca @rpc(ExtensionClass, _returns=ExtensionClass) def echo_extension_class(self, nc): return nc @rpc(Attachment, _returns=Attachment) def echo_attachment(self, a): assert isinstance(a, Attachment) return a @rpc(Array(Attachment), _returns=Array(Attachment)) def echo_attachment_array(self, aa): return aa
def test_class_nested_array(self): peeps = [] names = ['bob', 'jim', 'peabody', 'mumblesleves'] for name in names: a = Person() a.name = name a.birthdate = datetime.datetime(1979, 1, 1) a.age = 27 a.addresses = [] for i in range(0, 25): addr = Address() addr.street = '555 downtown' addr.city = 'funkytown' a.addresses.append(addr) peeps.append(a) type = Array(Person) type.resolve_namespace(type,__name__) element = etree.Element('test') type.to_parent_element(peeps, ns_test, element) element = element[0] self.assertEquals(4, len(element.getchildren())) peeps2 = type.from_xml(element) for peep in peeps2: self.assertEquals(27, peep.age) self.assertEquals(25, len(peep.addresses)) self.assertEquals('funkytown', peep.addresses[18].city)
class HelloWorldService(DefinitionBase): @rpc(String, Integer, _returns=Array(String)) def say_hello(self, name, times): '''Docstrings for service methods appear as documentation in the wsdl. @param name the name to say hello to @param the number of times to say hello @return the completed array ''' results = [] for i in range(0, times): results.append('Hello, %s' % name) return results
def test_array_empty(self): type = Array(String) type.resolve_namespace(type, "zbank") values = [] element = etree.Element('test') type.to_parent_element(values, ns_test, element) element = element[0] self.assertEquals(len(values), len(element.getchildren())) values2 = type.from_xml(element) self.assertEquals(len(values2), 0)
def test_array_empty(self): type = Array(String) type.resolve_namespace(type,"zbank") values = [] element = etree.Element('test') type.to_parent_element(values, ns_test, element) element = element[0] self.assertEquals(len(values), len(element.getchildren())) values2 = type.from_xml(element) self.assertEquals(len(values2), 0)
def test_class_array(self): peeps = [] names = ['bob', 'jim', 'peabody', 'mumblesleves'] for name in names: a = Person() a.name = name a.birthdate = datetime.datetime(1979, 1, 1) a.age = 27 peeps.append(a) type = Array(Person) type.resolve_namespace(type, __name__) element = etree.Element('test') type.to_parent_element(peeps, ns_test, element) element = element[0] self.assertEquals(4, len(element.getchildren())) peeps2 = type.from_xml(element) for i in range(0, 4): self.assertEquals(peeps2[i].name, names[i]) self.assertEquals(peeps2[i].birthdate, datetime.datetime(1979, 1, 1))
def test_class_array(self): peeps = [] names = ['bob', 'jim', 'peabody', 'mumblesleves'] for name in names: a = Person() a.name = name a.birthdate = datetime.datetime(1979, 1, 1) a.age = 27 peeps.append(a) type = Array(Person) type.resolve_namespace(type,__name__) element = etree.Element('test') type.to_parent_element(peeps, ns_test, element) element = element[0] self.assertEquals(4, len(element.getchildren())) peeps2 = type.from_xml(element) for i in range(0, 4): self.assertEquals(peeps2[i].name, names[i]) self.assertEquals(peeps2[i].birthdate, datetime.datetime(1979, 1, 1))
class InteropArray(service.DefinitionBase): @rpc(Array(Integer), _returns=Array(Integer)) def echo_integer_array(self, ia): return ia @rpc(Array(String), _returns=Array(String)) def echo_string_array(self, sa): return sa @rpc(Array(DateTime), _returns=Array(DateTime)) def echo_date_time_array(self, dta): return dta @rpc(Array(Float), _returns=Array(Float)) def echo_float_array(self, fa): return fa @rpc(Array(Double), _returns=Array(Double)) def echo_double_array(self, da): return da @rpc(Array(Boolean), _returns=Array(Boolean)) def echo_boolean_array(self, ba): return ba @rpc(Boolean(max_occurs="unbounded"), _returns=Boolean(max_occurs="unbounded")) def echo_simple_boolean_array(self, ba): return ba @rpc(Array(Boolean), _returns=Array(Array(Boolean))) def echo_array_in_array(self, baa): return baa
class Level1(ClassSerializer): level2 = Level2 level3 = Array(Level3) level4 = Array(Level4)
class Person(ClassSerializer): name = String birthdate = DateTime age = Integer addresses = Array(Address) titles = Array(String)