浏览代码

[utils] Add encode_compat_str

Sergey M․ 9 年之前
父节点
当前提交
8e60dc7526
共有 1 个文件被更改,包括 4 次插入0 次删除
  1. 4 0
      youtube_dl/utils.py

+ 4 - 0
youtube_dl/utils.py

@@ -1712,6 +1712,10 @@ def encode_dict(d, encoding='utf-8'):
     return dict((encode(k), encode(v)) for k, v in d.items())
     return dict((encode(k), encode(v)) for k, v in d.items())
 
 
 
 
+def encode_compat_str(string, encoding=preferredencoding(), errors='strict'):
+    return string if isinstance(string, compat_str) else compat_str(string, encoding, errors)
+
+
 US_RATINGS = {
 US_RATINGS = {
     'G': 0,
     'G': 0,
     'PG': 10,
     'PG': 10,