def parse_response(self, response): ctype = response.headers.get('content-type', '') ctype, pdict = cgi.parse_header(ctype) if ctype in self.contentTypes: return xmlrpclib.Transport.parse_response(self, response) elif ctype != self.mixedType: raise xmlrpclib.ResponseError( "Response has invalid or missing Content-Type") decoder = MultipartDecoder(response, pdict['boundary']) # Read XMLRPC response rpcHeaders, rpcBody = decoder.get() if (cgi.parse_header(rpcHeaders.get('content-type'))[0] not in self.contentTypes): raise xmlrpclib.ResponseError( "Response has invalid or missing Content-Type") rpcBody = StringIO.StringIO(rpcBody) result = xmlrpclib.Transport.parse_response(self, rpcBody) # Replace the URL in the XMLRPC response with a file-like object that # reads out the second part of the multipart response csResponse = decoder.getStream() if csResponse.headers.get('content-type') != ( 'application/x-conary-change-set'): raise xmlrpclib.ResponseError( "Response body has wrong Content-Type") result[0][1][0] = csResponse return result
def _parse_multipart_header(response, boundary): if response.readline() != "--%s\r\n" % (boundary,): raise xmlrpclib.ResponseError("Response body is corrupted") ctype = cenc = clen = None while True: line = response.readline().rstrip('\r\n') if not line: break key, value = line.split(': ') if key.lower() == 'content-type': ctype = cgi.parse_header(value)[0] elif key.lower() == 'content-encoding': cenc = value elif key.lower() == 'content-length': clen = int(value) return ctype, cenc, clen
def close(self): # return response tuple and target method if self._type is None or self._marks: raise xmlrpclib.ResponseError() if self._type == "fault": d = self._stack[0] m = error_pat.match(d['faultString']) if m: exception_name = m.group('exception') rest = m.group('rest') for exc in allowed_errors: if exc.__name__ == exception_name: raise exc(rest) # Fall through and just raise the fault raise xmlrpclib.Fault(**d) return tuple(self._stack)
def close(self): """return response tuple and target method""" if self._type is None or self._marks: raise xmlrpclib.ResponseError() if self._type == "fault": res_dict = self._stack[0] hit = error_pat.match(res_dict['faultString']) if hit: exception_name = hit.group('exception') errno = hit.group('errno') rest = hit.group('rest') for exc in allowed_errors: if exc.__name__ == exception_name: if errno is not None: raise exc(int(errno), rest) else: raise exc(rest) # Fall through and just raise the fault raise xmlrpclib.Fault(**res_dict) return tuple(self._stack)