def _prepare_data_payload(data): """ Make a copy of the `data` object, preparing it to be sent to the server. The data will be sent via x-www-form-urlencoded or multipart/form-data mechanisms. Both of them work with plain lists of key/value pairs, so this method converts the data into such format. """ if not data: return None res = {} for key, value in viewitems(data): if value is None: continue # don't send args set to None so backend defaults take precedence if isinstance(value, list): value = stringify_list(value) elif isinstance(value, dict) and "__meta" in value and value["__meta"]["schema_name"].endswith("KeyV3"): value = value["name"] else: value = str(value) # Some hackery here... It appears that requests library cannot stomach "upgraded" strings if they contain # certain characters such as '/'. Therefore we explicitly cast them to their native representation. # Reproduction steps: # >>> import requests # >>> from future.types import newstr as str # >>> requests.get("http://www.google.com/search", params={"q": str("/foo/bar")}) # (throws a "KeyError 47" exception). # if PY2 and hasattr(value, "__native__"): value = value.__native__() # if PY2 and hasattr(key, "__native__"): key = key.__native__() res[key] = value return res
def _prepare_data_payload(data): """ Make a copy of the `data` object, preparing it to be sent to the server. The data will be sent via x-www-form-urlencoded or multipart/form-data mechanisms. Both of them work with plain lists of key/value pairs, so this method converts the data into such format. """ if not data: return None res = {} for key, value in viewitems(data): if value is None: continue # don't send args set to None so backend defaults take precedence if isinstance(value, list): value = stringify_list(value) elif isinstance(value, dict) and "__meta" in value and value[ "__meta"]["schema_name"].endswith("KeyV3"): value = value["name"] else: value = str(value) # Some hackery here... It appears that requests library cannot stomach "upgraded" strings if they contain # certain characters such as '/'. Therefore we explicitly cast them to their native representation. # Reproduction steps: # >>> import requests # >>> from future.types import newstr as str # >>> requests.get("http://www.google.com/search", params={"q": str("/foo/bar")}) # (throws a "KeyError 47" exception). # if PY2 and hasattr(value, "__native__"): value = value.__native__() # if PY2 and hasattr(key, "__native__"): key = key.__native__() res[key] = value return res
def _prepare_data_payload(data): """ Make a copy of the `data` object, preparing it to be sent to the server. The data will be sent via x-www-form-urlencoded or multipart/form-data mechanisms. Both of them work with plain lists of key/value pairs, so this method converts the data into such format. """ if not data: return None res = {} for key, value in viewitems(data): if value is None: continue # don't send args set to None so backend defaults take precedence if isinstance(value, list): value = stringify_list(value) elif isinstance(value, dict) and "__meta" in value and value["__meta"]["schema_name"].endswith("KeyV3"): value = value["name"] else: value = str(value) res[key] = value return res