Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_encode_params_None(self):
self.assertEqual(utils.encode_params(None, None), None)
inline_uploads = []
# this supports OrderedDict
if isinstance(params, dict) or hasattr(params, 'items'):
params = list(params.items())
if isinstance(params, (list, tuple)):
inline_uploads = [v for (k, v) in params
if isinstance(v, (forms.File, forms.Upload))]
if len(inline_uploads) > 0:
content_type, params = self.encode_multipart(
params, upload_files or ())
environ['CONTENT_TYPE'] = content_type
else:
params = utils.encode_params(params, content_type)
if upload_files or \
(content_type and
to_bytes(content_type).startswith(b'multipart')):
params = urlparse.parse_qsl(params, keep_blank_values=True)
content_type, params = self.encode_multipart(
params, upload_files or ())
environ['CONTENT_TYPE'] = content_type
elif params:
environ.setdefault('CONTENT_TYPE',
str('application/x-www-form-urlencoded'))
if content_type is not None:
environ['CONTENT_TYPE'] = content_type
environ['REQUEST_METHOD'] = str(method)
url = str(url)
url = self._remove_fragment(url)
def test_encode_params_NoDefault(self):
self.assertEqual(utils.encode_params(utils.NoDefault, None), '')
def test_encode_params_no_charset(self):
# no content_type at all
self.assertEqual(utils.encode_params({'foo': 'bar'}, None), 'foo=bar')
# content_type without "charset=xxxx"
self.assertEqual(utils.encode_params({'foo': 'bar'}, 'ba'), 'foo=bar')
def test_encode_params_charset_utf8(self):
# charset is using inconsistent casing on purpose, it should still work
self.assertEqual(utils.encode_params({'f': '€'}, ' CHARset=uTF-8; '),
'f=%E2%82%AC')