Gibt es einen besseren Weg, Fehler in mitgelieferten Bibliotheken los zu werden?
Code: Alles auswählen
import hashlib
import inspect
import httplib
__bad_read = "801726b8e58a929be9ce667cf727c7f9"
if hashlib.md5(inspect.getsource(httplib.HTTPResponse.read)).hexdigest() == __bad_read:
# mostly copied from [...]/python2.6/httplib.py HTTPResponse.read
def __good_read(self, amt=None):
if self.fp is None:
return ''
if self.chunked:
if amt is None: # These lines are the only difference to original
return "" # read(). Without them a chunked HEAD would block.
return self._read_chunked(amt)
if amt is None:
if self.length is None:
s = self.fp.read()
else:
s = self._safe_read(self.length)
self.length = 0
self.close() # we read everything
return s
if self.length is not None:
if amt > self.length:
amt = self.length
s = self.fp.read(amt)
if self.length is not None:
self.length -= len(s)
if not self.length:
self.close()
return s
# monkeys were here!
httplib.HTTPResponse.read = __good_read