Explorar o código

[utils] Add encode_dict

Sergey M․ %!s(int64=10) %!d(string=hai) anos
pai
achega
1639282434
Modificáronse 1 ficheiros con 4 adicións e 0 borrados
  1. 4 0
      youtube_dl/utils.py

+ 4 - 0
youtube_dl/utils.py

@@ -1638,6 +1638,10 @@ def urlencode_postdata(*args, **kargs):
     return compat_urllib_parse.urlencode(*args, **kargs).encode('ascii')
 
 
+def encode_dict(d, encoding='utf-8'):
+    return dict((k.encode(encoding), v.encode(encoding)) for k, v in d.items())
+
+
 try:
     etree_iter = xml.etree.ElementTree.Element.iter
 except AttributeError:  # Python <=2.6