Bump for 3.6-28
[LibreOffice.git] / python / Python-2.6.1-urllib.patch
blob6e20390860a496a25368762d763d9675df92050d
1 --- misc/Python-2.6.1/Lib/urllib.py 2008-09-21 23:27:51.000000000 +0200
2 +++ misc/build/Python-2.6.1/Lib/urllib.py 2010-11-23 15:41:08.000000000 +0100
3 @@ -176,6 +176,9 @@ class URLopener:
4 def open(self, fullurl, data=None):
5 """Use URLopener().open(file) instead of open(file, 'r')."""
6 fullurl = unwrap(toBytes(fullurl))
7 + # percent encode url. fixing lame server errors like space within url
8 + # parts
9 + fullurl = quote(fullurl, safe="%/:=&?~#+!$,;'@()*[]|")
10 if self.tempcache and fullurl in self.tempcache:
11 filename, headers = self.tempcache[fullurl]
12 fp = open(filename, 'rb')
13 @@ -233,41 +236,45 @@ class URLopener:
14 except IOError, msg:
15 pass
16 fp = self.open(url, data)
17 - headers = fp.info()
18 - if filename:
19 - tfp = open(filename, 'wb')
20 - else:
21 - import tempfile
22 - garbage, path = splittype(url)
23 - garbage, path = splithost(path or "")
24 - path, garbage = splitquery(path or "")
25 - path, garbage = splitattr(path or "")
26 - suffix = os.path.splitext(path)[1]
27 - (fd, filename) = tempfile.mkstemp(suffix)
28 - self.__tempfiles.append(filename)
29 - tfp = os.fdopen(fd, 'wb')
30 - result = filename, headers
31 - if self.tempcache is not None:
32 - self.tempcache[url] = result
33 - bs = 1024*8
34 - size = -1
35 - read = 0
36 - blocknum = 0
37 - if reporthook:
38 - if "content-length" in headers:
39 - size = int(headers["Content-Length"])
40 - reporthook(blocknum, bs, size)
41 - while 1:
42 - block = fp.read(bs)
43 - if block == "":
44 - break
45 - read += len(block)
46 - tfp.write(block)
47 - blocknum += 1
48 - if reporthook:
49 - reporthook(blocknum, bs, size)
50 - fp.close()
51 - tfp.close()
52 + try:
53 + headers = fp.info()
54 + if filename:
55 + tfp = open(filename, 'wb')
56 + else:
57 + import tempfile
58 + garbage, path = splittype(url)
59 + garbage, path = splithost(path or "")
60 + path, garbage = splitquery(path or "")
61 + path, garbage = splitattr(path or "")
62 + suffix = os.path.splitext(path)[1]
63 + (fd, filename) = tempfile.mkstemp(suffix)
64 + self.__tempfiles.append(filename)
65 + tfp = os.fdopen(fd, 'wb')
66 + try:
67 + result = filename, headers
68 + if self.tempcache is not None:
69 + self.tempcache[url] = result
70 + bs = 1024*8
71 + size = -1
72 + read = 0
73 + blocknum = 0
74 + if reporthook:
75 + if "content-length" in headers:
76 + size = int(headers["Content-Length"])
77 + reporthook(blocknum, bs, size)
78 + while 1:
79 + block = fp.read(bs)
80 + if block == "":
81 + break
82 + read += len(block)
83 + tfp.write(block)
84 + blocknum += 1
85 + if reporthook:
86 + reporthook(blocknum, bs, size)
87 + finally:
88 + tfp.close()
89 + finally:
90 + fp.close()
91 del fp
92 del tfp