Skip to content
Myr

Proper test for str vs unicode when preparing data

Before adoption: this commit came in with the history the project adopted, so no landing records it.

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.

authored by Idan Gazit · committed by Donald Stufft · parent 798dc4a · Browse files · 1 file+4 added−2 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+4 added−2 removed

  • other:+4 added−2 removed

1 file+4 added−2 removed

modified:requests/models.py+4 added-2 removed
6 unmodified lines
7This module contains the primary objects that power Requests.8"""910import os11import types12from datetime import datetime1314from .hooks import dispatch_hook, HOOKS15from .structures import CaseInsensitiveDict
313 unmodified lines
329 if hasattr(data, 'items'):330 result = []331 for k, vs in list(data.items()):332 for v in isinstance(vs, list) and vs or [vs]:332 result.append((k.encode('utf-8') if isinstance(k, str) else k,333 v.encode('utf-8') if isinstance(v, str) else v))333 result.append(334 (k.encode('utf-8') if isinstance(k, types.StringType) else k,335 v.encode('utf-8') if isinstance(v, types.StringType) else v))336 return result, urlencode(result, doseq=True)337 else:338 return data, data339
507 unmodified lines