From 8e443b4c42f2fc7b230fe34319d4045b0e6d67a0 Mon Sep 17 00:00:00 2001 From: Petr Mladek Date: Tue, 23 Nov 2010 18:31:36 +0100 Subject: fixed urllib.urlopen in the internal python (fdo#31466) + backported two fixes from newer python: + close the file even if an exception occurs (py#5536) + urllib doesn't correct server returned urls (py#918368) + thanks karolus for analyzing and suggesting the fix --- python/Python-2.6.1-urllib.patch | 93 ++++++++++++++++++++++++++++++++++++++++ python/makefile.mk | 3 +- 2 files changed, 95 insertions(+), 1 deletion(-) create mode 100644 python/Python-2.6.1-urllib.patch (limited to 'python') diff --git a/python/Python-2.6.1-urllib.patch b/python/Python-2.6.1-urllib.patch new file mode 100644 index 000000000000..6e20390860a4 --- /dev/null +++ b/python/Python-2.6.1-urllib.patch @@ -0,0 +1,93 @@ +--- misc/Python-2.6.1/Lib/urllib.py 2008-09-21 23:27:51.000000000 +0200 ++++ misc/build/Python-2.6.1/Lib/urllib.py 2010-11-23 15:41:08.000000000 +0100 +@@ -176,6 +176,9 @@ class URLopener: + def open(self, fullurl, data=None): + """Use URLopener().open(file) instead of open(file, 'r').""" + fullurl = unwrap(toBytes(fullurl)) ++ # percent encode url. fixing lame server errors like space within url ++ # parts ++ fullurl = quote(fullurl, safe="%/:=&?~#+!$,;'@()*[]|") + if self.tempcache and fullurl in self.tempcache: + filename, headers = self.tempcache[fullurl] + fp = open(filename, 'rb') +@@ -233,41 +236,45 @@ class URLopener: + except IOError, msg: + pass + fp = self.open(url, data) +- headers = fp.info() +- if filename: +- tfp = open(filename, 'wb') +- else: +- import tempfile +- garbage, path = splittype(url) +- garbage, path = splithost(path or "") +- path, garbage = splitquery(path or "") +- path, garbage = splitattr(path or "") +- suffix = os.path.splitext(path)[1] +- (fd, filename) = tempfile.mkstemp(suffix) +- self.__tempfiles.append(filename) +- tfp = os.fdopen(fd, 'wb') +- result = filename, headers +- if self.tempcache is not None: +- self.tempcache[url] = result +- bs = 1024*8 +- size = -1 +- read = 0 +- blocknum = 0 +- if reporthook: +- if "content-length" in headers: +- size = int(headers["Content-Length"]) +- reporthook(blocknum, bs, size) +- while 1: +- block = fp.read(bs) +- if block == "": +- break +- read += len(block) +- tfp.write(block) +- blocknum += 1 +- if reporthook: +- reporthook(blocknum, bs, size) +- fp.close() +- tfp.close() ++ try: ++ headers = fp.info() ++ if filename: ++ tfp = open(filename, 'wb') ++ else: ++ import tempfile ++ garbage, path = splittype(url) ++ garbage, path = splithost(path or "") ++ path, garbage = splitquery(path or "") ++ path, garbage = splitattr(path or "") ++ suffix = os.path.splitext(path)[1] ++ (fd, filename) = tempfile.mkstemp(suffix) ++ self.__tempfiles.append(filename) ++ tfp = os.fdopen(fd, 'wb') ++ try: ++ result = filename, headers ++ if self.tempcache is not None: ++ self.tempcache[url] = result ++ bs = 1024*8 ++ size = -1 ++ read = 0 ++ blocknum = 0 ++ if reporthook: ++ if "content-length" in headers: ++ size = int(headers["Content-Length"]) ++ reporthook(blocknum, bs, size) ++ while 1: ++ block = fp.read(bs) ++ if block == "": ++ break ++ read += len(block) ++ tfp.write(block) ++ blocknum += 1 ++ if reporthook: ++ reporthook(blocknum, bs, size) ++ finally: ++ tfp.close() ++ finally: ++ fp.close() + del fp + del tfp + diff --git a/python/makefile.mk b/python/makefile.mk index 6f4b7ee5623c..d090cdc3932a 100644 --- a/python/makefile.mk +++ b/python/makefile.mk @@ -50,7 +50,8 @@ TARFILE_MD5=e81c2f0953aa60f8062c05a4673f2be0 PATCH_FILES=\ Python-$(PYVERSION).patch \ Python-ssl.patch \ - Python-aix.patch + Python-aix.patch \ + Python-2.6.1-urllib.patch CONFIGURE_DIR= -- cgit