summaryrefslogtreecommitdiffstats
path: root/Lib/xmlrpc/client.py
diff options
context:
space:
mode:
authorKristján Valur Jónsson <kristjan@ccpgames.com>2009-07-19 22:29:24 (GMT)
committerKristján Valur Jónsson <kristjan@ccpgames.com>2009-07-19 22:29:24 (GMT)
commitaefde242fd7bc6c838107aaa734c8808c5d21fe2 (patch)
tree6857c209b6d08ddc0b5f67d98c5529eb484e5768 /Lib/xmlrpc/client.py
parent22101aa086ddf50928939b9a9cf84f9ca814e52a (diff)
downloadcpython-aefde242fd7bc6c838107aaa734c8808c5d21fe2.zip
cpython-aefde242fd7bc6c838107aaa734c8808c5d21fe2.tar.gz
cpython-aefde242fd7bc6c838107aaa734c8808c5d21fe2.tar.bz2
porting revision 74098 from trunk:
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/xmlrpc/client.py')
-rw-r--r--Lib/xmlrpc/client.py16
1 files changed, 13 insertions, 3 deletions
diff --git a/Lib/xmlrpc/client.py b/Lib/xmlrpc/client.py
index 9f72931..fc32925 100644
--- a/Lib/xmlrpc/client.py
+++ b/Lib/xmlrpc/client.py
@@ -136,10 +136,13 @@ Exported functions:
import re, time, operator
import http.client
from xml.parsers import expat
-import gzip
import socket
import errno
from io import BytesIO
+try:
+ import gzip
+except ImportError:
+ gzip = None #python can be built without zlib/gzip support
# --------------------------------------------------------------------
# Internal stuff
@@ -1030,6 +1033,8 @@ def gzip_encode(data):
Encode data using the gzip content encoding as described in RFC 1952
"""
+ if not gzip:
+ raise NotImplementedError
f = BytesIO()
gzf = gzip.GzipFile(mode="wb", fileobj=f, compresslevel=1)
gzf.write(data)
@@ -1052,6 +1057,8 @@ def gzip_decode(data):
Decode data using the gzip content encoding as described in RFC 1952
"""
+ if not gzip:
+ raise NotImplementedError
f = BytesIO(data)
gzf = gzip.GzipFile(mode="rb", fileobj=f)
try:
@@ -1076,6 +1083,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.io = BytesIO(response.read())
gzip.GzipFile.__init__(self, mode="rb", fileobj=self.io)
@@ -1253,7 +1262,7 @@ class Transport:
headers = self._extra_headers[:]
if debug:
connection.set_debuglevel(1)
- if self.accept_gzip_encoding:
+ if self.accept_gzip_encoding and gzip:
connection.putrequest("POST", handler, skip_accept_encoding=True)
headers.append(("Accept-Encoding", "gzip"))
else:
@@ -1285,7 +1294,8 @@ class Transport:
def send_content(self, connection, request_body):
#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)