class WebService(DefinitionBase): @soap(String, String, String, String, Integer, _returns=Array(String)) def reg(self, usr, pwd, name, sex_zh, group): info = user_reg(usr, pwd, name, sex_zh, group) return info @soap(String, String, _returns=String) def login(self, usr, pwd): info = user_log(usr, pwd)[0] return info @soap(String, String, _returns=Array(String)) def user(self, usr, pwd): info = user_log(usr, pwd)[1:4] return info @soap(String, String, _returns=Array(Array(String))) def files(self, usr, pwd): info = user_log(usr, pwd)[4] return info @soap(String, _returns=Array(String)) def read(self, file_name): info = file_read(file_name) return info @soap(String, Integer, String, String, _returns=Integer) def upload(self, usr, group, file_name, txt): info = file_upload(usr, group, file_name, txt) return info '''
class HospitalService(DefinitionBase): @soap(String, _returns=Array(Array(String))) def hospital(self, hospitalName): hospital_list, hospitalData, viewLocation = view_hospital(hospitalName) hospital_distance = hospital_distance_recom(hospitalData, viewLocation) hospital_list.append(hospital_distance) return hospital_list
class WebService(DefinitionBase): @soap(String, _returns=Integer) def search(self, username): info = user_search(username) return info @soap(String, String, _returns=Integer) def reg(self, username, token): info = register(username, token) return info @soap(String, String, _returns=Integer) def log(self, username, token): info = log_in(username, token) return info @soap(String, _returns=Array(Array(String))) def files(self, username): info = get_files(username) return info @soap(String, String, String, _returns=Integer) def upload(self, username, file_name, txt): info = file_upload(username, file_name, txt) return info @soap(String, String, _returns=Array(String)) def download(self, username, file_name): info = file_read(username, file_name) return info @soap(String, String) def delete(self, username, file_name): file_del(username, file_name)
class NestedClass(ClassModel): __namespace__ = "punk.tunk" simple = Array(SimpleClass) s = String i = Integer f = Float other = OtherClass ai = Array(Integer)
class HelloWorldService(DefinitionBase): @soap(String, Integer, _returns=Array(String)) def say_hello(self, name, times): results = [] for i in range(0, times): results.append('Hello, %s' % name) return results @soap(String, _returns=Array(String)) def helloWorld(self, hello): print hello return hello
class User(ClassModel): __namespace__ = "user" userid = Integer username = String firstname = String lastname = String permissions = Array(Permission)
class UserManager(DefinitionBase): @soap(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 @soap(Integer, _returns=User) def get_user(self, userid): global user_database return user_database[userid] @soap(User) def modify_user(self, user): global user_database user_database[user.userid] = user @soap(Integer) def delete_user(self, userid): global user_database del user_database[userid] @soap(_returns=Array(User)) def list_users(self): global user_database return [v for k, v in user_database.items()]
class MySOAPService(DefinitionBase): # @rpc(String, String, _returns=Boolean) # def Test(self, f1, f2): # return True # @rpc(String, _returns=String) # def HelloWorld(self, name): # return 'Hello %s!' %name # @rpc(Integer, _returns=Array(String)) # def getTopList(self, number): # top_list = ['dudu','cc','aa'] # return top_list @rpc(Integer, _returns=Array(Record)) def getTopList(self, number): top_list = [] rank_list = Rank.objects.all().order_by('time')[0:number] for rank in rank_list: record = Record() record.name = rank.name record.time = rank.time top_list.append(record) return top_list @rpc(Integer, _returns=Integer) def getRank(self, time): rank_list = Rank.objects.all().order_by('time') rank = 1 for record in rank_list: if record.time < time: rank += 1 return rank
class HelloWorldService(DefinitionBase): @soap(String, Integer, _returns=Array(String)) def say_hello(self, name, times): results = [] for i in range(0, times): results.append('Hello, %s' % name) return results @soap(Rules, _returns=Boolean) def get_recommend(self, rules): print rules.username print 111 print rules.emotion return 1 @soap(String, _returns=String) def get_hi(self, name): result = "hi," + name return result @soap(String, _returns=String) def get_graph(self, name): result = "hi," + name overfitGraph.save_graph(name) return result
class HelloWorldService(DefinitionBase): @soap(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 HotelService(DefinitionBase): @soap(String, Integer, _returns=Array(Array(String))) def hotel(self, hotelName, selNum): dataHotel, hotelList, viewpoint_location = view_hotel(hotelName) if selNum == 1: hotel_list = hotel_distance_recom(dataHotel, viewpoint_location) if selNum == 2: hotel_list = hotel_price_recom(dataHotel, viewpoint_location) if selNum == 3: hotel_list = hotel_rate_recom(dataHotel, viewpoint_location) if selNum == 4: hotel_list = hotel_best_recom(dataHotel, viewpoint_location) hotelList.append(hotel_list) return hotelList '''
class BudgetService(DefinitionBase): def __init__(self, user_id, *args, **kwargs): self.user_id = user_id super(BudgetService, self).__init__(*args, **kwargs) @soap(Integer, Array(String), Auth, _returns=String) def getBudget(self, order, tracks, auth): if is_valid_request(auth): thread.start_new_thread(calculate_budget_price, ( order, tracks, self.user_id, )) logger.info("%s Returning async request for getBudget" % (self.user_id, )) return "OK" @soap(Integer, Auth, _returns=String) def confirmBudget(self, order, auth): if is_valid_request(auth): thread.start_new_thread(set_status_order, ( order, self.user_id, )) logger.info("%s Returning sync request for confirmBudget" % (self.user_id, )) return "OK"
class WebService(DefinitionBase): ''' 图片上传与去重函数: 输入参数 图片ID,图像特征值密文1,图像特征值密文2,图像感知哈希,图像密文 返回值 上传成功:1 有同名图像:2 有重复图像:3 ''' @soap(String, String, String, String, String, _returns = Integer) def upload(self, image_id, feature1, feature2, dhash, ciphertext): info = image_upload_dedup(image_id, feature1, feature2, dhash, ciphertext) return info ''' 图片搜索函数: 输入参数 图像特征值密文1,图像特征值密文2 返回值 图像密文列表(15张) ''' @soap(String, String, _returns = Array(String)) def search(self, feature1, feature2): info = image_search( feature1, feature2) return info
class RestService(DefinitionBase): @soap(String, Integer, _returns=Array(Array(String))) def rest(self, hotelName, selNum): print hotelName restList, hotelLocation, restraurantData = selHotel(hotelName) #print restList if selNum == 1: rest_list = rest_distance_recom(restraurantData, hotelLocation) if selNum == 2: rest_list = rest_price_recom(restraurantData, hotelLocation) if selNum == 3: rest_list = rest_rate_recom(restraurantData, hotelLocation) if selNum == 4: rest_list = rest_best_recom(restraurantData, hotelLocation) restList.append(rest_list) print restList return restList
class webserver(DefinitionBase): @soap(String, String, _returns=Array(Integer)) def panDuanTimeAndDept(self, date_time, department): time_flag = 0 time_delta = (datetime.strptime(date_time, "%Y-%m-%d") - datetime.now()).days + 1 if time_delta > 0 and time_delta < 3: time_flag = 1 department_flag = 0 yuyue_info = pickle.load(open('data/data', 'r')) print yuyue_info if yuyue_info[department] == '': department_flag = 1 return [time_flag, department_flag] @soap(String, String, String, _returns=Array(Integer)) def response(self, type, shouji, department): if type == 'yuyue': geshi_flag = 1 if re.match(r'((13[0-9])|(14[5,7])|(15[0-3,5-9])|(17[0,3,5-8])|(18[0-9])|166|198|199|(147))\d{8}$', shouji) else 0 yuyue_info = pickle.load(open('data/data', 'r')) shouji_flag = 1 if shouji not in yuyue_info.values() else 0 if geshi_flag and shouji_flag: yuyue_info[department] = shouji data = open('data/data', 'w') pickle.dump(yuyue_info, data) data.close() elif type == 'quxiaoyuyue': geshi_flag = 1 if re.match(r'((13[0-9])|(14[5,7])|(15[0-3,5-9])|(17[0,3,5-8])|(18[0-9])|166|198|199|(147))\d{8}$', shouji) else 0 yuyue_info = pickle.load(open('data/data', 'r')) shouji_flag = 1 if shouji in yuyue_info.values() else 0 if geshi_flag and shouji_flag: if yuyue_info['neike'] == shouji: yuyue_info['neike'] = '' print 'neike' elif yuyue_info['waike'] == shouji: yuyue_info['waike'] = '' print 'waike' print yuyue_info data = open('data/data', 'w') pickle.dump(yuyue_info, data) data.close() return [geshi_flag, shouji_flag]
class CalculationService(DefinitionBase): @soap(String, _returns=Array(String)) def call_math_function(self, number): rezults = check_output( ["C:\Users\Shakirov Farit\Desktop\math_function.exe", number]).split('\r\n') rezults.pop() return rezults
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 CreateMetall(DefinitionBase): @soap(Integer, Integer, Integer, Integer, _returns=Array(Integer)) def add(self, height, width, depth, weight): global result result = [height, width, depth, weight] @soap(_returns=Array(Integer)) def view(self): return result @soap(String_returns=Integer) def density(self): density = result[3] / (result[0] * result[1] * result[2]) return density @soap(String, _returns=Integer) def cubage(self): cubage = result[0] * result[1] * result[2] return cubage
class EodWorldService(DefinitionBase): @soap(String, Integer, _returns=Array(String)) def say_hello(self, name, times): results = [] for i in range(0, times): results.append('Hello, %s' % name) return results # @soap(String, _returns=String) # def algo_file_build_server(self, pf_account_plan_str): # algo_file_build_server(pf_account_plan_str) # return 'algo file build success' @soap(String, _returns=String) def query_strategy_info(self, strategy_name): return query_strategy_info(strategy_name) @soap(String, _returns=Array(String)) def query_strategy_money_long(self, strategy_name): return query_strategy_money_long(strategy_name)
class TripService(DefinitionBase): @soap(String, _returns=Array(Array(String))) def trip_name(self, city_Name): print city_Name tripName = tripRecom(city_Name) #dict = [['Name:小明','Age18'],['Name:小方','Age20']] print tripName return tripName @soap(_returns=String) def trip_season(self): import datetime now_time = datetime.datetime.now() dictSeason = { "wangji": ['06', '07', '08'], "danji": ['01', '02', '03', '04', '05', '09', '10', '11', '12'] } dataMonth = datetime.datetime.now().strftime('%m') for i in dictSeason.keys(): if dataMonth in dictSeason[i]: return i
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): @soap(SimpleClass, _returns=SimpleClass) def echo_simple_class(self, sc): return sc @soap(Array(SimpleClass), _returns=Array(SimpleClass)) def echo_simple_class_array(self, sca): return sca @soap(NestedClass, _returns=NestedClass) def echo_nested_class(self, nc): return nc @soap(Array(NestedClass), _returns=Array(NestedClass)) def echo_nested_class_array(self, nca): return nca @soap(ExtensionClass, _returns=ExtensionClass) def echo_extension_class(self, nc): return nc @soap(Attachment, _returns=Attachment) def echo_attachment(self, a): return a @soap(Array(Attachment), _returns=Array(Attachment)) def echo_attachment_array(self, aa): return aa
class HelloWorldService(DefinitionBase): @soap(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
class InvoiceReturnService(DefinitionBase): @soap(Array(Confirmation), _returns=ResInfo) def invoice_return(self, confirmation_list): try: print confirmation_list res = ResInfo() res.confirmation_id = 1 res.status = 'Y' res.detail = u'正常' except Exception, e: print str(e) res = ResInfo() res.confirmation_id = 0 res.status = 'N' res.detail = str(e) return res
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)
class AdditionService(DefinitionBase): @soap(Integer, Integer, _returns=String) #関数を定義する前に、必ずこの様なパラメータ値のタイプを指定しなければならない def addition(self, a, b): return str(a) + '+' + str(b) + '=' + str(a+b) #ブロックがインデントで別けます @soap(_returns=Array(String)) def GetCdrArray(self): L_Result = ["1", "2", "3"] return L_Result @soap(_returns=C_ProbeCdrModel) def GetCdr(self): L_Model = C_ProbeCdrModel() L_Model.Name = L_Model.Name L_Model.Id = L_Model.Id return L_Model
class AdditionService(DefinitionBase): #this is a web service @soap(Integer, Integer, _returns=String) def addition(self, a, b): print 'aaaaaaaaaaaa' return str(a) + '+' + str(b) + '=' + str(a + b) @soap(_returns=Array(String)) def GetCdrArray(self): print 'bbbbbbbbbb' L_Result = ["1", "2", "3"] return L_Result @soap(_returns=C_ProbeCdrModel) def GetCdr(self): print 'ccccccc' L_Model = C_ProbeCdrModel() L_Model.Name = L_Model.Name L_Model.Id = L_Model.Id return L_Model
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)
class InteropMisc(service.DefinitionBase): @soap(_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"]] @soap() def huge_number(_returns=Integer): return 2**int(1e5) @soap() def long_string(_returns=String): return len('0123456789abcdef' * 16384) @soap() def test_empty(self): pass @soap(String, Integer, DateTime) def multi_param(self, s, i, dt): pass @soap(_returns=String) def return_only(self): return 'howdy' @soap(NonNillableClass, _returns=String) def non_nillable(self, n): return "OK" @soap(String, _returns=String, _public_name="do_something") def do_something_else(self, s): return s
class UserManager(DefinitionBase): __service_interface__ = "UserManager" __port_types__ = ["user_services"] @soap(User, _returns=Integer, _port_type="user_services") def add_user(self, user): global user_database global userid_seq user.userid = userid_seq userid_seq += 1 user_database[user.userid] = user return user.userid @soap(Integer, _returns=User, _port_type="user_services") def get_user(self, userid): global user_database return user_database[userid] @soap(User, _port_type="user_services") def modify_user(self, user): global user_database user_database[user.userid] = user @soap(Integer, _port_type="user_services") def delete_user(self, userid): global user_database del user_database[userid] @soap(_returns=Array(User), _port_type="user_services") def list_users(self): global user_database return [v for k, v in user_database.items()]
class HelloWorldService(DefinitionBase): @soap(String, Integer, _returns=Array(String)) def say_hello(self, name, times): print name,times results = [] for i in range(0, times): results.append('Hello, %s' % times) return results @soap(String, Integer) def auth(self,username,password): print "auth",username,password if username=="admin" and password==123: token="token:abc123" return 1 else: return "Wrong username or password" @soap(Integer,_returns=String) def example(self,x): print "auth",x if x==123: token="token:abc123" return token else: return "Wrong username or password"
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))