Ejemplo n.º 1
0
    def parse_response(self, response):
        # read response data from httpresponse, and parse it

        # Check for new http response object, else it is a file object
        if hasattr(response, 'getheader'):
            if response.getheader("Content-Encoding", "") == "gzip":
                stream = xmlrpclib.GzipDecodedResponse(response)
            else:
                stream = response
        else:
            stream = response

        p, u = self.getparser()

        while 1:
            data = stream.read(1024)
            if not data:
                break
            if self.verbose:
                print("body:", repr(data))
            p.feed(data)

        if stream is not response:
            stream.close()
        p.close()

        return u.close()
Ejemplo n.º 2
0
    def parse_response(self, response):
        # This code taken from xmlrpclib Transport.parse_response, and
        # modified to remove the response processing.

        # Check for new http response object, else it is a file object
        if hasattr(response, 'getheader'):
            if response.getheader("Content-Encoding", "") == "gzip":
                stream = xmlrpclib.GzipDecodedResponse(response)
            else:
                stream = response
        else:
            stream = response

        ret = ''
        while 1:
            data = stream.read(1024)
            ret += data
            if not data:
                break
            if self.verbose:
                print "body:", repr(data)

        if stream is not response:
            stream.close()

        return ret
Ejemplo n.º 3
0
def ParseHTTPResponse(response):
    """Parse an HTTP response object and return the JSON object.

  Args:
    response: An HTTP response object.

  Returns:
    The returned JSON-RPC object.

  Raises:
    ProtocolError: if the object format is not correct.
    Fault: If a Fault error is returned from the server.
  """
    # Check for new http response object, else it is a file object
    if hasattr(response, 'getheader'):
        if response.getheader('Content-Encoding', '') == 'gzip':
            stream = _base.GzipDecodedResponse(response)
        else:
            stream = response
    else:
        stream = response

    data = ''
    while 1:
        chunk = stream.read(1024)
        if not chunk:
            break
        data += chunk

    response = json.loads(data)
    ValidateBasicJSONRPCData(response)

    if 'response' in response:
        ValidateResponse(response)
        return response['response']
    elif 'error' in response:
        ValidateError(response)
        code = response['error']['code']
        message = response['error']['message']
        raise Fault(code, message)
    else:
        raise ProtocolError('No valid JSON returned')
Ejemplo n.º 4
0
    def parse_response(self, response):
        # read response data from httpresponse, and parse it

        # Check for new http response object, else it is a file object
        if hasattr(response, 'getheader'):
            if response.getheader("Content-Encoding", "") == "gzip":
                stream = xmlrpclib.GzipDecodedResponse(response)
            else:
                stream = response
        else:
            stream = response

        p, u = self.getparser()

        # CHANGE-START
        first = True
        # CHANGE-END

        while 1:
            data = stream.read(1024)
            if not data:
                break
            if self.verbose:
                print "body:", repr(data)

            # CHANGE-START
            if first:
                first = False
                if data[0] == "\n":
                    data = data[1:]
            # CHANGE-END
            p.feed(data)

        if stream is not response:
            stream.close()
        p.close()

        return u.close()