def parse_response(self, f): # read response from input file, and parse it def binary_cb(data): b = Binary() b.decode(data) return b def boolean_cb(value): if value == 0: return False elif value == 1: return True else: raise TypeError, "bad boolean value" def fault_cb(arg): raise apply(Fault, (), arg) my_thread = threading.currentThread() unmarshaller = ximian_unmarshaller.new(binary_cb, boolean_cb, fault_cb) while 1: if my_thread in self.__cancelled: f.close() self.__cancelled.remove(my_thread) return () response = f.read(1024) if not response: break if self.verbose: print "body:", repr(response) unmarshaller.feed(response, 0) f.close() unmarshaller.feed("", 1) return unmarshaller.close()
def parse_response(self, f): # read response from input file, and parse it def binary_cb(data): b = Binary() b.decode(data) return b def boolean_cb(value): if value == 0: return False elif value == 1: return True else: raise TypeError, "bad boolean value" def fault_cb(arg): raise apply(Fault, (), arg) my_thread = threading.currentThread() unmarshaller = ximian_unmarshaller.new(binary_cb, boolean_cb, fault_cb) first_pass = 1 while 1: if my_thread in self.__cancelled: f.close() self.__cancelled.remove(my_thread) return () response = f.read(1024) if not response: break if self.verbose: print "response:", repr(response) # FIXME: This is evil and wrong and papers over what appears # to be a race in rcd. Essentially there is garbage on the # wire, including null bytes, and the unmarshaller will throw # a TypeError if this happens, so we move past the bad data # to the start of the actual XML if first_pass: ind = string.index(response, "<?xml") if self.verbose and ind > 0: print "Moving past %d bad bytes" % ind response = response[ind:] unmarshaller.feed(response, 0) first_pass = 0 f.close() unmarshaller.feed("", 1) return unmarshaller.close()