Kaydet (Commit) f90b002e authored tarafından Jeremy Hylton's avatar Jeremy Hylton

change indentation from 8 spaces to 4 spaces

üst 547c3f1c
...@@ -247,12 +247,9 @@ class URLopener: ...@@ -247,12 +247,9 @@ class URLopener:
else: else:
realhost, rest = splithost(rest) realhost, rest = splithost(rest)
if realhost: if realhost:
user_passwd, realhost = \ user_passwd, realhost = splituser(realhost)
splituser(realhost)
if user_passwd: if user_passwd:
selector = "%s://%s%s" % (urltype, selector = "%s://%s%s" % (urltype, realhost, rest)
realhost,
rest)
#print "proxy via http:", host, selector #print "proxy via http:", host, selector
if not host: raise IOError, ('http error', 'no host given') if not host: raise IOError, ('http error', 'no host given')
if user_passwd: if user_passwd:
...@@ -263,8 +260,7 @@ class URLopener: ...@@ -263,8 +260,7 @@ class URLopener:
h = httplib.HTTP(host) h = httplib.HTTP(host)
if data is not None: if data is not None:
h.putrequest('POST', selector) h.putrequest('POST', selector)
h.putheader('Content-type', h.putheader('Content-type', 'application/x-www-form-urlencoded')
'application/x-www-form-urlencoded')
h.putheader('Content-length', '%d' % len(data)) h.putheader('Content-length', '%d' % len(data))
else: else:
h.putrequest('GET', selector) h.putrequest('GET', selector)
...@@ -280,16 +276,10 @@ class URLopener: ...@@ -280,16 +276,10 @@ class URLopener:
return addinfourl(fp, headers, "http:" + url) return addinfourl(fp, headers, "http:" + url)
else: else:
if data is None: if data is None:
return self.http_error(url, return self.http_error(url, fp, errcode, errmsg,
fp, errcode, headers, data)
errmsg,
headers,
data)
else: else:
return self.http_error(url, return self.http_error(url, fp, errcode, errmsg, headers)
fp, errcode,
errmsg,
headers)
# Handle http errors. # Handle http errors.
# Derived class can override this, or provide specific handlers # Derived class can override this, or provide specific handlers
...@@ -300,11 +290,9 @@ class URLopener: ...@@ -300,11 +290,9 @@ class URLopener:
if hasattr(self, name): if hasattr(self, name):
method = getattr(self, name) method = getattr(self, name)
if data is None: if data is None:
result = method(url, fp, errcode, errmsg, result = method(url, fp, errcode, errmsg, headers, data)
headers, data)
else: else:
result = method(url, fp, errcode, errmsg, result = method(url, fp, errcode, errmsg, headers)
headers)
if result: return result if result: return result
return self.http_error_default( return self.http_error_default(
url, fp, errcode, errmsg, headers) url, fp, errcode, errmsg, headers)
...@@ -346,14 +334,12 @@ class URLopener: ...@@ -346,14 +334,12 @@ class URLopener:
'Content-Type: %s\n' % (mtype or 'text/plain'))) 'Content-Type: %s\n' % (mtype or 'text/plain')))
host, file = splithost(url) host, file = splithost(url)
if not host: if not host:
return addinfourl( return addinfourl(open(url2pathname(file), 'rb'),
open(url2pathname(file), 'rb'),
headers, 'file:'+pathname2url(file)) headers, 'file:'+pathname2url(file))
host, port = splitport(host) host, port = splitport(host)
if not port and socket.gethostbyname(host) in ( if not port \
localhost(), thishost()): and socket.gethostbyname(host) in (localhost(), thishost()):
return addinfourl( return addinfourl(open(url2pathname(file), 'rb'),
open(url2pathname(file), 'rb'),
headers, 'file:'+pathname2url(file)) headers, 'file:'+pathname2url(file))
raise IOError, ('local file error', 'not on local host') raise IOError, ('local file error', 'not on local host')
...@@ -391,8 +377,7 @@ class URLopener: ...@@ -391,8 +377,7 @@ class URLopener:
try: try:
if not self.ftpcache.has_key(key): if not self.ftpcache.has_key(key):
self.ftpcache[key] = \ self.ftpcache[key] = \
ftpwrapper(user, passwd, ftpwrapper(user, passwd, host, port, dirs)
host, port, dirs)
if not file: type = 'D' if not file: type = 'D'
else: type = 'I' else: type = 'I'
for attr in attrs: for attr in attrs:
...@@ -488,13 +473,11 @@ class FancyURLopener(URLopener): ...@@ -488,13 +473,11 @@ class FancyURLopener(URLopener):
if headers.has_key('www-authenticate'): if headers.has_key('www-authenticate'):
stuff = headers['www-authenticate'] stuff = headers['www-authenticate']
import re import re
match = re.match( match = re.match('[ \t]*([^ \t]+)[ \t]+realm="([^"]*)"', stuff)
'[ \t]*([^ \t]+)[ \t]+realm="([^"]*)"', stuff)
if match: if match:
scheme, realm = match.groups() scheme, realm = match.groups()
if string.lower(scheme) == 'basic': if string.lower(scheme) == 'basic':
return self.retry_http_basic_auth( return self.retry_http_basic_auth(url, realm, data)
url, realm, data)
def retry_http_basic_auth(self, url, realm, data): def retry_http_basic_auth(self, url, realm, data):
host, selector = splithost(url) host, selector = splithost(url)
...@@ -521,10 +504,9 @@ class FancyURLopener(URLopener): ...@@ -521,10 +504,9 @@ class FancyURLopener(URLopener):
# Override this in a GUI environment! # Override this in a GUI environment!
import getpass import getpass
try: try:
user = raw_input("Enter username for %s at %s: " % user = raw_input("Enter username for %s at %s: " % (realm,
(realm, host)) host))
passwd = getpass.getpass( passwd = getpass.getpass("Enter password for %s in %s at %s: " %
"Enter password for %s in %s at %s: " %
(user, realm, host)) (user, realm, host))
return user, passwd return user, passwd
except KeyboardInterrupt: except KeyboardInterrupt:
...@@ -606,8 +588,7 @@ class ftpwrapper: ...@@ -606,8 +588,7 @@ class ftpwrapper:
try: try:
self.ftp.nlst(file) self.ftp.nlst(file)
except ftplib.error_perm, reason: except ftplib.error_perm, reason:
raise IOError, ('ftp error', reason), \ raise IOError, ('ftp error', reason), sys.exc_info()[2]
sys.exc_info()[2]
# Restore the transfer mode! # Restore the transfer mode!
self.ftp.voidcmd(cmd) self.ftp.voidcmd(cmd)
# Try to retrieve as a file # Try to retrieve as a file
...@@ -616,8 +597,7 @@ class ftpwrapper: ...@@ -616,8 +597,7 @@ class ftpwrapper:
conn = self.ftp.ntransfercmd(cmd) conn = self.ftp.ntransfercmd(cmd)
except ftplib.error_perm, reason: except ftplib.error_perm, reason:
if reason[:3] != '550': if reason[:3] != '550':
raise IOError, ('ftp error', reason), \ raise IOError, ('ftp error', reason), sys.exc_info()[2]
sys.exc_info()[2]
if not conn: if not conn:
# Set transfer mode to ASCII! # Set transfer mode to ASCII!
self.ftp.voidcmd('TYPE A') self.ftp.voidcmd('TYPE A')
...@@ -627,7 +607,8 @@ class ftpwrapper: ...@@ -627,7 +607,8 @@ class ftpwrapper:
conn = self.ftp.ntransfercmd(cmd) conn = self.ftp.ntransfercmd(cmd)
self.busy = 1 self.busy = 1
# Pass back both a suitably decorated object and a retrieval length # 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): def endtransfer(self):
if not self.busy: if not self.busy:
return return
...@@ -652,8 +633,8 @@ class addbase: ...@@ -652,8 +633,8 @@ class addbase:
self.readlines = self.fp.readlines self.readlines = self.fp.readlines
self.fileno = self.fp.fileno self.fileno = self.fp.fileno
def __repr__(self): def __repr__(self):
return '<%s at %s whose fp = %s>' % ( return '<%s at %s whose fp = %s>' % (self.__class__.__name__,
self.__class__.__name__, `id(self)`, `self.fp`) `id(self)`, `self.fp`)
def close(self): def close(self):
self.read = None self.read = None
self.readline = None self.readline = None
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment