diff options
author | Gonzalo Odiard <godiard@sugarlabs.org> | 2011-03-22 17:01:52 (GMT) |
---|---|---|
committer | Gonzalo Odiard <godiard@sugarlabs.org> | 2011-03-22 17:01:52 (GMT) |
commit | 42d499f0c562e03f4fc1da1162299128c8c4162c (patch) | |
tree | 2316fd021c8713c37d884ac01e89d4757004a3d4 /GetIABooksActivity.py | |
parent | 2650d4a5b8b99879dcf8f1ae1124b909789d33ed (diff) |
Avoid error if the book server does not set Content-Length in the http header
Diffstat (limited to 'GetIABooksActivity.py')
-rwxr-xr-x | GetIABooksActivity.py | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/GetIABooksActivity.py b/GetIABooksActivity.py index 11a58b7..56778ce 100755 --- a/GetIABooksActivity.py +++ b/GetIABooksActivity.py @@ -67,7 +67,11 @@ class ReadURLDownloader(network.GlibURLDownloader): def get_content_length(self): """Return the content-length of the download.""" if self._info is not None: - return int(self._info.headers.get('Content-Length')) + length = self._info.headers.get('Content-Length') + if length is not None: + return int(length) + else: + return 0 def get_content_type(self): """Return the content-type of the download.""" @@ -388,7 +392,7 @@ class GetIABooksActivity(activity.Activity): os.remove(tempfile) def _get_image_progress_cb(self, getter, bytes_downloaded): - if self._download_content_length > 0: + if self._download_image_content_length > 0: _logger.debug("Downloaded %u of %u bytes...", bytes_downloaded, self._download_image_content_length) else: |