1.1 --- a/MoinMessage.py Sun Jan 05 18:24:24 2014 +0100
1.2 +++ b/MoinMessage.py Sun Jan 05 22:27:55 2014 +0100
1.3 @@ -334,7 +334,7 @@
1.4
1.5 # Return the decrypted message text.
1.6
1.7 - return self.decryptMessageText(content.get_payload())
1.8 + return self.decryptMessageText(content.get_payload(decode=True))
1.9
1.10 def encryptMessage(self, message, keyid):
1.11
1.12 @@ -505,7 +505,18 @@
1.13 else:
1.14 message["Date"] = datestr
1.15
1.16 -def sendMessage(message, url, method="PUT"):
1.17 +def _getConnection(scheme):
1.18 +
1.19 + "Return the connection class for the given 'scheme'."
1.20 +
1.21 + if scheme == "http":
1.22 + return httplib.HTTPConnection
1.23 + elif scheme == "https":
1.24 + return httplib.HTTPSConnection
1.25 + else:
1.26 + raise MoinMessageError, "Communications protocol not supported: %s" % scheme
1.27 +
1.28 +def sendMessageForReading(message, url, method="PUT"):
1.29
1.30 """
1.31 Send 'message' to the given 'url' using the given 'method' (using PUT as the
1.32 @@ -515,20 +526,23 @@
1.33 scheme, host, port, path = parseURL(url)
1.34 text = message.as_string()
1.35
1.36 - if scheme == "http":
1.37 - cls = httplib.HTTPConnection
1.38 - elif scheme == "https":
1.39 - cls = httplib.HTTPSConnection
1.40 - else:
1.41 - raise MoinMessageError, "Communications protocol not supported: %s" % scheme
1.42 -
1.43 - req = cls(host, port)
1.44 + req = _getConnection(scheme)(host, port)
1.45 req.request(method, path, text)
1.46 resp = req.getresponse()
1.47
1.48 if resp.status >= 400:
1.49 - raise MoinMessageError, "Message sending failed: %s" % resp.status
1.50 + raise MoinMessageError, "Message sending failed (%s): %s" % (resp.status, resp.read())
1.51 +
1.52 + return resp
1.53 +
1.54 +def sendMessage(message, url, method="PUT"):
1.55
1.56 + """
1.57 + Send 'message' to the given 'url' using the given 'method' (using PUT as the
1.58 + default if omitted).
1.59 + """
1.60 +
1.61 + resp = sendMessageForReading(message, url, method)
1.62 return resp.read()
1.63
1.64 def parseURL(url):