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.
 
 
 
 

142 lines
3.4 KiB

  1. #!/usr/bin/env python
  2. # Copyright (c) 2001 actzero, inc. All rights reserved.
  3. # This is a server for the XMethods matrix
  4. # (http://jake.soapware.org/currentXmethodsResults).
  5. import getopt
  6. import sys
  7. sys.path.insert (1, '..')
  8. from SOAPpy import SOAP
  9. if SOAP.Config.SSLserver:
  10. from M2Crypto import SSL
  11. ident = '$Id: silabserver.py 98 2003-03-08 05:10:01Z warnes $'
  12. def echoFloat (inputFloat):
  13. return inputFloat
  14. def echoFloatArray (inputFloatArray):
  15. return inputFloatArray
  16. def echoInteger (inputInteger):
  17. return inputInteger
  18. def echoIntegerArray (inputIntegerArray):
  19. return inputIntegerArray
  20. def echoString (inputString):
  21. return inputString
  22. def echoStringArray (inputStringArray):
  23. return inputStringArray
  24. def echoStruct (inputStruct):
  25. return inputStruct
  26. def echoStructArray (inputStructArray):
  27. return inputStructArray
  28. def echoVoid ():
  29. return SOAP.voidType()
  30. def echoDate (inputDate):
  31. return SOAP.dateTimeType (inputDate)
  32. def echoBase64 (inputBase64):
  33. return SOAP.binaryType (inputBase64)
  34. namespace = 'http://soapinterop.org/'
  35. DEFAULT_HOST = 'localhost'
  36. DEFAULT_HTTP_PORT = 8080
  37. DEFAULT_HTTPS_PORT = 8443
  38. def usage (error = None):
  39. sys.stdout = sys.stderr
  40. if error != None:
  41. print error
  42. print """usage: %s [options]
  43. If a long option shows an argument is mandatory, it's mandatory for the
  44. equivalent short option also. The default (if any) is shown in brackets.
  45. -?, --help display this usage
  46. -h, --host=HOST use HOST in the address to listen on [%s]
  47. -p, --port=PORT listen on PORT [%d]
  48. """ % (sys.argv[0], DEFAULT_HOST, DEFAULT_HTTP_PORT),
  49. if SOAP.Config.SSLserver:
  50. print " -s, --ssl serve using SSL"
  51. sys.exit (0)
  52. def main ():
  53. host = DEFAULT_HOST
  54. port = None
  55. ssl = 0
  56. try:
  57. opts = '?h:p:'
  58. args = ['help', 'host', 'port']
  59. if SOAP.Config.SSLserver:
  60. opts += 's'
  61. args += ['ssl']
  62. opts, args = getopt.getopt (sys.argv[1:], opts, args)
  63. for opt, arg in opts:
  64. if opt in ('-?', '--help'):
  65. usage ()
  66. elif opt in ('-h', '--host'):
  67. host = arg
  68. elif opt in ('-p', '--port'):
  69. port = int (arg)
  70. elif opt in ('-s', '--ssl'):
  71. ssl = 1
  72. else:
  73. raise AttributeError, \
  74. "Recognized but unimplemented option `%s'" % opt
  75. except SystemExit:
  76. raise
  77. except:
  78. usage (sys.exc_info ()[1])
  79. if port == None:
  80. port = [DEFAULT_HTTP_PORT, DEFAULT_HTTPS_PORT][ssl]
  81. if ssl:
  82. ssl_context = SSL.Context()
  83. ssl_context.load_cert('server.pem')
  84. else:
  85. ssl_context = None
  86. server = SOAP.SOAPServer ((host, port), namespace = namespace,
  87. ssl_context = ssl_context)
  88. server.registerFunction (echoFloat)
  89. server.registerFunction (echoFloatArray)
  90. server.registerFunction (echoInteger)
  91. server.registerFunction (echoIntegerArray)
  92. server.registerFunction (echoString)
  93. server.registerFunction (echoStringArray)
  94. server.registerFunction (echoStruct)
  95. server.registerFunction (echoStructArray)
  96. server.registerFunction (echoVoid)
  97. server.registerFunction (echoDate)
  98. server.registerFunction (echoBase64)
  99. server.serve_forever()
  100. if __name__ == '__main__':
  101. try:
  102. sys.exit (main ())
  103. except KeyboardInterrupt:
  104. sys.exit (0)