Fix flake8 issues after #14225
[youtube-dl] / youtube_dl / utils.py
index 9e4492d402c225d53071d1424005ff5be0577681..acc4f987bba1e5133d1d7eda011c527ea2fb2054 100644 (file)
@@ -2572,14 +2572,18 @@ def srt_subtitles_timecode(seconds):
 
 
 def dfxp2srt(dfxp_data):
+    '''
+    @param dfxp_data A bytes-like object containing DFXP data
+    @returns A unicode object containing converted SRT data
+    '''
     LEGACY_NAMESPACES = (
-        ('http://www.w3.org/ns/ttml', [
-            'http://www.w3.org/2004/11/ttaf1',
-            'http://www.w3.org/2006/04/ttaf1',
-            'http://www.w3.org/2006/10/ttaf1',
+        (b'http://www.w3.org/ns/ttml', [
+            b'http://www.w3.org/2004/11/ttaf1',
+            b'http://www.w3.org/2006/04/ttaf1',
+            b'http://www.w3.org/2006/10/ttaf1',
         ]),
-        ('http://www.w3.org/ns/ttml#styling', [
-            'http://www.w3.org/ns/ttml#style',
+        (b'http://www.w3.org/ns/ttml#styling', [
+            b'http://www.w3.org/ns/ttml#style',
         ]),
     )
 
@@ -2674,7 +2678,7 @@ def dfxp2srt(dfxp_data):
         for ns in v:
             dfxp_data = dfxp_data.replace(ns, k)
 
-    dfxp = compat_etree_fromstring(dfxp_data.encode('utf-8'))
+    dfxp = compat_etree_fromstring(dfxp_data)
     out = []
     paras = dfxp.findall(_x('.//ttml:p')) or dfxp.findall('.//p')
 
@@ -3826,23 +3830,23 @@ def cookie_to_dict(cookie):
     cookie_dict = {
         'name': cookie.name,
         'value': cookie.value,
-    };
+    }
     if cookie.port_specified:
         cookie_dict['port'] = cookie.port
     if cookie.domain_specified:
         cookie_dict['domain'] = cookie.domain
     if cookie.path_specified:
         cookie_dict['path'] = cookie.path
-    if not cookie.expires is None:
+    if cookie.expires is not None:
         cookie_dict['expires'] = cookie.expires
-    if not cookie.secure is None:
+    if cookie.secure is not None:
         cookie_dict['secure'] = cookie.secure
-    if not cookie.discard is None:
+    if cookie.discard is not None:
         cookie_dict['discard'] = cookie.discard
     try:
         if (cookie.has_nonstandard_attr('httpOnly') or
-            cookie.has_nonstandard_attr('httponly') or
-            cookie.has_nonstandard_attr('HttpOnly')):
+                cookie.has_nonstandard_attr('httponly') or
+                cookie.has_nonstandard_attr('HttpOnly')):
             cookie_dict['httponly'] = True
     except TypeError:
         pass
@@ -3953,7 +3957,7 @@ class PhantomJSwrapper(object):
             cookies = json.loads(f.read().decode('utf-8'))
         for cookie in cookies:
             if cookie['httponly'] is True:
-                cookie['rest'] = { 'httpOnly': None }
+                cookie['rest'] = {'httpOnly': None}
             if 'expiry' in cookie:
                 cookie['expire_time'] = cookie['expiry']
             self.extractor._set_cookie(**cookie)
@@ -3961,7 +3965,7 @@ class PhantomJSwrapper(object):
     def get(self, url, html=None, video_id=None, note=None, note2='Executing JS on webpage', headers={}, jscode='saveAndExit();'):
         """
         Downloads webpage (if needed) and executes JS
-        
+
         Params:
             url: website url
             html: optional, html code of website
@@ -3970,11 +3974,11 @@ class PhantomJSwrapper(object):
             note2: optional, displayed when executing JS
             headers: custom http headers
             jscode: code to be executed when page is loaded
-        
+
         Returns tuple with:
             * downloaded website (after JS execution)
             * anything you print with `console.log` (but not inside `page.execute`!)
-        
+
         In most cases you don't need to add any `jscode`.
         It is executed in `page.onLoadFinished`.
         `saveAndExit();` is mandatory, use it instead of `phantom.exit()`
@@ -3988,7 +3992,7 @@ class PhantomJSwrapper(object):
               else
                 window.setTimeout(check, 500);
             }
-            
+
             page.evaluate(function(){
               document.querySelector('#a').click();
             });
@@ -4020,13 +4024,14 @@ class PhantomJSwrapper(object):
         else:
             self.extractor.to_screen('%s: %s' % (video_id, note2))
 
-        p = subprocess.Popen([self.exe, '--ssl-protocol=any',
-            self._TMP_FILES['script'].name], stdout=subprocess.PIPE,
-            stderr=subprocess.PIPE)
+        p = subprocess.Popen([
+            self.exe, '--ssl-protocol=any',
+            self._TMP_FILES['script'].name
+        ], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
         out, err = p.communicate()
         if p.returncode != 0:
-            raise ExtractorError('Executing JS failed\n:'
-                                 + encodeArgument(err))
+            raise ExtractorError(
+                'Executing JS failed\n:' + encodeArgument(err))
         with open(self._TMP_FILES['html'].name, 'rb') as f:
             html = f.read().decode('utf-8')