]>
git.proxmox.com Git - ovs.git/blob - tests/test-json.py
1 # Copyright (c) 2009, 2010 Nicira, Inc.
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at:
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
22 if isinstance(json
, str):
23 print("error: %s" % json
)
26 ovs
.json
.to_stream(json
, sys
.stdout
)
27 sys
.stdout
.write("\n")
31 def parse_multiple(stream
):
32 buf
= stream
.read(4096)
36 if parser
is None and buf
[0] in " \t\r\n":
40 parser
= ovs
.json
.Parser()
44 if not print_json(parser
.finish()):
48 buf
= stream
.read(4096)
49 if parser
and not print_json(parser
.finish()):
58 options
, args
= getopt
.gnu_getopt(argv
[1:], '', ['multiple'])
59 except getopt
.GetoptError
as geo
:
60 sys
.stderr
.write("%s: %s\n" % (argv0
, geo
.msg
))
64 for key
, value
in options
:
65 if key
== '--multiple':
68 sys
.stderr
.write("%s: unhandled option %s\n" % (argv0
, key
))
72 sys
.stderr
.write("usage: %s [--multiple] INPUT.json\n" % argv0
)
79 stream
= open(input_file
, "r")
82 ok
= parse_multiple(stream
)
84 ok
= print_json(ovs
.json
.from_stream(stream
))
90 if __name__
== '__main__':