1
###############################################################################
3
# Purpose: Web an network utilties #
4
# Author: Cody Precord <cprecord@editra.org> #
5
# Copyright: (c) 2010 Cody Precord <staff@editra.org> #
6
# Licence: wxWindows Licence #
7
###############################################################################
10
Editra Buisness Model Library: Web Utilities
12
Utility functions for working with web and other networking protocols
16
__author__ = "Cody Precord <cprecord@editra.org>"
17
__svnid__ = "$Id: e_weblib.py 66131 2010-11-13 05:22:48Z CJP $"
18
__revision__ = "$Revision: 66131 $"
20
__all__ = ['SOAP12Message',]
22
#-----------------------------------------------------------------------------#
27
#-----------------------------------------------------------------------------#
28
_SOAP_TPL = """<?xml version=\"1.0\" encoding=\"utf-8\"?>
29
<soap12:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap12=\"http://www.w3.org/2003/05/soap-envelope\">
37
_SM_TPL = """<?xml version="1.0" encoding="UTF-8"?>
39
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
40
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
47
#-----------------------------------------------------------------------------#
49
class SOAP12Message(object):
50
"""Class for creating and sending a message
51
using the SOAP protocol.
54
def __init__(self, host, request, msg, action=""):
55
"""Create the message object
56
@param host: host the message will be sent to (url)
57
@param request: POST request
58
@param msg: XML Body text
59
@keyword action: SoapAction
62
assert len(host), "Must specify a valid host"
63
super(SOAP12Message, self).__init__()
67
self._request = request
70
self._http = httplib.HTTP(self._host, 80)
73
def MessageBody(self):
74
soapmsg = _SOAP_TPL % dict(msg=self._msg)
75
soapmsg = soapmsg.replace("\n", "\r\n")
79
"""Send the message"""
80
# Create the SOAP message
81
soapmsg = self.MessageBody
84
self._http.putrequest("POST", self._request)
85
self._http.putheader("Host", self._host)
86
# self._http.putheader("User-Agent", "Python post")
87
self._http.putheader("Content-Type", "application/soap+xml; charset=utf-8")
88
self._http.putheader("Content-Length", "%d" % len(soapmsg))
89
self._http.putheader("SOAPAction", '"%s"' % self._action)
90
self._http.endheaders()
93
self._http.send(soapmsg)
96
"""Get the reply (may block for a long time)
97
@return: (statuscode, statusmessage, header)
100
return self._http.getreply()