storageTest.py :  » Web-Services » SOAPpy » SOAPpy-0.12.0 » tests » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Web Services » SOAPpy 
SOAPpy » SOAPpy 0.12.0 » tests » storageTest.py
#!/usr/bin/env python

ident = '$Id: storageTest.py,v 1.6 2005/02/16 04:24:54 warnes Exp $'

import sys, os, time, signal, re
sys.path.insert(1, "..")
from SOAPpy import SOAPProxy,SOAPConfig,SOAPUserAgent

# Check for a web proxy definition in environment
try:
   proxy_url=os.environ['http_proxy']
   phost, pport = re.search('http://([^:]+):([0-9]+)', proxy_url).group(1,2)
   http_proxy = "%s:%s" % (phost, pport)
except:
   http_proxy = None


PROXY="http://www.soapware.org/xmlStorageSystem"
EMAIL="SOAPpy@actzero.com"
NAME="test_user"
PASSWORD="mypasswd"
SERIAL=1123214

MY_PORT=15600

def resourceChanged (url):
    print "\n##### NOTIFICATION MESSAGE: Resource %s has changed #####\n" % url
    return 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 = SOAPProxy(encoding="US-ASCII", 
                   proxy=PROXY,
                   soapaction="/xmlStorageSystem",
                   http_proxy=http_proxy,
#                   config=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=SOAPUserAgent(),
                          serialnumber=SERIAL)
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 = 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)
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.