Created
October 18, 2016 04:07
Revisions
-
dushujun renamed this gist
Oct 18, 2016 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
dushujun created this gist
Oct 18, 2016 .There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,21 @@ def str2unicode(data): """从bt拿到的任务参数是str, 需要转换成unicode""" if isinstance(data, str): return data.decode('utf8') elif isinstance(data, unicode): return data elif isinstance(data, collections.Mapping): return dict(map(str2unicode, data.iteritems())) elif isinstance(data, collections.Iterable): return type(data)(map(str2unicode, data)) else: return data def test_str2unicode(): # from yorg.contrib.cninfo import str2unicode assert str2unicode('test') == 'test' assert str2unicode('测试') == '测试' assert str2unicode('测试'.encode('utf8')) == '测试' assert str2unicode({'测试': 'test'})['测试'] == 'test' assert str2unicode(['测试', 'test']) == ['测试', 'test']