[Zope-Checkins] CVS: Zope3/lib/python/SOAPpy/tests - alanbushTest.py:1.1.2.1 cardClient.py:1.1.2.1 cardServer.py:1.1.2.1 fortuneTest.py:1.1.2.1 guidTest.py:1.1.2.1 itimeTest.py:1.1.2.1 newsTest.py:1.1.2.1 quoteTest.py:1.1.2.1 quoteTest1.py:1.1.2.1 quoteTest2.py:1.1.2.1 storageTest.py:1.1.2.1 translateTest.py:1.1.2.1 weatherTest.py:1.1.2.1 whoisTest.py:1.1.2.1 wordFindTest.py:1.1.2.1
Stephan Richter
srichter@cbu.edu
Wed, 13 Mar 2002 11:39:34 -0500
Update of /cvs-repository/Zope3/lib/python/SOAPpy/tests
In directory cvs.zope.org:/tmp/cvs-serv1678/SOAPpy/tests
Added Files:
Tag: srichter-OFS_Formulator-branch
alanbushTest.py cardClient.py cardServer.py fortuneTest.py
guidTest.py itimeTest.py newsTest.py quoteTest.py
quoteTest1.py quoteTest2.py storageTest.py translateTest.py
weatherTest.py whoisTest.py wordFindTest.py
Log Message:
- Switched to SOAPpy library.
- Made the first action in XUL work.
This checkin is primary for people that want to look at the code. I will
probably replace SOAPpy with Brian Lloyd's SOAP implementation later today,
since I have no approval to use SOAPpy in Zope 3 and Brian's stuff is
already ZPL 2.0.
=== Added File Zope3/lib/python/SOAPpy/tests/alanbushTest.py ===
#!/usr/bin/env python
# Copyright (c) 2001 actzero, inc. All rights reserved.
import sys
sys.path.insert (1, '..')
import SOAP
ident = '$Id: alanbushTest.py,v 1.1.2.1 2002/03/13 16:39:33 srichter Exp $'
SoapEndpointURL = 'http://www.alanbushtrust.org.uk/soap/compositions.asp'
MethodNamespaceURI = 'urn:alanbushtrust-org-uk:soap.methods'
SoapAction = MethodNamespaceURI + ".GetCategories"
server = SOAP.SOAPProxy( SoapEndpointURL, namespace=MethodNamespaceURI, soapaction=SoapAction )
for category in server.GetCategories():
print category
=== Added File Zope3/lib/python/SOAPpy/tests/cardClient.py ===
#!/usr/bin/env python
# Copyright (c) 2001 actzero, inc. All rights reserved.
import sys
sys.path.insert (1, '..')
import SOAP
ident = '$Id: cardClient.py,v 1.1.2.1 2002/03/13 16:39:33 srichter Exp $'
endpoint = "http://localhost:12027/xmethodsInterop"
sa = "urn:soapinterop"
ns = "http://soapinterop.org/"
serv = SOAP.SOAPProxy(endpoint, namespace=ns, soapaction=sa)
try: hand = serv.dealHand(NumberOfCards = 13, StringSeparator = '\n')
except: print "no dealHand"; hand = 0
try: sortedhand = serv.dealArrangedHand(NumberOfCards=13,StringSeparator='\n')
except: print "no sorted"; sortedhand = 0
try: card = serv.dealCard()
except: print "no card"; card = 0
print "*****hand****\n",hand,"\n*********"
print "******sortedhand*****\n",sortedhand,"\n*********"
print "card:",card
=== Added File Zope3/lib/python/SOAPpy/tests/cardServer.py ===
#!/usr/bin/env python
# Copyright (c) 2001 actzero, inc. All rights reserved.
import string
import sys
sys.path.insert (1, '..')
import SOAP
ident = '$Id: cardServer.py,v 1.1.2.1 2002/03/13 16:39:33 srichter Exp $'
# create the list of all cards, and keep strings for each suit
__cs = "Clubs"
__ds = "Diamonds"
__hs = "Hearts"
__ss = "Spades"
__cards = []
for suit in [__cs, __ds, __hs, __ss]:
for num in range(9):
num += 1
__cards.append(str(num+1)+" of "+suit)
for face in ["ace","King","Queen","Jack"]:
__cards.append(face+" of "+suit)
def deal(num):
if num not in range(1,53):
return -1
else:
alreadydealt = []
ignore = 0
handdealt = []
import whrandom
while num > 0:
idx = int(str(whrandom.random())[2:4])
if idx in range(52) and idx not in alreadydealt:
handdealt.append(__cards[idx])
alreadydealt.append(idx)
num -= 1
else:
ignore += 1
continue
return handdealt
def arrangeHand(hand):
c = []
d = []
h = []
s = []
import string
for card in hand:
if string.find(card, __cs) != -1:
c.append(card)
elif string.find(card, __ds) != -1:
d.append(card)
elif string.find(card, __hs) != -1:
h.append(card)
elif string.find(card, __ss) != -1:
s.append(card)
for cards, str in ((c, __cs),(d, __ds),(h,__hs), (s,__ss)):
cards.sort()
idx = 0
if "10 of "+str in cards:
cards.remove("10 of "+str)
if "Jack of "+str in cards: idx += 1
if "Queen of "+str in cards: idx += 1
if "King of "+str in cards: idx += 1
if "ace of "+str in cards: idx +=1
cards.insert(len(cards)-idx,"10 of "+str)
if "King of "+str in cards:
cards.remove("King of "+str)
if "ace of "+str in cards: cards.insert(len(cards)-1,"King of "+str)
else: cards.append("King of "+str)
return c+d+h+s
def dealHand (NumberOfCards, StringSeparator):
hand = deal(NumberOfCards)
return string.join(hand,StringSeparator)
def dealArrangedHand (NumberOfCards, StringSeparator):
if NumberOfCards < 1 or NumberOfCards > 52:
raise ValueError, "NumberOfCards must be between 1 and 52"
unarranged = deal(NumberOfCards)
hand = arrangeHand(unarranged)
return string.join(hand, StringSeparator)
def dealCard ():
return deal(1)[0]
namespace = 'http://soapinterop.org/'
server = SOAP.SOAPServer (("localhost", 12027))
server.registerKWFunction (dealHand, namespace)
server.registerKWFunction (dealArrangedHand, namespace)
server.registerKWFunction (dealCard, namespace)
try:
server.serve_forever()
except KeyboardInterrupt:
pass
=== Added File Zope3/lib/python/SOAPpy/tests/fortuneTest.py ===
#!/usr/bin/env python
# Copyright (c) 2001 actzero, inc. All rights reserved.
import sys
sys.path.insert (1, '..')
import SOAP
ident = '$Id: fortuneTest.py,v 1.1.2.1 2002/03/13 16:39:33 srichter Exp $'
SoapEndpointURL = 'http://www.lemurlabs.com/rpcrouter'
MethodNamespaceURI = 'urn:lemurlabs-Fortune'
server = SOAP.SOAPProxy(SoapEndpointURL, namespace = MethodNamespaceURI,
encoding = None)
print server.getAnyFortune()
=== Added File Zope3/lib/python/SOAPpy/tests/guidTest.py ===
#!/usr/bin/env python
# Copyright (c) 2001 actzero, inc. All rights reserved.
import sys
sys.path.insert (1, '..')
import SOAP
ident = '$Id: guidTest.py,v 1.1.2.1 2002/03/13 16:39:33 srichter Exp $'
# Three ways to do namespaces, force it at the server level
server = SOAP.SOAPProxy("http://www.itfinity.net:8008/soap/guid/default.asp",
namespace="http://www.itfinity.net/soap/guid/guid.xsd")
print "GUID>>", server.NextGUID()
=== Added File Zope3/lib/python/SOAPpy/tests/itimeTest.py ===
#!/usr/bin/env python
# Copyright (c) 2001 actzero, inc. All rights reserved.
import sys
sys.path.insert (1, '..')
import SOAP
SoapEndpointURL = 'http://www.lemurlabs.com/rpcrouter'
MethodNamespaceURI = 'urn:lemurlabs-ITimeService'
server = SOAP.SOAPProxy(SoapEndpointURL, namespace = MethodNamespaceURI,
encoding = None)
print server.getInternetTime()
=== Added File Zope3/lib/python/SOAPpy/tests/newsTest.py ===
#!/usr/bin/env python
# Copyright (c) 2001 actzero, inc. All rights reserved.
import sys
sys.path.insert (1, '..')
import SOAP
ident = '$Id: newsTest.py,v 1.1.2.1 2002/03/13 16:39:33 srichter Exp $'
SoapEndpointURL = 'http://aspx.securewebs.com/prasadv/BreakingNewsService.asmx'
MethodNamespaceURI = 'http://tempuri.org/'
# Three ways to do namespaces, force it at the server level
server = SOAP.SOAPProxy(SoapEndpointURL, namespace = MethodNamespaceURI,
soapaction='http://tempuri.org/GetCNNNews', encoding = None)
print "[server level CNN News call]"
print server.GetCNNNews()
# Do it inline ala SOAP::LITE, also specify the actually ns (namespace) and
# sa (soapaction)
server = SOAP.SOAPProxy(SoapEndpointURL, encoding = None)
print "[inline CNNNews call]"
print server._ns('ns1',
MethodNamespaceURI)._sa('http://tempuri.org/GetCNNNews').GetCNNNews()
# Create an instance of your server with specific namespace and then use
# inline soapactions for each call
dq = server._ns(MethodNamespaceURI)
print "[namespaced CNNNews call]"
print dq._sa('http://tempuri.org/GetCNNNews').GetCNNNews()
print "[namespaced CBSNews call]"
print dq._sa('http://tempuri.org/GetCBSNews').GetCBSNews()
=== Added File Zope3/lib/python/SOAPpy/tests/quoteTest.py ===
#!/usr/bin/env python
# Copyright (c) 2001 actzero, inc. All rights reserved.
import sys
sys.path.insert (1, '..')
import SOAP
ident = '$Id: quoteTest.py,v 1.1.2.1 2002/03/13 16:39:33 srichter Exp $'
# Three ways to do namespaces, force it at the server level
server = SOAP.SOAPProxy("http://services.xmethods.com:80/soap",
namespace = 'urn:xmethods-delayed-quotes')
print "IBM>>", server.getQuote(symbol = 'IBM')
# Do it inline ala SOAP::LITE, also specify the actually ns
server = SOAP.SOAPProxy("http://services.xmethods.com:80/soap")
print "IBM>>", server._ns('ns1',
'urn:xmethods-delayed-quotes').getQuote(symbol = 'IBM')
# Create a namespaced version of your server
dq = server._ns('urn:xmethods-delayed-quotes')
print "IBM>>", dq.getQuote(symbol='IBM')
print "ORCL>>", dq.getQuote(symbol='ORCL')
print "INTC>>", dq.getQuote(symbol='INTC')
=== Added File Zope3/lib/python/SOAPpy/tests/quoteTest1.py ===
#!/usr/bin/env python
import sys
sys.path.insert (1, '..')
import SOAP
ident = '$Id: quoteTest1.py,v 1.1.2.1 2002/03/13 16:39:33 srichter Exp $'
# http://www.durrios.com/Finance.wsdl
server = SOAP.SOAPProxy('http://www.durrios.com/soap/finance.cgi',
namespace = 'http://www.durrios.com/Finance')
symbol='SUNW'
print symbol, "-> close ", server.stockquote_lasttrade(symbol=symbol), \
" volume ", server.stockquote_volume(symbol=symbol)
=== Added File Zope3/lib/python/SOAPpy/tests/quoteTest2.py ===
#!/usr/bin/env python
import sys
sys.path.insert (1, '..')
import SOAP
ident = '$Id: quoteTest2.py,v 1.1.2.1 2002/03/13 16:39:33 srichter Exp $'
# http://www.mybubble.com:8080/mybubbleEntServer/MyBubbleSoapServices.wsdl
server = SOAP.SOAPProxy('http://www.mybubble.com:8080/soap/servlet/rpcrouter',
namespace='urn:MyBubble-SoapServices',
config=SOAP.SOAPConfig(argsOrdering={"login":("userName", "authenticationToken")}))
symbol='SUNW'
loginToken=server.login(userName='wsguest', authenticationToken='pass')
print server.getServiceResponse(loginToken=loginToken, serviceName="StockQuote", inputText=symbol)
server.logout(logintoken=loginToken)
=== Added File Zope3/lib/python/SOAPpy/tests/storageTest.py ===
#!/usr/bin/env python
# Copyright (c) 2001 actzero, inc. All rights reserved.
import sys, os, time, signal
sys.path.insert (1, '..')
import SOAP
ident = '$Id: storageTest.py,v 1.1.2.1 2002/03/13 16:39:33 srichter Exp $'
#PROXY="http://data.ourfavoritesongs.com"
PROXY="http://localhost:15500"
EMAIL="bennett@actzero.com"
NAME="Bennett"
PASSWORD="mypasswd"
MY_PORT=15600
def resourceChanged (url):
print "\n##### NOTIFICATION MESSAGE: Resource %s has changed #####\n" % url
return SOAP.booleanType(1)
def printstatus (cmd, stat):
print
if stat.flError:
print "### %s failed: %s ###" % (cmd, stat.message)
else:
print "### %s successful: %s ###" % (cmd, stat.message)
return not stat.flError
server = SOAP.SOAPProxy(encoding="US-ASCII",
proxy=PROXY,
soapaction="/xmlStorageSystem"
)
# , config=SOAP.SOAPConfig(debug=1))
# Register as a new user or update user information
reg = server.registerUser(email=EMAIL, name=NAME, password=PASSWORD, clientPort=MY_PORT, userAgent=SOAP.SOAPUserAgent())
printstatus("registerUser", reg)
# See what this server can do
reg = server.getServerCapabilities (email=EMAIL, password=PASSWORD)
if printstatus("getServerCapabilities", reg):
print "Legal file extensions: " + str(reg.legalFileExtensions)
print "Maximum file size: " + str(reg.maxFileSize)
print "Maximum bytes per user: " + str(reg.maxBytesPerUser)
print "Number of bytes in use by the indicated user: " + str(reg.ctBytesInUse)
print "URL of the folder containing your files: " + str(reg.yourUpstreamFolderUrl)
# Store some files
reg = server.saveMultipleFiles (email=EMAIL, password=PASSWORD,
relativepathList=['index.html','again.html'],
fileTextList=['<html><title>bennett@actzero.com home page</title><body>' +
'<a href=again.html>Hello Earth</a></body></html>',
'<html><title>bennett@actzero.com home page</title><body>' +
'<a href=index.html>Hello Earth Again</a></body></html>'])
if printstatus("saveMultipleFiles", reg):
print "Files stored:"
for file in reg.urlList:
print " %s" % file
# Save this for call to test pleaseNotify
mylist = reg.urlList
else:
mylist = []
# Check to see what files are stored
reg = server.getMyDirectory (email=EMAIL, password=PASSWORD)
if printstatus("getMyDirectory", reg):
i = 1
while hasattr(reg.directory, "file%05d" % i):
d = getattr(reg.directory, "file%05d" % i)
print "Relative Path: %s" % d.relativePath
print "Size: %d" % d.size
print "Created: %s" % d.whenCreated
print "Last Uploaded: %s" % d.whenLastUploaded
print "URL: %s" % d.url
print
i += 1
# Set up notification
reg = server.pleaseNotify(notifyProcedure="resourceChanged", port=MY_PORT, path="/", protocol="soap", urlList=mylist)
printstatus("notifyProcedure", reg)
pid = os.fork()
if pid == 0:
# I am a child process. Set up SOAP server to receive notification
print
print "## Starting notification server ##"
s = SOAP.SOAPServer(('localhost', MY_PORT))
s.registerFunction(resourceChanged)
s.serve_forever()
else:
def handler(signum, frame):
# Kill child process
print "Killing child process %d" % pid
os.kill(pid, signal.SIGINT)
signal.signal(signal.SIGINT, handler)
# I am a parent process
# Change some files
time.sleep(3)
reg = server.saveMultipleFiles (email=EMAIL, password=PASSWORD,
relativepathList=['index.html'],
fileTextList=['<html><title>bennett@actzero.com home page</title><body>' +
'<a href=again.html>Hello Bennett</a></body></html>'])
if printstatus("saveMultipleFiles", reg):
print "Files stored:"
for file in reg.urlList:
print " %s" % file
os.waitpid(pid, 0)
=== Added File Zope3/lib/python/SOAPpy/tests/translateTest.py ===
#!/usr/bin/env python
# Copyright (c) 2001 actzero, inc. All rights reserved.
import sys
sys.path.insert (1, '..')
import SOAP
ident = '$Id: translateTest.py,v 1.1.2.1 2002/03/13 16:39:33 srichter Exp $'
server = SOAP.SOAPProxy("http://services.xmethods.com:80/perl/soaplite.cgi")
babel = server._ns('urn:xmethodsBabelFish#BabelFish')
print babel.BabelFish(translationmode = "en_fr",
sourcedata = "The quick brown fox did something or other")
=== Added File Zope3/lib/python/SOAPpy/tests/weatherTest.py ===
#!/usr/bin/env python
# Copyright (c) 2001 actzero, inc. All rights reserved.
import sys
sys.path.insert (1, '..')
import SOAP
ident = '$Id: weatherTest.py,v 1.1.2.1 2002/03/13 16:39:33 srichter Exp $'
SoapEndpointURL = 'http://services.xmethods.net/soap/servlet/rpcrouter'
MethodNamespaceURI = 'urn:xmethods-Temperature'
# Do it inline ala SOAP::LITE, also specify the actually ns
server = SOAP.SOAPProxy(SoapEndpointURL)
print "inline", server._ns('ns1', MethodNamespaceURI).getTemp(zipcode='94063')
=== Added File Zope3/lib/python/SOAPpy/tests/whoisTest.py ===
#!/usr/bin/env python
# Copyright (c) 2001 actzero, inc. All rights reserved.
import sys
sys.path.insert (1, '..')
import SOAP
ident = '$Id: whoisTest.py,v 1.1.2.1 2002/03/13 16:39:33 srichter Exp $'
server = SOAP.SOAPProxy("http://soap.4s4c.com/whois/soap.asp",
namespace = "http://www.pocketsoap.com/whois")
print "whois>>", server.whois(name = "actzero.com")
=== Added File Zope3/lib/python/SOAPpy/tests/wordFindTest.py ===
import sys
sys.path.insert (1, '..')
import SOAP
def usage():
print sys.argv[0], "searchString"
print '''\tcurrently, this can be used to search for word completions or
anagrams- the function will parse and perform the word-search function if
there is a "?" or "*" character, and perform the anagram-search function
otherwise'''
sys.exit(1)
if len(sys.argv) < 2: usage()
ss = sys.argv[1]
if ss.find('?') > -1 or ss.find('*') > -1: word=1
else: word=0
#SOAP.Config.debug = 1
serv = SOAP.SOAPProxy("http://webservices.matlus.com/scripts/WordFind.DLL/soap/IWordFind", namespace="urn:WordFindIntf-IWordFind", soapaction="urn:WordFindIntf-IWordFind#FindWords")
if word: print serv.FindWords(Source=ss)
else:
serv._sa= ""
print serv.FindAnagrams(Source=ss)