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)
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:
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)
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
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)
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:
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)
# @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:
#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)