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.
 
 
 
 

118 lines
3.2 KiB

  1. #!/usr/bin/env python
  2. # This server validates as of 4/23/01 when run with UserLand's SOAP validator
  3. # (http://validator.soapware.org/).
  4. import getopt
  5. import sys
  6. sys.path.insert (1, '..')
  7. from SOAPpy import SOAP
  8. ident = '$Id: soapware.py 98 2003-03-08 05:10:01Z warnes $'
  9. def whichToolkit ():
  10. return SOAP.SOAPUserAgent ()
  11. def countTheEntities (s):
  12. counts = {'ctLeftAngleBrackets': 0, 'ctRightAngleBrackets': 0,
  13. 'ctAmpersands': 0, 'ctApostrophes': 0, 'ctQuotes': 0}
  14. for i in s:
  15. if i == '<':
  16. counts['ctLeftAngleBrackets'] += 1
  17. elif i == '>':
  18. counts['ctRightAngleBrackets'] += 1
  19. elif i == '&':
  20. counts['ctAmpersands'] += 1
  21. elif i == "'":
  22. counts['ctApostrophes'] += 1
  23. elif i == '"':
  24. counts['ctQuotes'] += 1
  25. return counts
  26. def easyStructTest (stooges):
  27. return stooges['larry'] + stooges['moe'] + stooges['curly']
  28. def echoStructTest (myStruct):
  29. return myStruct
  30. def manyTypesTest (num, bool, state, doub, dat, bin):
  31. return [num, SOAP.booleanType (bool), state, doub,
  32. SOAP.dateTimeType (dat), bin]
  33. def moderateSizeArrayCheck (myArray):
  34. return myArray[0] + myArray[-1]
  35. def nestedStructTest (myStruct):
  36. return easyStructTest (myStruct.year2000.month04.day01)
  37. def simpleStructReturnTest (myNumber):
  38. return {'times10': myNumber * 10, 'times100': myNumber * 100,
  39. 'times1000': myNumber * 1000}
  40. namespace = 'http://www.soapware.org/'
  41. DEFAULT_HOST = 'localhost'
  42. DEFAULT_PORT = 8080
  43. def usage (error = None):
  44. sys.stdout = sys.stderr
  45. if error != None:
  46. print(error)
  47. print("""usage: %s [options]
  48. If a long option shows an argument is mandatory, it's mandatory for the
  49. equivalent short option also. The default (if any) is shown in brackets.
  50. -?, --help display this usage
  51. -h, --host=HOST use HOST in the address to listen on [%s]
  52. -p, --port=PORT listen on PORT [%d]
  53. """ % (sys.argv[0], DEFAULT_HOST, DEFAULT_PORT), end=' ')
  54. sys.exit (0)
  55. def main ():
  56. host = DEFAULT_HOST
  57. port = DEFAULT_PORT
  58. try:
  59. opts, args = getopt.getopt (sys.argv[1:], '?h:p:',
  60. ['help', 'host', 'port'])
  61. for opt, arg in opts:
  62. if opt in ('-?', '--help'):
  63. usage ()
  64. elif opt in ('-h', '--host'):
  65. host = arg
  66. elif opt in ('-p', '--port'):
  67. port = int (arg)
  68. else:
  69. raise AttributeError("Recognized but unimplemented option `%s'" % opt)
  70. except SystemExit:
  71. raise
  72. except:
  73. usage (sys.exc_info ()[1])
  74. server = SOAP.SOAPServer ((host, port))
  75. server.registerFunction (whichToolkit, namespace)
  76. server.registerFunction (countTheEntities)
  77. server.registerFunction (easyStructTest)
  78. server.registerFunction (echoStructTest)
  79. server.registerFunction (manyTypesTest)
  80. server.registerFunction (moderateSizeArrayCheck)
  81. server.registerFunction (nestedStructTest)
  82. server.registerFunction (simpleStructReturnTest)
  83. server.serve_forever()
  84. if __name__ == '__main__':
  85. try:
  86. sys.exit (main ())
  87. except KeyboardInterrupt:
  88. sys.exit (0)