[Python-checkins] CVS: python/dist/src/Lib urllib.py,1.105,1.106
Fredrik Lundh
python-dev@python.org
Sun, 24 Sep 2000 11:51:28 -0700
Update of /cvsroot/python/python/dist/src/Lib
In directory slayer.i.sourceforge.net:/tmp/cvs-serv28055/Lib
Modified Files:
urllib.py
Log Message:
- Improved handling of win32 proxy settings (addresses bug #114256).
The earlier code assumed "protocol=host;protocol=host;..." or "host",
but Windows may also use "protocol=host" (just one entry), as well as
"protocol://host". This code needs some more work, so I'll leave the
bug open for now.
Index: urllib.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/urllib.py,v
retrieving revision 1.105
retrieving revision 1.106
diff -C2 -r1.105 -r1.106
*** urllib.py 2000/09/14 16:59:06 1.105
--- urllib.py 2000/09/24 18:51:25 1.106
***************
*** 17,21 ****
protocol. All you know is that is has methods read(), readline(),
readlines(), fileno(), close() and info(). The read*(), fileno()
! and close() methods work like those of open files.
The info() method returns a mimetools.Message object which can be
used to query various info about the object, if available.
--- 17,21 ----
protocol. All you know is that is has methods read(), readline(),
readlines(), fileno(), close() and info(). The read*(), fileno()
! and close() methods work like those of open files.
The info() method returns a mimetools.Message object which can be
used to query various info about the object, if available.
***************
*** 37,41 ****
from macurl2path import url2pathname, pathname2url
elif os.name == 'nt':
! from nturl2path import url2pathname, pathname2url
else:
def url2pathname(pathname):
--- 37,41 ----
from macurl2path import url2pathname, pathname2url
elif os.name == 'nt':
! from nturl2path import url2pathname, pathname2url
else:
def url2pathname(pathname):
***************
*** 396,400 ****
host, port = splitport(host)
if not port \
! and socket.gethostbyname(host) in (localhost(), thishost()):
urlfile = file
if file[:1] == '/':
--- 396,400 ----
host, port = splitport(host)
if not port \
! and socket.gethostbyname(host) in (localhost(), thishost()):
urlfile = file
if file[:1] == '/':
***************
*** 510,514 ****
return addinfourl(fp, headers, "http:" + url)
! def http_error_302(self, url, fp, errcode, errmsg, headers, data=None):
"""Error 302 -- relocated (temporarily)."""
# XXX The server can force infinite recursion here!
--- 510,514 ----
return addinfourl(fp, headers, "http:" + url)
! def http_error_302(self, url, fp, errcode, errmsg, headers, data=None):
"""Error 302 -- relocated (temporarily)."""
# XXX The server can force infinite recursion here!
***************
*** 528,536 ****
return self.open(newurl, data)
! def http_error_301(self, url, fp, errcode, errmsg, headers, data=None):
"""Error 301 -- also relocated (permanently)."""
return self.http_error_302(url, fp, errcode, errmsg, headers, data)
! def http_error_401(self, url, fp, errcode, errmsg, headers, data=None):
"""Error 401 -- authentication required.
See this URL for a description of the basic authentication scheme:
--- 528,536 ----
return self.open(newurl, data)
! def http_error_301(self, url, fp, errcode, errmsg, headers, data=None):
"""Error 301 -- also relocated (permanently)."""
return self.http_error_302(url, fp, errcode, errmsg, headers, data)
! def http_error_401(self, url, fp, errcode, errmsg, headers, data=None):
"""Error 401 -- authentication required.
See this URL for a description of the basic authentication scheme:
***************
*** 561,565 ****
else:
return self.open(newurl, data)
!
def retry_https_basic_auth(self, url, realm, data=None):
host, selector = splithost(url)
--- 561,565 ----
else:
return self.open(newurl, data)
!
def retry_https_basic_auth(self, url, realm, data=None):
host, selector = splithost(url)
***************
*** 588,592 ****
try:
user = raw_input("Enter username for %s at %s: " % (realm,
! host))
passwd = getpass.getpass("Enter password for %s in %s at %s: " %
(user, realm, host))
--- 588,592 ----
try:
user = raw_input("Enter username for %s at %s: " % (realm,
! host))
passwd = getpass.getpass("Enter password for %s in %s at %s: " %
(user, realm, host))
***************
*** 694,698 ****
# Pass back both a suitably decorated object and a retrieval length
return (addclosehook(conn[0].makefile('rb'),
! self.endtransfer), conn[1])
def endtransfer(self):
if not self.busy:
--- 694,698 ----
# Pass back both a suitably decorated object and a retrieval length
return (addclosehook(conn[0].makefile('rb'),
! self.endtransfer), conn[1])
def endtransfer(self):
if not self.busy:
***************
*** 723,727 ****
def __repr__(self):
return '<%s at %s whose fp = %s>' % (self.__class__.__name__,
! `id(self)`, `self.fp`)
def close(self):
--- 723,727 ----
def __repr__(self):
return '<%s at %s whose fp = %s>' % (self.__class__.__name__,
! `id(self)`, `self.fp`)
def close(self):
***************
*** 821,825 ****
else:
basepath = ''
!
path = basepath + path
if type and host: return type + '://' + host + path
--- 821,825 ----
else:
basepath = ''
!
path = basepath + path
if type and host: return type + '://' + host + path
***************
*** 875,879 ****
_hostprog = re.compile('^//([^/]*)(.*)$')
! match = _hostprog.match(url)
if match: return match.group(1, 2)
return None, url
--- 875,879 ----
_hostprog = re.compile('^//([^/]*)(.*)$')
! match = _hostprog.match(url)
if match: return match.group(1, 2)
return None, url
***************
*** 1012,1016 ****
return unquote(s)
! always_safe = ('ABCDEFGHIJKLMNOPQRSTUVWXYZ'
'abcdefghijklmnopqrstuvwxyz'
'0123456789' '_.-')
--- 1012,1016 ----
return unquote(s)
! always_safe = ('ABCDEFGHIJKLMNOPQRSTUVWXYZ'
'abcdefghijklmnopqrstuvwxyz'
'0123456789' '_.-')
***************
*** 1034,1038 ****
def quote(s, safe = '/'):
"""quote('abc def') -> 'abc%20def'
!
Each part of a URL, e.g. the path info, the query, etc., has a
different set of reserved characters that must be quoted.
--- 1034,1038 ----
def quote(s, safe = '/'):
"""quote('abc def') -> 'abc%20def'
!
Each part of a URL, e.g. the path info, the query, etc., has a
different set of reserved characters that must be quoted.
***************
*** 1112,1116 ****
except ImportError:
return {}
!
try:
config = ic.IC()
--- 1112,1116 ----
except ImportError:
return {}
!
try:
config = ic.IC()
***************
*** 1144,1149 ****
return proxies
try:
! internetSettings = _winreg.OpenKey(_winreg.HKEY_CURRENT_USER,
! 'Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings')
proxyEnable = _winreg.QueryValueEx(internetSettings,
'ProxyEnable')[0]
--- 1144,1149 ----
return proxies
try:
! internetSettings = _winreg.OpenKey(_winreg.HKEY_CURRENT_USER,
! r'Software\Microsoft\Windows\CurrentVersion\Internet Settings')
proxyEnable = _winreg.QueryValueEx(internetSettings,
'ProxyEnable')[0]
***************
*** 1152,1162 ****
proxyServer = str(_winreg.QueryValueEx(internetSettings,
'ProxyServer')[0])
! if ';' in proxyServer: # Per-protocol settings
for p in proxyServer.split(';'):
! protocol, address = p.split('=')
proxies[protocol] = '%s://%s' % (protocol, address)
! else: # Use one setting for all protocols
! proxies['http'] = 'http://%s' % proxyServer
! proxies['ftp'] = 'ftp://%s' % proxyServer
internetSettings.Close()
except (WindowsError, ValueError, TypeError):
--- 1152,1167 ----
proxyServer = str(_winreg.QueryValueEx(internetSettings,
'ProxyServer')[0])
! if '=' in proxyServer:
! # Per-protocol settings
for p in proxyServer.split(';'):
! protocol, address = p.split('=', 1)
proxies[protocol] = '%s://%s' % (protocol, address)
! else:
! # Use one setting for all protocols
! if proxyServer[:5] == 'http:':
! proxies['http'] = proxyServer
! else:
! proxies['http'] = 'http://%s' % proxyServer
! proxies['ftp'] = 'ftp://%s' % proxyServer
internetSettings.Close()
except (WindowsError, ValueError, TypeError):