From b01906a45c7b745a487af535310373a890b2758a Mon Sep 17 00:00:00 2001 From: Jakub Roztocil Date: Tue, 18 Feb 2014 13:06:12 +0100 Subject: [PATCH] Fixed ZeroDivisionError in download summary. Closes #202 --- httpie/downloads.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/httpie/downloads.py b/httpie/downloads.py index acce1243..cdcaa1cb 100644 --- a/httpie/downloads.py +++ b/httpie/downloads.py @@ -417,11 +417,20 @@ class ProgressReporterThread(threading.Thread): time_taken = self.status.time_finished - self.status.time_started self.output.write(CLEAR_LINE) + + try: + speed = actually_downloaded / time_taken + except ZeroDivisionError: + # Either time is 0 (not all systems provide `time.time` + # with a better precision than 1 second), and/or nothing + # has been downloaded. + speed = actually_downloaded + self.output.write(SUMMARY.format( downloaded=humanize_bytes(actually_downloaded), total=(self.status.total_size and humanize_bytes(self.status.total_size)), - speed=humanize_bytes(actually_downloaded / time_taken), + speed=humanize_bytes(speed), time=time_taken, )) self.output.flush()