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.
 
 
 
 

164 lines
6.1 KiB

  1. diff -urN Zope-2.5.0-linux2-x86/lib/python/ZPublisher/HTTPRequest.py Zope-2.5.0-linux2-x86.1/lib/python/ZPublisher/HTTPRequest.py
  2. --- Zope-2.5.0-linux2-x86/lib/python/ZPublisher/HTTPRequest.py 2002-01-03 20:41:05.000000000 +0100
  3. +++ Zope-2.5.0-linux2-x86.1/lib/python/ZPublisher/HTTPRequest.py 2003-11-12 13:17:57.000000000 +0100
  4. @@ -21,6 +21,7 @@
  5. from Converters import get_converter
  6. from maybe_lock import allocate_lock
  7. xmlrpc=None # Placeholder for module that we'll import if we have to.
  8. +soap=None
  9. #cgi hotfix:
  10. if not hasattr(cgi, 'valid_boundary'):
  11. @@ -347,18 +348,28 @@
  12. meth=None
  13. fs=FieldStorage(fp=fp,environ=environ,keep_blank_values=1)
  14. if not hasattr(fs,'list') or fs.list is None:
  15. - # Hm, maybe it's an XML-RPC
  16. - if (fs.headers.has_key('content-type') and
  17. - fs.headers['content-type'] == 'text/xml' and
  18. + # Hm, maybe it's an XML-RPC or SOAP
  19. + if (fs.headers.has_key('content-type') and
  20. + fs.headers['content-type'][:8] == 'text/xml' and
  21. method == 'POST'):
  22. - # Ye haaa, XML-RPC!
  23. - global xmlrpc
  24. - if xmlrpc is None: import xmlrpc
  25. - meth, self.args = xmlrpc.parse_input(fs.value)
  26. - response=xmlrpc.response(response)
  27. - other['RESPONSE']=self.response=response
  28. - other['REQUEST_METHOD']='' # We don't want index_html!
  29. - self.maybe_webdav_client = 0
  30. + if environ.has_key('HTTP_SOAPACTION'):
  31. + # this is a SOAP request
  32. + global soap
  33. + if soap is None:
  34. + import soap
  35. + meth, self.args = soap.parse_input(fs.value)
  36. + response = soap.response(response)
  37. + other['RESPONSE'] = self.response = response
  38. + other['REQUEST_METHOD'] = ''
  39. + else:
  40. + # Ye haaa, XML-RPC!
  41. + global xmlrpc
  42. + if xmlrpc is None: import xmlrpc
  43. + meth, self.args = xmlrpc.parse_input(fs.value)
  44. + response=xmlrpc.response(response)
  45. + other['RESPONSE']=self.response=response
  46. + other['REQUEST_METHOD']='' # We don't want index_html!
  47. + self.maybe_webdav_client = 0
  48. else:
  49. self._file=fs.file
  50. else:
  51. diff -urN Zope-2.5.0-linux2-x86/lib/python/ZPublisher/soap.py Zope-2.5.0-linux2-x86.1/lib/python/ZPublisher/soap.py
  52. --- Zope-2.5.0-linux2-x86/lib/python/ZPublisher/soap.py 1970-01-01 01:00:00.000000000 +0100
  53. +++ Zope-2.5.0-linux2-x86.1/lib/python/ZPublisher/soap.py 2003-11-12 13:20:39.000000000 +0100
  54. @@ -0,0 +1,108 @@
  55. +"""SOAP support module
  56. +
  57. +by Antonio Beamud Montero <antonio.beamud@linkend.com>
  58. +
  59. +Based on the XML-RPC Zope support module written by Eric Kidd at UserLand
  60. +software and the modifications made by Petru Paler, with much help
  61. +from Jim Fulton at DC.
  62. +
  63. +This code hooks Zope up to SOAPpy library.
  64. +"""
  65. +
  66. +import sys
  67. +from string import replace
  68. +from HTTPResponse import HTTPResponse
  69. +from SOAPpy import *
  70. +from zLOG import LOG, PROBLEM, ERROR, DEBUG, INFO,TRACE
  71. +
  72. +Config.specialArgs=0.
  73. +
  74. +def parse_input(data):
  75. + """Parse input data and return a method path and argument tuple
  76. +
  77. + The data is a string.
  78. + """
  79. + obj = Parser.parseSOAPRPC(data)
  80. + method = obj._name
  81. + args = tuple(obj._aslist)
  82. +
  83. + # Translate '.' to '/' in meth to represent object traversal.
  84. + method = replace(method, '.', '/')
  85. + return method, args
  86. +
  87. +#######################################################################
  88. +# New Object response based on SOAPpy
  89. +#
  90. +class SOAPResponse:
  91. + def __init__(self, real): self.__dict__['_real']=real
  92. + def __getattr__(self, name): return getattr(self._real, name)
  93. + def __setattr__(self, name, v): return setattr(self._real, name, v)
  94. + def __delattr__(self, name): return delattr(self._real, name)
  95. +
  96. + def setBody(self, body, title='', is_error=0, bogus_str_search=None):
  97. + # Marshall our body as an SOAP response. Strings will be sent
  98. + # strings, integers as integers, etc. We do *not* convert
  99. + # everything to a string first.
  100. + status = 200
  101. + if isinstance(body, Types.faultType):
  102. + status = 500
  103. + # Convert Fault object to SOAP response.
  104. + soapbody = Types.faulType("%s:Server" % NS.ENV_T, body)
  105. + body = buildSOAP(soapbody,encoding=None)
  106. + else:
  107. + try:
  108. + body = buildSOAP((body,),encoding=None)
  109. + except Exception,e:
  110. + self.exception()
  111. + return self
  112. +
  113. + t = 'text/xml'
  114. + # Set our body to the XML-RPC message, and fix our MIME type.
  115. + self._real.setBody(body)
  116. + self._real.setHeader('content-type', t)
  117. + self._real.setHeader("content-length", str(len(body)))
  118. + self._real.setStatus(status)
  119. + return self
  120. +
  121. + def exception(self, fatal=0, info=None,
  122. + absuri_match=None, tag_search=None):
  123. + # Fetch our exception info. t is type, v is value and tb is the
  124. + # traceback object.
  125. +
  126. + if type(info) is type(()) and len(info)==3: t,v,tb = info
  127. + else: t,v,tb = sys.exc_info()
  128. + LOG('SOAPException', TRACE, tb)
  129. + # Create an appropriate Fault object. Unfortunately, we throw away
  130. + # most of the debugging information. More useful error reporting is
  131. + # left as an exercise for the reader.
  132. + Fault=Types.faultType
  133. + f=None
  134. + try:
  135. + if isinstance(v, Fault):
  136. + f=v
  137. + elif isinstance(v, Exception):
  138. + f=Fault("%s:Server" % NS.ENV_T,
  139. + "Unexpected Zope exception: %s"%str(v))
  140. + else:
  141. + f=Fault("%s:Server" % NS.ENV_T,
  142. + "Unexpected Zope error value: %s"%str(v))
  143. + except:
  144. + f=Fault("%s:Server" % NS.ENV_T,
  145. + "Unknown Zope fault type")
  146. +
  147. + # Do the damage.
  148. + body = buildSOAP(f)
  149. + self._real.setBody(body)
  150. + self._real.setHeader('content-type', 'text/xml')
  151. + self._real.setStatus(500)
  152. + return tb
  153. +
  154. +response=SOAPResponse
  155. +
  156. +
  157. +
  158. +
  159. +
  160. +
  161. +
  162. +