From 0f96348fd1f5435a36ce40f33357fb1872774880 Mon Sep 17 00:00:00 2001 From: Jakub Roztocil Date: Sat, 28 Jun 2014 20:44:40 +0200 Subject: [PATCH] Cleanup --- README.rst | 1 + httpie/downloads.py | 16 ++++++++-------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/README.rst b/README.rst index 4253b434..1e27a33f 100644 --- a/README.rst +++ b/README.rst @@ -53,6 +53,7 @@ Main Features * Wget-like downloads * Python 2.6, 2.7 and 3.x support * Linux, Mac OS X and Windows support +* Plugins * Documentation * Test coverage diff --git a/httpie/downloads.py b/httpie/downloads.py index c88e2983..77a8de67 100644 --- a/httpie/downloads.py +++ b/httpie/downloads.py @@ -135,12 +135,12 @@ def filename_from_url(url, content_type): return fn -def get_unique_filename(fn, exists=os.path.exists): +def get_unique_filename(filename, exists=os.path.exists): attempt = 0 while True: suffix = '-' + str(attempt) if attempt > 0 else '' - if not exists(fn + suffix): - return fn + suffix + if not exists(filename + suffix): + return filename + suffix attempt += 1 @@ -223,16 +223,16 @@ class Download(object): else: # TODO: Should the filename be taken from response.history[0].url? # Output file not specified. Pick a name that doesn't exist yet. - fn = None + filename = None if 'Content-Disposition' in response.headers: - fn = filename_from_content_disposition( + filename = filename_from_content_disposition( response.headers['Content-Disposition']) - if not fn: - fn = filename_from_url( + if not filename: + filename = filename_from_url( url=response.url, content_type=response.headers.get('Content-Type'), ) - self._output_file = open(get_unique_filename(fn), mode='a+b') + self._output_file = open(get_unique_filename(filename), mode='a+b') self.status.started( resumed_from=self._resumed_from,