diff --git a/ChangeLog.txt b/ChangeLog.txt index 997873d..793f765 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -9,6 +9,7 @@ each version. - NEW: Added support for Python 3.6. - IMPROVE: Updated the user agents list. - IMPROVE: Less memory-hungry hashing function. +- IMPROVE: Minor improvements. - FIX: Bug fixes. (Version 1.2.4 beta; 02/12/14) diff --git a/pySmartDL/pySmartDL.py b/pySmartDL/pySmartDL.py index 8d3533c..1f9f0c5 100644 --- a/pySmartDL/pySmartDL.py +++ b/pySmartDL/pySmartDL.py @@ -80,7 +80,9 @@ def __init__(self, urls, dest=None, progress_bar=True, fix_urls=True, threads=5, self.mirrors = [utils.url_fix(x) for x in self.mirrors] self.url = self.mirrors.pop(0) - fn = urllib2.unquote(os.path.basename(urlparse(self.url).path)).decode('utf-8') + fn = urllib2.unquote(os.path.basename(urlparse(self.url).path)) + if sys.version_info < (3, 0): + fn = fn.decode('utf-8') # required only on python 2 self.dest = dest or os.path.join(tempfile.gettempdir(), 'pySmartDL', fn) if self.dest[-1] == os.sep: if os.path.exists(self.dest[:-1]) and os.path.isfile(self.dest[:-1]): diff --git a/pySmartDL/utils.py b/pySmartDL/utils.py index dd7f79e..28c67d6 100644 --- a/pySmartDL/utils.py +++ b/pySmartDL/utils.py @@ -128,7 +128,7 @@ def get_filesize(url, timeout=15): return 0 try: file_size = int(urlObj.headers["Content-Length"]) - except (IndexError,KeyError): + except (IndexError, KeyError, TypeError): return 0 return file_size diff --git a/setup.py b/setup.py index b4b3a15..194fcab 100644 --- a/setup.py +++ b/setup.py @@ -19,7 +19,7 @@ description='A Smart Download Manager for Python', long_description=open('README.md').read(), test_suite = "test.test_pySmartDL.test_suite", - classifiers=( + classifiers=[ 'Development Status :: 4 - Beta', 'Intended Audience :: Developers', 'Environment :: Console', @@ -37,6 +37,6 @@ "Operating System :: POSIX", "Topic :: Internet :: WWW/HTTP", "Topic :: Software Development :: Libraries :: Python Modules", - ), + ], **extra ) diff --git a/test/test_pySmartDL.py b/test/test_pySmartDL.py index 2fa02cc..dded801 100644 --- a/test/test_pySmartDL.py +++ b/test/test_pySmartDL.py @@ -1,3 +1,5 @@ +# -*- coding: utf-8 -*- + import os import sys import random @@ -84,7 +86,6 @@ def test_pause_unpause_stop(self): obj.stop() obj.wait() self.assertFalse(obj.isSuccessful()) - # self.assertTrue(isinstance(obj.get_errors()[-1], pySmartDL.CanceledException), msg=str(obj.get_errors()[-1])) def test_basic_auth(self): basic_auth_test_url = "http://httpbin.org/basic-auth/user/passwd" @@ -94,6 +95,11 @@ def test_basic_auth(self): data = obj.get_data() self.assertTrue(json.loads(data)['authenticated']) + def test_unicode(self): + url = u"http://he.wikipedia.org/wiki/ג'חנון" + obj = pySmartDL.SmartDL(url, progress_bar=False) + obj.start() + def test_suite(): suite = unittest.makeSuite(TestSmartDL) return suite @@ -102,4 +108,4 @@ def test_suite(): if sys.version_info < (2,7): unittest.main() else: - unittest.main(verbosity=2) \ No newline at end of file + unittest.main(verbosity=2)