Skip to content
This repository has been archived by the owner on Jul 9, 2024. It is now read-only.

Commit

Permalink
Fix to catch appropriate exceptions and style of code.
Browse files Browse the repository at this point in the history
  • Loading branch information
yamaneko1212 committed Apr 17, 2012
1 parent 5ebf9d8 commit 9a4c85b
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions pythonz/genericdownloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ def __init__(self, out=sys.stdout):

def update_line(self, current):
num_bar = int(current / 100.0 * (self._term_width - 5))
return '#' * num_bar + ' ' * (self._term_width - 5 - num_bar) + \
u' %3d' % int(current) + u'%\r'
bars = u'#' * num_bar
spaces = u' ' * (self._term_width - 5 - num_bar)
percentage = u'%3d' % int(current) + u'%\r'
return bars + spaces + u' ' + percentage

def reporthook(self, blocknum, bs, size):
current = (blocknum * bs * 100) / size
Expand All @@ -42,7 +44,7 @@ def can_use(cls):
def read(self, url):
try:
r = urllib.urlopen(url)
except:
except IOError:
logger.log(traceback.format_exc())
raise CurlFetchException('Failed to fetch.')
return r.read()
Expand All @@ -51,7 +53,7 @@ def readheader(self, url):
try:
req = HEADRequest(url)
res = urllib2.urlopen(req)
except:
except IOError:
logger.log(traceback.format_exc())
raise CurlFetchException('Failed to fetch.')
if res.code != 200:
Expand All @@ -61,9 +63,9 @@ def readheader(self, url):
def fetch(self, url, filename):
b = ProgressBar()
try:
r = urllib.urlretrieve(url, filename, b.reporthook)
urllib.urlretrieve(url, filename, b.reporthook)
sys.stdout.write('\n')
except:
except IOError:
sys.stdout.write('\n')
logger.log(traceback.format_exc())
raise CurlFetchException('Failed to fetch.')

0 comments on commit 9a4c85b

Please sign in to comment.