mirror of
https://github.com/python/cpython.git
synced 2025-07-23 11:15:24 +00:00
change indentation from 8 spaces to 4 spaces
This commit is contained in:
parent
547c3f1c13
commit
f90b002e31
1 changed files with 832 additions and 851 deletions
|
@ -247,12 +247,9 @@ class URLopener:
|
|||
else:
|
||||
realhost, rest = splithost(rest)
|
||||
if realhost:
|
||||
user_passwd, realhost = \
|
||||
splituser(realhost)
|
||||
user_passwd, realhost = splituser(realhost)
|
||||
if user_passwd:
|
||||
selector = "%s://%s%s" % (urltype,
|
||||
realhost,
|
||||
rest)
|
||||
selector = "%s://%s%s" % (urltype, realhost, rest)
|
||||
#print "proxy via http:", host, selector
|
||||
if not host: raise IOError, ('http error', 'no host given')
|
||||
if user_passwd:
|
||||
|
@ -263,8 +260,7 @@ class URLopener:
|
|||
h = httplib.HTTP(host)
|
||||
if data is not None:
|
||||
h.putrequest('POST', selector)
|
||||
h.putheader('Content-type',
|
||||
'application/x-www-form-urlencoded')
|
||||
h.putheader('Content-type', 'application/x-www-form-urlencoded')
|
||||
h.putheader('Content-length', '%d' % len(data))
|
||||
else:
|
||||
h.putrequest('GET', selector)
|
||||
|
@ -280,16 +276,10 @@ class URLopener:
|
|||
return addinfourl(fp, headers, "http:" + url)
|
||||
else:
|
||||
if data is None:
|
||||
return self.http_error(url,
|
||||
fp, errcode,
|
||||
errmsg,
|
||||
headers,
|
||||
data)
|
||||
return self.http_error(url, fp, errcode, errmsg,
|
||||
headers, data)
|
||||
else:
|
||||
return self.http_error(url,
|
||||
fp, errcode,
|
||||
errmsg,
|
||||
headers)
|
||||
return self.http_error(url, fp, errcode, errmsg, headers)
|
||||
|
||||
# Handle http errors.
|
||||
# Derived class can override this, or provide specific handlers
|
||||
|
@ -300,11 +290,9 @@ class URLopener:
|
|||
if hasattr(self, name):
|
||||
method = getattr(self, name)
|
||||
if data is None:
|
||||
result = method(url, fp, errcode, errmsg,
|
||||
headers, data)
|
||||
result = method(url, fp, errcode, errmsg, headers, data)
|
||||
else:
|
||||
result = method(url, fp, errcode, errmsg,
|
||||
headers)
|
||||
result = method(url, fp, errcode, errmsg, headers)
|
||||
if result: return result
|
||||
return self.http_error_default(
|
||||
url, fp, errcode, errmsg, headers)
|
||||
|
@ -346,14 +334,12 @@ class URLopener:
|
|||
'Content-Type: %s\n' % (mtype or 'text/plain')))
|
||||
host, file = splithost(url)
|
||||
if not host:
|
||||
return addinfourl(
|
||||
open(url2pathname(file), 'rb'),
|
||||
return addinfourl(open(url2pathname(file), 'rb'),
|
||||
headers, 'file:'+pathname2url(file))
|
||||
host, port = splitport(host)
|
||||
if not port and socket.gethostbyname(host) in (
|
||||
localhost(), thishost()):
|
||||
return addinfourl(
|
||||
open(url2pathname(file), 'rb'),
|
||||
if not port \
|
||||
and socket.gethostbyname(host) in (localhost(), thishost()):
|
||||
return addinfourl(open(url2pathname(file), 'rb'),
|
||||
headers, 'file:'+pathname2url(file))
|
||||
raise IOError, ('local file error', 'not on local host')
|
||||
|
||||
|
@ -391,8 +377,7 @@ class URLopener:
|
|||
try:
|
||||
if not self.ftpcache.has_key(key):
|
||||
self.ftpcache[key] = \
|
||||
ftpwrapper(user, passwd,
|
||||
host, port, dirs)
|
||||
ftpwrapper(user, passwd, host, port, dirs)
|
||||
if not file: type = 'D'
|
||||
else: type = 'I'
|
||||
for attr in attrs:
|
||||
|
@ -488,13 +473,11 @@ class FancyURLopener(URLopener):
|
|||
if headers.has_key('www-authenticate'):
|
||||
stuff = headers['www-authenticate']
|
||||
import re
|
||||
match = re.match(
|
||||
'[ \t]*([^ \t]+)[ \t]+realm="([^"]*)"', stuff)
|
||||
match = re.match('[ \t]*([^ \t]+)[ \t]+realm="([^"]*)"', stuff)
|
||||
if match:
|
||||
scheme, realm = match.groups()
|
||||
if string.lower(scheme) == 'basic':
|
||||
return self.retry_http_basic_auth(
|
||||
url, realm, data)
|
||||
return self.retry_http_basic_auth(url, realm, data)
|
||||
|
||||
def retry_http_basic_auth(self, url, realm, data):
|
||||
host, selector = splithost(url)
|
||||
|
@ -521,10 +504,9 @@ class FancyURLopener(URLopener):
|
|||
# Override this in a GUI environment!
|
||||
import getpass
|
||||
try:
|
||||
user = raw_input("Enter username for %s at %s: " %
|
||||
(realm, host))
|
||||
passwd = getpass.getpass(
|
||||
"Enter password for %s in %s at %s: " %
|
||||
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))
|
||||
return user, passwd
|
||||
except KeyboardInterrupt:
|
||||
|
@ -606,8 +588,7 @@ class ftpwrapper:
|
|||
try:
|
||||
self.ftp.nlst(file)
|
||||
except ftplib.error_perm, reason:
|
||||
raise IOError, ('ftp error', reason), \
|
||||
sys.exc_info()[2]
|
||||
raise IOError, ('ftp error', reason), sys.exc_info()[2]
|
||||
# Restore the transfer mode!
|
||||
self.ftp.voidcmd(cmd)
|
||||
# Try to retrieve as a file
|
||||
|
@ -616,8 +597,7 @@ class ftpwrapper:
|
|||
conn = self.ftp.ntransfercmd(cmd)
|
||||
except ftplib.error_perm, reason:
|
||||
if reason[:3] != '550':
|
||||
raise IOError, ('ftp error', reason), \
|
||||
sys.exc_info()[2]
|
||||
raise IOError, ('ftp error', reason), sys.exc_info()[2]
|
||||
if not conn:
|
||||
# Set transfer mode to ASCII!
|
||||
self.ftp.voidcmd('TYPE A')
|
||||
|
@ -627,7 +607,8 @@ class ftpwrapper:
|
|||
conn = self.ftp.ntransfercmd(cmd)
|
||||
self.busy = 1
|
||||
# Pass back both a suitably decorated object and a retrieval length
|
||||
return (addclosehook(conn[0].makefile('rb'), self.endtransfer), conn[1])
|
||||
return (addclosehook(conn[0].makefile('rb'),
|
||||
self.endtransfer), conn[1])
|
||||
def endtransfer(self):
|
||||
if not self.busy:
|
||||
return
|
||||
|
@ -652,8 +633,8 @@ class addbase:
|
|||
self.readlines = self.fp.readlines
|
||||
self.fileno = self.fp.fileno
|
||||
def __repr__(self):
|
||||
return '<%s at %s whose fp = %s>' % (
|
||||
self.__class__.__name__, `id(self)`, `self.fp`)
|
||||
return '<%s at %s whose fp = %s>' % (self.__class__.__name__,
|
||||
`id(self)`, `self.fp`)
|
||||
def close(self):
|
||||
self.read = None
|
||||
self.readline = None
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue