1
0
mirror of https://github.com/httpie/cli.git synced 2024-11-28 08:38:44 +02:00

Validate "file fields (name@/path) require --form / -f".

This commit is contained in:
Jakub Roztocil 2012-07-29 06:58:50 +02:00
parent 16635870e3
commit f73bfea6b8
3 changed files with 22 additions and 3 deletions

View File

@ -89,7 +89,6 @@ class Parser(argparse.ArgumentParser):
#noinspection PyMethodOverriding #noinspection PyMethodOverriding
def parse_args(self, env, args=None, namespace=None): def parse_args(self, env, args=None, namespace=None):
args = super(Parser, self).parse_args(args, namespace) args = super(Parser, self).parse_args(args, namespace)
self._process_output_options(args, env) self._process_output_options(args, env)
@ -183,7 +182,13 @@ class Parser(argparse.ArgumentParser):
' --form is used. File fields: %s' ' --form is used. File fields: %s'
% ','.join(args.files.keys())) % ','.join(args.files.keys()))
fn, data = list(args.files.values())[0] field_name = list(args.files.keys())[0]
fn, data = args.files[field_name]
if field_name:
# `http url name@/path' doesn't make sense here.
self.error(
'file fields (name@/path) require --form / -f')
self._body_from_file(args, data) self._body_from_file(args, data)
# Reset files # Reset files

View File

@ -120,10 +120,13 @@ class HTTPMessage(object):
except AttributeError: except AttributeError:
# requests < 0.12.1 # requests < 0.12.1
body = request._enc_data body = request._enc_data
if isinstance(body, dict): if isinstance(body, dict):
#noinspection PyUnresolvedReferences #noinspection PyUnresolvedReferences
body = type(request)._encode_params(body) body = type(request)._encode_params(body)
body = body.encode('utf8')
if isinstance(body, str):
body = body.encode('utf8')
return cls(line=request_line, return cls(line=request_line,
headers=headers, headers=headers,

View File

@ -515,6 +515,17 @@ class VerboseFlagTest(BaseTestCase):
self.assertIn('HTTP/1.1 200', r) self.assertIn('HTTP/1.1 200', r)
self.assertIn('foo=bar&baz=bar', r) self.assertIn('foo=bar&baz=bar', r)
def test_verbose_json(self):
r = http(
'--verbose',
'POST',
httpbin('/post'),
'foo=bar',
'baz=bar'
)
self.assertIn('HTTP/1.1 200', r)
self.assertEqual(r.count('"baz": "bar"'), 2)
class MultipartFormDataFileUploadTest(BaseTestCase): class MultipartFormDataFileUploadTest(BaseTestCase):