# -*- coding: utf-8 from SOAPpy import SOAPProxy from SOAPpy import Types from SOAPpy import Config import re import sys import cElementTree import random #url = "http://opah.htk.tlu.ee:8080/WaramuWeb/waramuService" #url = "http://opah:8080/waramuService/waramu" url = "http://localhost:8080/waramuService/waramu" #url = "http://localhost:8080/WaramuWeb/waramuService" namespace= "http://wssoap.waramu.htk.tlu.ee/" username='admin' password='adminadmin' #username='vahur' #password='parool' c = Config c.debug = 0 s = SOAPProxy(url, config=c) # ======= Login in sessIdresponse = s._ns(namespace).newSession(uid=username, pwd=password) respCode = int(re.search('(.*?)', sessIdresponse).group(1)) if respCode: # not 0 msg = re.search('(.*?)', sessIdresponse).group(1) print msg sys.exit(); sessId = re.search('(.*?)', sessIdresponse).group(1) print "Session id:", sessId # ======= search def _search(qqs): print "\nSearching and listing objects." searchquery = "\n"+qqs print "Query:", searchquery searchResponse = s._ns(namespace).search(sessId = sessId, query = searchquery) searchResponse = searchResponse.encode('utf-8') xml = cElementTree.fromstring(searchResponse) respCode = int(xml.find('status').text) if respCode: # not 0 msg = xml.find('message').text print "Search failed. Reason: %s" % msg else: ids = xml.findall('objects/object') print "Number of results:", len(ids) queries = [ "kala", "sai", "kala", "<_fulltext>kunst" ] print "\nTwo search calls MUST fail!" for qq in queries: _search(qq) # ======= Logging out print "\nEnd. Bye-bye." logoutResponse = s._ns(namespace).closeSession(sessId=sessId) respCode = int(re.search('(.*?)', logoutResponse).group(1)) if respCode: msg = re.search('(.*?)', logoutResponse).group(1) print "Logout failed. Reason:", msg else: print "Logout successful"