From e662c030701bfd1f23494ff112e64c2cb99178b4 Mon Sep 17 00:00:00 2001 From: Henrik Hank Date: Mon, 14 May 2018 23:31:22 +0200 Subject: [PATCH] More flake8 compatibility. --- test/test_compat.py | 22 +++++++++------------- test/test_utils.py | 2 +- youtube_dl/YoutubeDL.py | 6 +++--- youtube_dl/compat.py | 4 ++-- youtube_dl/utils.py | 26 +++++++++++++------------- 5 files changed, 28 insertions(+), 32 deletions(-) diff --git a/test/test_compat.py b/test/test_compat.py index 63ae8e799..b25bcb44c 100644 --- a/test/test_compat.py +++ b/test/test_compat.py @@ -63,16 +63,14 @@ class TestCompat(unittest.TestCase): self.assertEqual(compat_urllib_parse_quote('%', safe='%'), '%') self.assertEqual(compat_urllib_parse_quote('津波'), '%E6%B4%A5%E6%B3%A2') self.assertEqual( - compat_urllib_parse_quote( - ''' - %%a''', safe='<>=":%/ \r\n'), + compat_urllib_parse_quote(''' +%%a''', safe='<>=":%/ \r\n'), ''' - %%a''') +%%a''') self.assertEqual( - compat_urllib_parse_quote( - '''(^◣_◢^)っ︻デ═一 ⇀ ⇀ ⇀ ⇀ ⇀ ↶%I%Break%25Things%''', safe='% '), + compat_urllib_parse_quote('''(^◣_◢^)っ︻デ═一 ⇀ ⇀ ⇀ ⇀ ⇀ ↶%I%Break%25Things%''', safe='% '), '''%28%5E%E2%97%A3_%E2%97%A2%5E%29%E3%81%A3%EF%B8%BB%E3%83%87%E2%95%90%E4%B8%80 %E2%87%80 %E2%87%80 %E2%87%80 %E2%87%80 %E2%87%80 %E2%86%B6%I%Break%25Things%''') - + def test_compat_urllib_parse_quote_plus(self): self.assertEqual(compat_urllib_parse_quote_plus('abc def'), 'abc+def') self.assertEqual(compat_urllib_parse_quote_plus('~/abc def'), '%7E%2Fabc+def') @@ -88,14 +86,12 @@ class TestCompat(unittest.TestCase): self.assertEqual(compat_urllib_parse_unquote('%2f'), '/') self.assertEqual(compat_urllib_parse_unquote('%E6%B4%A5%E6%B3%A2'), '津波') self.assertEqual( - compat_urllib_parse_unquote( - ''' - %%a'''), + compat_urllib_parse_unquote(''' +%%a'''), ''' - %%a''') +%%a''') self.assertEqual( - compat_urllib_parse_unquote( - '''%28%5E%E2%97%A3_%E2%97%A2%5E%29%E3%81%A3%EF%B8%BB%E3%83%87%E2%95%90%E4%B8%80 %E2%87%80 %E2%87%80 %E2%87%80 %E2%87%80 %E2%87%80 %E2%86%B6%I%Break%25Things%'''), + compat_urllib_parse_unquote('''%28%5E%E2%97%A3_%E2%97%A2%5E%29%E3%81%A3%EF%B8%BB%E3%83%87%E2%95%90%E4%B8%80 %E2%87%80 %E2%87%80 %E2%87%80 %E2%87%80 %E2%87%80 %E2%86%B6%I%Break%25Things%'''), '''(^◣_◢^)っ︻デ═一 ⇀ ⇀ ⇀ ⇀ ⇀ ↶%I%Break%Things%''') def test_compat_urllib_parse_unquote_plus(self): diff --git a/test/test_utils.py b/test/test_utils.py index f881f12a4..f377e6405 100644 --- a/test/test_utils.py +++ b/test/test_utils.py @@ -1334,7 +1334,7 @@ Line 1 self.assertEqual(get_elements_by_attribute('class', 'foo bar', html), ['nice', 'also nice']) self.assertEqual(get_elements_by_attribute('class', 'foo', html), []) self.assertEqual(get_elements_by_attribute('class', 'no-such-foo', html), []) - + def test_iri_to_uri(self): self.assertEqual( iri_to_uri('https://www.google.com/search?q=foo&ie=utf-8&oe=utf-8&client=firefox-b'), diff --git a/youtube_dl/YoutubeDL.py b/youtube_dl/YoutubeDL.py index 20fd53b69..98d4e58ee 100755 --- a/youtube_dl/YoutubeDL.py +++ b/youtube_dl/YoutubeDL.py @@ -1877,7 +1877,7 @@ class YoutubeDL(object): try: self.to_screen('[info] Writing internet shortcut to: ' + linkfn) with io.open(encodeFilename(to_high_limit_path(linkfn)), 'w', encoding='utf-8', newline=newline) as linkfile: - template_vars = { 'url': ascii_url } + template_vars = {'url': ascii_url} if embed_filename: template_vars['filename'] = linkfn[:-len(extension) - 1] linkfile.write(template % template_vars) @@ -1892,12 +1892,12 @@ class YoutubeDL(object): if not _write_link_file('webloc', WEBLOC_LINK_TEMPLATE, '\n', embed_filename=False): return if desktop_link: if not _write_link_file('desktop', DESKTOP_LINK_TEMPLATE, '\n', embed_filename=True ): return - + if self.params.get('skip_download', False): # Regarding the download archive, consider internet shortcut creation in conjunction with the `--skip-download` switch as everything the user wants. (See also help for the`--download-archive` switch.) if url_link or webloc_link or desktop_link: self.record_download_archive(info_dict) - + # Download else: # No `--skip-download` try: diff --git a/youtube_dl/compat.py b/youtube_dl/compat.py index 1268e7379..f4d23dc5a 100644 --- a/youtube_dl/compat.py +++ b/youtube_dl/compat.py @@ -50,7 +50,7 @@ except ImportError: # Python 2 try: from urllib.parse import urlunparse as compat_urllib_parse_urlunparse except ImportError: # Python 2 - from urlparse import urlunparse as compat_urllib_parse_urlunparse + from urlparse import urlunparse as compat_urllib_parse_urlunparse try: import urllib.response as compat_urllib_response @@ -2360,7 +2360,7 @@ except NameError: compat_str = str try: - from urllib.parse import quote as compat_urllib_parse_quote + from urllib.parse import quote as compat_urllib_parse_quote from urllib.parse import quote_plus as compat_urllib_parse_quote_plus except ImportError: # Python 2 def compat_urllib_parse_quote(string, safe='/'): diff --git a/youtube_dl/utils.py b/youtube_dl/utils.py index f1aa620fc..46a12d342 100644 --- a/youtube_dl/utils.py +++ b/youtube_dl/utils.py @@ -3951,29 +3951,29 @@ def iri_to_uri(iri): net_location = '' if iri_parts.username: - net_location += compat_urllib_parse_quote(iri_parts.username, safe=r"!$%&'()*+,~") + net_location += compat_urllib_parse_quote(iri_parts.username, safe=r"!$%&'()*+,~") if iri_parts.password is not None: net_location += ':' + compat_urllib_parse_quote(iri_parts.password, safe=r"!$%&'()*+,~") net_location += '@' - + net_location += iri_parts.hostname.encode('idna').decode('utf-8') # Punycode for Unicode hostnames. # The 'idna' encoding produces ASCII text. if iri_parts.port is not None and iri_parts.port != 80: net_location += ':' + str(iri_parts.port) - - return compat_urllib_parse_urlunparse( ( - iri_parts.scheme, - net_location, - compat_urllib_parse_quote_plus(iri_parts.path, safe=r"!$%&'()*+,/:;=@|~"), + return compat_urllib_parse_urlunparse( + (iri_parts.scheme, + net_location, - # Unsure about the `safe` argument , since this is a legacy way of handling parameters. - compat_urllib_parse_quote_plus(iri_parts.params, safe=r"!$%&'()*+,/:;=@|~"), + compat_urllib_parse_quote_plus(iri_parts.path, safe=r"!$%&'()*+,/:;=@|~"), - # Not totally sure about the `safe` argument, since the source does not explicitly mention the query URI component. - compat_urllib_parse_quote_plus(iri_parts.query, safe=r"!$%&'()*+,/:;=?@{|}~"), + # Unsure about the `safe` argument , since this is a legacy way of handling parameters. + compat_urllib_parse_quote_plus(iri_parts.params, safe=r"!$%&'()*+,/:;=@|~"), - compat_urllib_parse_quote_plus(iri_parts.fragment, safe=r"!#$%&'()*+,/:;=?@{|}~")) ) + # Not totally sure about the `safe` argument, since the source does not explicitly mention the query URI component. + compat_urllib_parse_quote_plus(iri_parts.query, safe=r"!$%&'()*+,/:;=?@{|}~"), + + compat_urllib_parse_quote_plus(iri_parts.fragment, safe=r"!#$%&'()*+,/:;=?@{|}~"))) # Source for `safe` arguments: https://url.spec.whatwg.org/#percent-encoded-bytes. @@ -3982,5 +3982,5 @@ def to_high_limit_path(path): if sys.platform in ['win32', 'cygwin']: # Work around MAX_PATH limitation on Windows. The maximum allowed length for the individual path segments may still be quite limited. return r'\\?\ '.rstrip() + os.path.abspath(path) - + return path