MCPcopy
hub / github.com/django/django / urlencode

Function urlencode

django/utils/http.py:45–83  ·  view source on GitHub ↗

A version of Python's urllib.parse.urlencode() function that can operate on MultiValueDict and non-string values.

(query, doseq=False)

Source from the content-addressed store, hash-verified

43
44
45def urlencode(query, doseq=False):
46 """
47 A version of Python's urllib.parse.urlencode() function that can operate on
48 MultiValueDict and non-string values.
49 """
50 if isinstance(query, MultiValueDict):
51 query = query.lists()
52 elif hasattr(query, "items"):
53 query = query.items()
54 query_params = []
55 for key, value in query:
56 if value is None:
57 raise TypeError(
58 "Cannot encode None for key '%s' in a query string. Did you "
59 "mean to pass an empty string or omit the value?" % key
60 )
61 elif not doseq or isinstance(value, (str, bytes)):
62 query_val = value
63 else:
64 try:
65 itr = iter(value)
66 except TypeError:
67 query_val = value
68 else:
69 # Consume generators and iterators, when doseq=True, to
70 # work around https://bugs.python.org/issue31706.
71 query_val = []
72 for item in itr:
73 if item is None:
74 raise TypeError(
75 "Cannot encode None for key '%s' in a query "
76 "string. Did you mean to pass an empty string or "
77 "omit the value?" % key
78 )
79 elif not isinstance(item, bytes):
80 item = str(item)
81 query_val.append(item)
82 query_params.append((key, query_val))
83 return original_urlencode(query_params, doseq)
84
85
86def http_date(epoch_seconds=None):

Callers 15

get_preserved_filtersMethod · 0.90
get_contextMethod · 0.90
add_preserved_filtersFunction · 0.90
get_query_stringMethod · 0.90
__init__Method · 0.90
genericMethod · 0.90
genericMethod · 0.90
test_tuplesMethod · 0.90

Calls 3

listsMethod · 0.80
itemsMethod · 0.45
appendMethod · 0.45

Used in the wild real call sites across dependent graphs

searching dependent graphs…