Last active
October 13, 2015 04:37
-
-
Save davidejones/2be24a4cb2e376c6b128 to your computer and use it in GitHub Desktop.
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 characters
import urllib | |
def encoded_dict(in_dict): | |
out_dict = {} | |
for k, v in in_dict.iteritems(): | |
if isinstance(v, unicode): | |
v = v.encode('utf8') | |
elif isinstance(v, str): | |
# Must be encoded in UTF-8 | |
v.decode('utf8') | |
out_dict[k] = v | |
return out_dict | |
tests = [1, '1', u'1', u'\u306a', u'Mo\xebt Chandon', u'M\xe9nage \xe0 trois', | |
u'M\xb4', u't\xfc', u'SCHRAMSBERG\xa0', u'\x80', u'\u20ac', u'\u0445', u'\u0445\u044c\u0437\u044c', u'\u306a'] | |
for test in tests: | |
print repr(test), repr(urllib.urlencode(encoded_dict({'a':test}))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment