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.
 
 
 
 

176 lines
6.5 KiB

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