[vk.com] Updated the extract_videos_from_page function with a much simpler 1-liner.
[youtube-dl] / youtube_dl / compat.py
index 08e8d64d7c49f992a10e33de324193e313473eba..385924803f0fed16e62227a14c717486068690b2 100644 (file)
@@ -1,3 +1,5 @@
+from __future__ import unicode_literals
+
 import getpass
 import os
 import subprocess
@@ -280,11 +282,20 @@ except AttributeError:
 if sys.version_info < (3, 0) and sys.platform == 'win32':
     def compat_getpass(prompt, *args, **kwargs):
         if isinstance(prompt, compat_str):
+            from .utils import preferredencoding
             prompt = prompt.encode(preferredencoding())
         return getpass.getpass(prompt, *args, **kwargs)
 else:
     compat_getpass = getpass.getpass
 
+# Old 2.6 and 2.7 releases require kwargs to be bytes
+try:
+    (lambda x: x)(**{'x': 0})
+except TypeError:
+    def compat_kwargs(kwargs):
+        return dict((bytes(k), v) for k, v in kwargs.items())
+else:
+    compat_kwargs = lambda kwargs: kwargs
 
 __all__ = [
     'compat_HTTPError',
@@ -296,6 +307,7 @@ __all__ = [
     'compat_html_entities',
     'compat_html_parser',
     'compat_http_client',
+    'compat_kwargs',
     'compat_ord',
     'compat_parse_qs',
     'compat_print',