summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorPetr Mladek <pmladek@suse.cz>2010-11-23 18:31:36 +0100
committerPetr Mladek <pmladek@suse.cz>2010-11-23 18:38:31 +0100
commit8e443b4c42f2fc7b230fe34319d4045b0e6d67a0 (patch)
tree494f836953de754355faf7205ed054165a7b967a /python
parentc036e339cb70badcfb05811b221b08d2fc37fda0 (diff)
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 <karlooforum at arcor dot de> for analyzing and suggesting the fix
Diffstat (limited to 'python')
-rw-r--r--python/Python-2.6.1-urllib.patch93
-rw-r--r--python/makefile.mk3
2 files changed, 95 insertions, 1 deletions
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=