-# Copyright (c) 2009, 2010 Nicira Networks.
-#
+# Copyright (c) 2009, 2010 Nicira, Inc.
+#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at:
-#
+#
# http://www.apache.org/licenses/LICENSE-2.0
-#
+#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
+from __future__ import print_function
+
import codecs
import getopt
import sys
import ovs.json
+import six
+
def print_json(json):
- if type(json) in [str, unicode]:
- print "error: %s" % json
+ if isinstance(json, six.string_types):
+ print("error: %s" % json)
return False
else:
ovs.json.to_stream(json, sys.stdout)
sys.stdout.write("\n")
return True
+
def parse_multiple(stream):
buf = stream.read(4096)
ok = True
ok = False
return ok
+
def main(argv):
argv0 = argv[0]
- # Make stdout and stderr UTF-8, even if they are redirected to a file.
- sys.stdout = codecs.getwriter("utf-8")(sys.stdout)
- sys.stderr = codecs.getwriter("utf-8")(sys.stderr)
+ # When this is used with Python 3, the program produces no output.
+ if sys.version_info[0] == 2:
+ # Make stdout and stderr UTF-8, even if they are redirected to a file.
+ sys.stdout = codecs.getwriter("utf-8")(sys.stdout)
+ sys.stderr = codecs.getwriter("utf-8")(sys.stderr)
try:
options, args = getopt.gnu_getopt(argv[1:], '', ['multiple'])
- except getopt.GetoptError, geo:
+ except getopt.GetoptError as geo:
sys.stderr.write("%s: %s\n" % (argv0, geo.msg))
sys.exit(1)
if not ok:
sys.exit(1)
+
if __name__ == '__main__':
main(sys.argv)