diff options
author | Kristján Valur Jónsson <kristjan@ccpgames.com> | 2009-07-19 22:14:00 (GMT) |
---|---|---|
committer | Kristján Valur Jónsson <kristjan@ccpgames.com> | 2009-07-19 22:14:00 (GMT) |
commit | 6d755900f6735a6c66b5e8455a0127ac99caf2a6 (patch) | |
tree | 099c42b9a6ec4f405797ca5b4114564aefa642f6 /Lib | |
parent | d7b0eebcaea618c982eff7ed92054292b9281d1f (diff) | |
download | cpython-6d755900f6735a6c66b5e8455a0127ac99caf2a6.zip cpython-6d755900f6735a6c66b5e8455a0127ac99caf2a6.tar.gz cpython-6d755900f6735a6c66b5e8455a0127ac99caf2a6.tar.bz2 |
http://bugs.python.org/issue6499
zlib/gzip may not be present for all builds. Make xmlrpclib gracefully not supporg gzip encoding in this case
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/SimpleXMLRPCServer.py | 9 | ||||
-rw-r--r-- | Lib/test/test_xmlrpc.py | 6 | ||||
-rw-r--r-- | Lib/xmlrpclib.py | 16 |
3 files changed, 25 insertions, 6 deletions
diff --git a/Lib/SimpleXMLRPCServer.py b/Lib/SimpleXMLRPCServer.py index 5b5aced..7aac89a 100644 --- a/Lib/SimpleXMLRPCServer.py +++ b/Lib/SimpleXMLRPCServer.py @@ -521,8 +521,11 @@ class SimpleXMLRPCRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler): if len(response) > self.encode_threshold: q = self.accept_encodings().get("gzip", 0) if q: - response = xmlrpclib.gzip_encode(response) - self.send_header("Content-Encoding", "gzip") + try: + response = xmlrpclib.gzip_encode(response) + self.send_header("Content-Encoding", "gzip") + except NotImplementedError: + pass self.send_header("Content-length", str(len(response))) self.end_headers() self.wfile.write(response) @@ -535,6 +538,8 @@ class SimpleXMLRPCRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler): if encoding == "gzip": try: return xmlrpclib.gzip_decode(data) + except NotImplementedError: + self.send_response(501, "encoding %r not supported" % encoding) except ValueError: self.send_response(400, "error decoding gzip content") else: diff --git a/Lib/test/test_xmlrpc.py b/Lib/test/test_xmlrpc.py index f5749c6..abd905a 100644 --- a/Lib/test/test_xmlrpc.py +++ b/Lib/test/test_xmlrpc.py @@ -918,7 +918,11 @@ def test_main(): xmlrpc_tests.append(SimpleServerTestCase) xmlrpc_tests.append(KeepaliveServerTestCase1) xmlrpc_tests.append(KeepaliveServerTestCase2) - xmlrpc_tests.append(GzipServerTestCase) + try: + import gzip + xmlrpc_tests.append(GzipServerTestCase) + except ImportError: + pass #gzip not supported in this build xmlrpc_tests.append(ServerProxyTestCase) xmlrpc_tests.append(FailingServerTestCase) xmlrpc_tests.append(CGIHandlerTestCase) diff --git a/Lib/xmlrpclib.py b/Lib/xmlrpclib.py index a712a64..57d0055 100644 --- a/Lib/xmlrpclib.py +++ b/Lib/xmlrpclib.py @@ -139,10 +139,13 @@ Exported functions: import re, string, time, operator from types import * -import gzip import socket import errno import httplib +try: + import gzip +except ImportError: + gzip = None #python can be built without zlib/gzip support # -------------------------------------------------------------------- # Internal stuff @@ -1146,6 +1149,8 @@ def gzip_encode(data): Encode data using the gzip content encoding as described in RFC 1952 """ + if not gzip: + raise NotImplementedError f = StringIO.StringIO() gzf = gzip.GzipFile(mode="wb", fileobj=f, compresslevel=1) gzf.write(data) @@ -1168,6 +1173,8 @@ def gzip_decode(data): Decode data using the gzip content encoding as described in RFC 1952 """ + if not gzip: + raise NotImplementedError f = StringIO.StringIO(data) gzf = gzip.GzipFile(mode="rb", fileobj=f) try: @@ -1192,6 +1199,8 @@ class GzipDecodedResponse(gzip.GzipFile): def __init__(self, response): #response doesn't support tell() and read(), required by #GzipFile + if not gzip: + raise NotImplementedError self.stringio = StringIO.StringIO(response.read()) gzip.GzipFile.__init__(self, mode="rb", fileobj=self.stringio) @@ -1378,7 +1387,7 @@ class Transport: # @param request_body XML-RPC body. def send_request(self, connection, handler, request_body): - if (self.accept_gzip_encoding): + if (self.accept_gzip_encoding and gzip): connection.putrequest("POST", handler, skip_accept_encoding=True) connection.putheader("Accept-Encoding", "gzip") else: @@ -1421,7 +1430,8 @@ class Transport: #optionally encode the request if (self.encode_threshold is not None and - self.encode_threshold < len(request_body)): + self.encode_threshold < len(request_body) and + gzip): connection.putheader("Content-Encoding", "gzip") request_body = gzip_encode(request_body) |