aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'lib-python/2.7/urllib.py')
-rw-r--r--lib-python/2.7/urllib.py17
1 files changed, 12 insertions, 5 deletions
diff --git a/lib-python/2.7/urllib.py b/lib-python/2.7/urllib.py
index 33962968b1..87bcd94db5 100644
--- a/lib-python/2.7/urllib.py
+++ b/lib-python/2.7/urllib.py
@@ -203,7 +203,9 @@ class URLopener:
name = 'open_' + urltype
self.type = urltype
name = name.replace('-', '_')
- if not hasattr(self, name):
+
+ # bpo-35907: disallow the file reading with the type not allowed
+ if not hasattr(self, name) or name == 'open_local_file':
if proxy:
return self.open_unknown_proxy(proxy, fullurl, data)
else:
@@ -932,7 +934,13 @@ class ftpwrapper:
return (ftpobj, retrlen)
def endtransfer(self):
+ if not self.busy:
+ return
self.busy = 0
+ try:
+ self.ftp.voidresp()
+ except ftperrors():
+ pass
def close(self):
self.keepalive = False
@@ -1093,8 +1101,7 @@ def splithost(url):
"""splithost('//host[:port]/path') --> 'host[:port]', '/path'."""
global _hostprog
if _hostprog is None:
- import re
- _hostprog = re.compile('^//([^/?]*)(.*)$')
+ _hostprog = re.compile('//([^/#?]*)(.*)', re.DOTALL)
match = _hostprog.match(url)
if match:
@@ -1237,8 +1244,7 @@ def unquote(s):
return s
res = [bits[0]]
append = res.append
- for j in xrange(1, len(bits)):
- item = bits[j]
+ for item in bits[1:]:
try:
append(_hextochr[item[:2]])
append(item[2:])
@@ -1428,6 +1434,7 @@ def proxy_bypass_environment(host, proxies=None):
no_proxy_list = [proxy.strip() for proxy in no_proxy.split(',')]
for name in no_proxy_list:
if name:
+ name = name.lstrip('.') # ignore leading dots
name = re.escape(name)
pattern = r'(.+\.)?%s$' % name
if (re.match(pattern, hostonly, re.I)