Proper test for str vs unicode when preparing data

In python 2.x, requests sets str = unicode in requests/compat.py. This causes
isinstance(foo, str) to return True even if foo is a unicode string.
This commit is contained in:
Idan Gazit
2012-04-19 09:18:26 +03:00
committed by Donald Stufft
parent 798dc4ae1d
commit 3e60a9eb9c
+4 -2
View File
@@ -8,6 +8,7 @@ This module contains the primary objects that power Requests.
"""
import os
import types
from datetime import datetime
from .hooks import dispatch_hook, HOOKS
@@ -329,8 +330,9 @@ class Request(object):
result = []
for k, vs in list(data.items()):
for v in isinstance(vs, list) and vs or [vs]:
result.append((k.encode('utf-8') if isinstance(k, str) else k,
v.encode('utf-8') if isinstance(v, str) else v))
result.append(
(k.encode('utf-8') if isinstance(k, types.StringType) else k,
v.encode('utf-8') if isinstance(v, types.StringType) else v))
return result, urlencode(result, doseq=True)
else:
return data, data