Remove superfluous encodings
[youtube-dl] / youtube_dl / utils.py
index 370567705c64886c24bdffe51ef12d033c0d796d..0aa350e648d154f9356d81b76a583deeb7ca4623 100644 (file)
@@ -33,19 +33,23 @@ except ImportError: # Python 2
 
 try:
        import html.entities as compat_html_entities
-except NameError: # Python 2
+except ImportError: # Python 2
        import htmlentitydefs as compat_html_entities
 
 try:
        import html.parser as compat_html_parser
-except NameError: # Python 2
+except ImportError: # Python 2
        import HTMLParser as compat_html_parser
 
 try:
-       import http.client as compat_html_client
-except NameError: # Python 2
-       import httplib as compat_html_client
+       import http.client as compat_http_client
+except ImportError: # Python 2
+       import httplib as compat_http_client
 
+try:
+       from urllib.parse import parse_qs as compat_parse_qs
+except ImportError: # Python 2
+       from urlparse import parse_qs as compat_parse_qs
 
 try:
        compat_str = unicode # Python 2
@@ -57,7 +61,6 @@ try:
 except NameError:
        compat_chr = chr
 
-
 std_headers = {
        'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:10.0) Gecko/20100101 Firefox/10.0',
        'Accept-Charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.7',
@@ -79,6 +82,13 @@ def preferredencoding():
 
        return pref
 
+if sys.version_info < (3,0):
+       def compat_print(s):
+               print(s.encode(preferredencoding(), 'xmlcharrefreplace'))
+else:
+       def compat_print(s):
+               assert type(s) == type(u'')
+               print(s)
 
 def htmlentity_transform(matchobj):
        """Transforms an HTML entity to a character.