Use except .. as everywhere (#180)

This commit is contained in:
Philipp Hagemeister
2012-11-27 23:31:55 +01:00
parent 96731798db
commit e08bee320e
4 changed files with 84 additions and 84 deletions

View File

@ -74,7 +74,7 @@ def updateSelf(downloader, filename):
urlh.close()
with open(exe + '.new', 'wb') as outf:
outf.write(newcontent)
except (IOError, OSError), err:
except (IOError, OSError) as err:
sys.exit('ERROR: unable to download latest version')
try:
@ -89,7 +89,7 @@ del "%s"
b.close()
os.startfile(bat)
except (IOError, OSError), err:
except (IOError, OSError) as err:
sys.exit('ERROR: unable to overwrite current version')
else:
@ -97,13 +97,13 @@ del "%s"
urlh = urllib2.urlopen(UPDATE_URL)
newcontent = urlh.read()
urlh.close()
except (IOError, OSError), err:
except (IOError, OSError) as err:
sys.exit('ERROR: unable to download latest version')
try:
with open(filename, 'wb') as outf:
outf.write(newcontent)
except (IOError, OSError), err:
except (IOError, OSError) as err:
sys.exit('ERROR: unable to overwrite current version')
downloader.to_screen(u'Updated youtube-dl. Restart youtube-dl to use the new version.')
@ -386,7 +386,7 @@ def _real_main():
jar = cookielib.MozillaCookieJar(opts.cookiefile)
if os.path.isfile(opts.cookiefile) and os.access(opts.cookiefile, os.R_OK):
jar.load()
except (IOError, OSError), err:
except (IOError, OSError) as err:
sys.exit(u'ERROR: unable to open cookie file')
# Set user agent
if opts.user_agent is not None:
@ -394,7 +394,7 @@ def _real_main():
# Dump user agent
if opts.dump_user_agent:
print std_headers['User-Agent']
print(std_headers['User-Agent'])
sys.exit(0)
# Batch file verification
@ -450,7 +450,7 @@ def _real_main():
if opts.retries is not None:
try:
opts.retries = int(opts.retries)
except (TypeError, ValueError), err:
except (TypeError, ValueError) as err:
parser.error(u'invalid retry count specified')
if opts.buffersize is not None:
numeric_buffersize = FileDownloader.parse_bytes(opts.buffersize)
@ -461,13 +461,13 @@ def _real_main():
opts.playliststart = int(opts.playliststart)
if opts.playliststart <= 0:
raise ValueError(u'Playlist start must be positive')
except (TypeError, ValueError), err:
except (TypeError, ValueError) as err:
parser.error(u'invalid playlist start number specified')
try:
opts.playlistend = int(opts.playlistend)
if opts.playlistend != -1 and (opts.playlistend <= 0 or opts.playlistend < opts.playliststart):
raise ValueError(u'Playlist end must be greater than playlist start')
except (TypeError, ValueError), err:
except (TypeError, ValueError) as err:
parser.error(u'invalid playlist end number specified')
if opts.extractaudio:
if opts.audioformat not in ['best', 'aac', 'mp3', 'vorbis', 'm4a', 'wav']:
@ -559,7 +559,7 @@ def _real_main():
if opts.cookiefile is not None:
try:
jar.save()
except (IOError, OSError), err:
except (IOError, OSError) as err:
sys.exit(u'ERROR: unable to save cookie jar')
sys.exit(retcode)