A fork of https://github.com/Synerty/SOAPpy-py3 This is a working tree till fixes get imported upstream.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

127 lines
4.0 KiB

  1. #!/usr/bin/env python
  2. ident = '$Id: storageTest.py,v 1.6 2005/02/16 04:24:54 warnes Exp $'
  3. import sys, os, time, signal, re
  4. sys.path.insert(1, "..")
  5. from SOAPpy import SOAPProxy, SOAPConfig, SOAPUserAgent
  6. # Check for a web proxy definition in environment
  7. try:
  8. proxy_url=os.environ['http_proxy']
  9. phost, pport = re.search('http://([^:]+):([0-9]+)', proxy_url).group(1,2)
  10. http_proxy = "%s:%s" % (phost, pport)
  11. except:
  12. http_proxy = None
  13. PROXY="http://www.soapware.org/xmlStorageSystem"
  14. EMAIL="SOAPpy@actzero.com"
  15. NAME="test_user"
  16. PASSWORD="mypasswd"
  17. SERIAL=1123214
  18. MY_PORT=15600
  19. def resourceChanged (url):
  20. print "\n##### NOTIFICATION MESSAGE: Resource %s has changed #####\n" % url
  21. return booleanType(1)
  22. def printstatus (cmd, stat):
  23. print
  24. if stat.flError:
  25. print "### %s failed: %s ###" % (cmd, stat.message)
  26. else:
  27. print "### %s successful: %s ###" % (cmd, stat.message)
  28. return not stat.flError
  29. server = SOAPProxy(encoding="US-ASCII",
  30. proxy=PROXY,
  31. soapaction="/xmlStorageSystem",
  32. http_proxy=http_proxy,
  33. # config=SOAPConfig(debug=1)
  34. )
  35. # Register as a new user or update user information
  36. reg = server.registerUser(email=EMAIL, name=NAME, password=PASSWORD,
  37. clientPort=MY_PORT, userAgent=SOAPUserAgent(),
  38. serialnumber=SERIAL)
  39. printstatus("registerUser", reg)
  40. # See what this server can do
  41. reg = server.getServerCapabilities (email=EMAIL, password=PASSWORD)
  42. if printstatus("getServerCapabilities", reg):
  43. print "Legal file extensions: " + str(reg.legalFileExtensions)
  44. print "Maximum file size: " + str(reg.maxFileSize)
  45. print "Maximum bytes per user: " + str(reg.maxBytesPerUser)
  46. print "Number of bytes in use by the indicated user: " + str(reg.ctBytesInUse)
  47. print "URL of the folder containing your files: " + str(reg.yourUpstreamFolderUrl)
  48. # Store some files
  49. reg = server.saveMultipleFiles (email=EMAIL, password=PASSWORD,
  50. relativepathList=['index.html','again.html'],
  51. fileTextList=['<html><title>bennett@actzero.com home page</title><body>' +
  52. '<a href=again.html>Hello Earth</a></body></html>',
  53. '<html><title>bennett@actzero.com home page</title><body>' +
  54. '<a href=index.html>Hello Earth Again</a></body></html>'])
  55. if printstatus("saveMultipleFiles", reg):
  56. print "Files stored:"
  57. for file in reg.urlList:
  58. print " %s" % file
  59. # Save this for call to test pleaseNotify
  60. mylist = reg.urlList
  61. else:
  62. mylist = []
  63. # Check to see what files are stored
  64. reg = server.getMyDirectory (email=EMAIL, password=PASSWORD)
  65. if printstatus("getMyDirectory", reg):
  66. i = 1
  67. while hasattr(reg.directory, "file%05d" % i):
  68. d = getattr(reg.directory, "file%05d" % i)
  69. print "Relative Path: %s" % d.relativePath
  70. print "Size: %d" % d.size
  71. print "Created: %s" % d.whenCreated
  72. print "Last Uploaded: %s" % d.whenLastUploaded
  73. print "URL: %s" % d.url
  74. print
  75. i += 1
  76. # Set up notification
  77. reg = server.pleaseNotify(notifyProcedure="resourceChanged", port=MY_PORT, path="/", protocol="soap", urlList=mylist)
  78. printstatus("notifyProcedure", reg)
  79. pid = os.fork()
  80. if pid == 0:
  81. # I am a child process. Set up SOAP server to receive notification
  82. print
  83. print "## Starting notification server ##"
  84. s = SOAPServer(('localhost', MY_PORT))
  85. s.registerFunction(resourceChanged)
  86. s.serve_forever()
  87. else:
  88. def handler(signum, frame):
  89. # Kill child process
  90. print "Killing child process %d" % pid
  91. os.kill(pid, signal.SIGINT)
  92. signal.signal(signal.SIGINT, handler)
  93. # I am a parent process
  94. # Change some files
  95. time.sleep(3)
  96. reg = server.saveMultipleFiles (email=EMAIL, password=PASSWORD,
  97. relativepathList=['index.html'],
  98. fileTextList=['<html><title>bennett@actzero.com home page</title><body>' +
  99. '<a href=again.html>Hello Bennett</a></body></html>'])
  100. if printstatus("saveMultipleFiles", reg):
  101. print "Files stored:"
  102. for file in reg.urlList:
  103. print " %s" % file
  104. os.waitpid(pid, 0)