Skip to content

Commit 4a8dbe4

Browse files
author
Josh Marshall
committed
Making corrections for 2.7 compatibility (which mostly means bypassing the xml parsers by overwriting Transport.getparser)
1 parent a8ad7ff commit 4a8dbe4

File tree

2 files changed

+25
-15
lines changed

2 files changed

+25
-15
lines changed

jsonrpclib/jsonrpc.py

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -113,25 +113,35 @@ def send_content(self, connection, request_body):
113113
if request_body:
114114
connection.send(request_body)
115115

116-
def _parse_response(self, file_h, sock):
117-
response_body = ''
118-
while 1:
119-
if sock:
120-
response = sock.recv(1024)
121-
else:
122-
response = file_h.read(1024)
123-
if not response:
124-
break
125-
response_body += response
126-
if self.verbose:
127-
print 'body: %s' % response
128-
return response_body
116+
def getparser(self):
117+
target = JSONTarget()
118+
return JSONParser(target), target
119+
120+
class JSONParser(object):
121+
def __init__(self, target):
122+
self.target = target
123+
124+
def feed(self, data):
125+
self.target.feed(data)
126+
127+
def close(self):
128+
pass
129+
130+
class JSONTarget(object):
131+
def __init__(self):
132+
self.data = []
133+
134+
def feed(self, data):
135+
self.data.append(data)
136+
137+
def close(self):
138+
return ''.join(self.data)
129139

130140
class SafeTransport(XMLSafeTransport):
131141
""" Just extends for HTTPS calls """
132142
user_agent = Transport.user_agent
133143
send_content = Transport.send_content
134-
_parse_response = Transport._parse_response
144+
getparser = Transport.getparser
135145

136146
class ServerProxy(XMLServerProxy):
137147
"""

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
distutils.core.setup(
2020
name = "jsonrpclib",
21-
version = "0.11",
21+
version = "0.12",
2222
packages = ["jsonrpclib"],
2323
author = "Josh Marshall",
2424
author_email = "[email protected]",

0 commit comments

Comments
 (0)