8000 Support non-string parameters gracefully · core-api/python-client@b2eab88 · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Mar 18, 2019. It is now read-only.

Commit b2eab88

Browse files
committed
Support non-string parameters gracefully
1 parent 154f36a commit b2eab88

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

coreapi/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from coreapi.transport import BaseTransport, HTTPTransport
88

99

10-
__version__ = '1.11.2'
10+
__version__ = '1.11.3'
1111
__all__ = [
1212
'BaseCodec', 'CoreJSONCodec', 'HALCodec', 'HTMLCodec', 'PlainTextCodec', 'PythonCodec',
1313
'negotiate_encoder', 'negotiate_decoder',

coreapi/commandline.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,15 +153,21 @@ def show(path):
153153
keys = coerce_key_types(doc, path)
154154
for key in keys:
155155
doc = doc[key]
156-
if isinstance(doc, (bool, type(None))):
157-
doc = {True: 'true', False: 'false', None: 'null'}[doc]
158156
click.echo(display(doc))
159157

160158

161159
def validate_params(ctx, param, value):
162160
if any(['=' not in item for item in value]):
163161
raise click.BadParameter('Parameters need to be in format <field name>=<value>')
164-
return dict([tuple(item.split('=', 1)) for item in value])
162+
params = dict([tuple(item.split('=', 1)) for item in value])
163+
for key, value in params.items():
164+
try:
165+
value = json.loads(value)
166+
except:
167+
pass
168+
else:
169+
params[key] = value
170+
return params
165171

166172

167173
def validate_inplace(ctx, param, value):

0 commit comments

Comments
 (0)
0