From 50da866eea22e15a2daf7f834549bac6505f047d Mon Sep 17 00:00:00 2001 From: Robert Breker Date: Fri, 2 Oct 2015 15:43:32 +0000 Subject: [PATCH 1/2] Check for both --json and -j arguments as specified in --help Signed-off-by: Robert Breker --- generator/src/python.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/generator/src/python.ml b/generator/src/python.ml index 48d17fba..7b60b3e9 100644 --- a/generator/src/python.ml +++ b/generator/src/python.ml @@ -298,7 +298,7 @@ let commandline_parse env i m = Line (sprintf "\"\"\"%s\"\"\"" m.Method.description); ] @ [ Line "# in --json mode we don't have any other arguments"; - Line "if '--json' in sys.argv:"; + Line "if ('--json' in sys.argv or '-j' in sys.argv):"; Block [ Line "return json.loads(sys.stdin.readline(),)"; ]; From bc2fce049d0ab11de9159206d13c351d56d01929 Mon Sep 17 00:00:00 2001 From: Robert Breker Date: Fri, 2 Oct 2015 15:53:43 +0000 Subject: [PATCH 2/2] CA-184422: Fix json error encapsulation in generated python code If json is parsed, parse_-function should add an element rv['json']=True. This is required so use_json can be true, as otherwise the json based error encapsulation never kicks in. Signed-off-by: Robert Breker --- generator/src/python.ml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/generator/src/python.ml b/generator/src/python.ml index 7b60b3e9..0e84dfc4 100644 --- a/generator/src/python.ml +++ b/generator/src/python.ml @@ -300,7 +300,9 @@ let commandline_parse env i m = Line "# in --json mode we don't have any other arguments"; Line "if ('--json' in sys.argv or '-j' in sys.argv):"; Block [ - Line "return json.loads(sys.stdin.readline(),)"; + Line "jsondict = json.loads(sys.stdin.readline(),)"; + Line "jsondict['json'] = True"; + Line "return jsondict"; ]; Line (sprintf "parser = argparse.ArgumentParser(description='%s')" m.Method.description); Line "parser.add_argument('-j', '--json', action='store_const', const=True, default=False, help='Read json from stdin, print json to stdout', required=False)";