class ProtocolError(Exception):
pass
-class Transport(XMLTransport):
+class TransportMixIn(object):
""" Just extends the XMLRPC transport where necessary. """
user_agent = config.user_agent
+ # for Python 2.7 support
+ _connection = None
def send_content(self, connection, request_body):
connection.putheader("Content-Type", "application/json-rpc")
if request_body:
connection.send(request_body)
- def _parse_response(self, file_h, sock):
- response_body = ''
- while 1:
- if sock:
- response = sock.recv(1024)
- else:
- response = file_h.read(1024)
- if not response:
- break
- response_body += response
- if self.verbose:
- print 'body: %s' % response
- return response_body
-
-class SafeTransport(XMLSafeTransport):
- """ Just extends for HTTPS calls """
- user_agent = Transport.user_agent
- send_content = Transport.send_content
- _parse_response = Transport._parse_response
+ def getparser(self):
+ target = JSONTarget()
+ return JSONParser(target), target
+
+class JSONParser(object):
+ def __init__(self, target):
+ self.target = target
+
+ def feed(self, data):
+ self.target.feed(data)
+
+ def close(self):
+ pass
+
+class JSONTarget(object):
+ def __init__(self):
+ self.data = []
+ def feed(self, data):
+ self.data.append(data)
+
+ def close(self):
+ return ''.join(self.data)
+
+class Transport(TransportMixIn, XMLTransport):
+ pass
+
+class SafeTransport(TransportMixIn, XMLSafeTransport):
+ pass
+
class ServerProxy(XMLServerProxy):
"""
Unfortunately, much more of this class has to be copied since