[SEBA-412] Automated reformat of Python code

Passes of modernize, autopep8, black, then check with flake8

flake8 + manual fixes:
  lib/xos-config
  lib/xos-kafka
  lib/xos-util
  xos/coreapi
  xos/api
  xos/xos_client

Change-Id: Ib23cf84cb13beb3c6381fa0d79594dc9131dc815
diff --git a/lib/xos-genx/xosgenx/xosgen.py b/lib/xos-genx/xosgenx/xosgen.py
index 27a7fb4..1318242 100755
--- a/lib/xos-genx/xosgenx/xosgen.py
+++ b/lib/xos-genx/xosgenx/xosgen.py
@@ -1,4 +1,3 @@
-
 # Copyright 2017-present Open Networking Foundation
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
@@ -16,49 +15,116 @@
 
 #!/usr/bin/python
 
+from __future__ import print_function
 import argparse
 from generator import *
 from version import __version__
 
-parse = argparse.ArgumentParser(description='XOS Generative Toolchain')
-parse.add_argument('--rev', dest='rev', action='store_true',
-                   default=XOSProcessorArgs.default_rev, help='Convert proto to xproto')
-parse.add_argument('--output', dest='output', action='store',
-                   default=XOSProcessorArgs.default_output, help='Destination dir')
-parse.add_argument('--attic', dest='attic', action='store',
-                   default=XOSProcessorArgs.default_attic, help='The location at which static files are stored')
-parse.add_argument('--kvpairs', dest='kv', action='store',
-                   default=XOSProcessorArgs.default_kvpairs, help='Key value pairs to make available to the target')
-parse.add_argument('--write-to-file', dest='write_to_file', choices = ['single', 'model', 'target'], action='store',
-                   default=XOSProcessorArgs.default_write_to_file,
-                   help='Single output file (single) or output file per model (model) or let target decide (target)')
-parse.add_argument('--version', action='version', version=__version__)
-parse.add_argument("-v", "--verbosity", action="count",
-                   default=XOSProcessorArgs.default_verbosity, help="increase output verbosity")
-parse.add_argument("--include-models", dest="include_models", action="append",
-                   default=XOSProcessorArgs.default_include_models, help="list of models to include")
-parse.add_argument("--include-apps", dest="include_apps", action="append",
-                   default=XOSProcessorArgs.default_include_apps, help="list of models to include")
+parse = argparse.ArgumentParser(description="XOS Generative Toolchain")
+parse.add_argument(
+    "--rev",
+    dest="rev",
+    action="store_true",
+    default=XOSProcessorArgs.default_rev,
+    help="Convert proto to xproto",
+)
+parse.add_argument(
+    "--output",
+    dest="output",
+    action="store",
+    default=XOSProcessorArgs.default_output,
+    help="Destination dir",
+)
+parse.add_argument(
+    "--attic",
+    dest="attic",
+    action="store",
+    default=XOSProcessorArgs.default_attic,
+    help="The location at which static files are stored",
+)
+parse.add_argument(
+    "--kvpairs",
+    dest="kv",
+    action="store",
+    default=XOSProcessorArgs.default_kvpairs,
+    help="Key value pairs to make available to the target",
+)
+parse.add_argument(
+    "--write-to-file",
+    dest="write_to_file",
+    choices=["single", "model", "target"],
+    action="store",
+    default=XOSProcessorArgs.default_write_to_file,
+    help="Single output file (single) or output file per model (model) or let target decide (target)",
+)
+parse.add_argument("--version", action="version", version=__version__)
+parse.add_argument(
+    "-v",
+    "--verbosity",
+    action="count",
+    default=XOSProcessorArgs.default_verbosity,
+    help="increase output verbosity",
+)
+parse.add_argument(
+    "--include-models",
+    dest="include_models",
+    action="append",
+    default=XOSProcessorArgs.default_include_models,
+    help="list of models to include",
+)
+parse.add_argument(
+    "--include-apps",
+    dest="include_apps",
+    action="append",
+    default=XOSProcessorArgs.default_include_apps,
+    help="list of models to include",
+)
 
 group = parse.add_mutually_exclusive_group()
-group.add_argument('--dest-file', dest='dest_file', action='store',
-                   default=XOSProcessorArgs.default_dest_file, help='Output file name (if write-to-file is set to single)')
-group.add_argument('--dest-extension', dest='dest_extension', action='store',
-                   default=XOSProcessorArgs.default_dest_extension, help='Output file extension (if write-to-file is set to single)')
+group.add_argument(
+    "--dest-file",
+    dest="dest_file",
+    action="store",
+    default=XOSProcessorArgs.default_dest_file,
+    help="Output file name (if write-to-file is set to single)",
+)
+group.add_argument(
+    "--dest-extension",
+    dest="dest_extension",
+    action="store",
+    default=XOSProcessorArgs.default_dest_extension,
+    help="Output file extension (if write-to-file is set to single)",
+)
 
 group = parse.add_mutually_exclusive_group(required=True)
-group.add_argument('--target', dest='target', action='store',
-                   default=XOSProcessorArgs.default_target, help='Output format, corresponding to <output>.yaml file')
-group.add_argument('--checkers', dest='checkers', action='store',
-                   default=XOSProcessorArgs.default_checkers, help='Comma-separated list of static checkers')
+group.add_argument(
+    "--target",
+    dest="target",
+    action="store",
+    default=XOSProcessorArgs.default_target,
+    help="Output format, corresponding to <output>.yaml file",
+)
+group.add_argument(
+    "--checkers",
+    dest="checkers",
+    action="store",
+    default=XOSProcessorArgs.default_checkers,
+    help="Comma-separated list of static checkers",
+)
 
-parse.add_argument('files', metavar='<input file>', nargs='+', action='store', help='xproto files to compile')
+parse.add_argument(
+    "files",
+    metavar="<input file>",
+    nargs="+",
+    action="store",
+    help="xproto files to compile",
+)
 
 CHECK = 1
 GEN = 2
 
-class XosGen:
 
+class XosGen:
     @staticmethod
     def init(args=None):
         if not args:
@@ -68,77 +134,94 @@
 
         if args.target:
             op = GEN
-            subdir = '/targets/'
+            subdir = "/targets/"
         elif args.checkers:
             op = CHECK
-            subdir = '/checkers/'
+            subdir = "/checkers/"
         else:
             parse.error("At least one of --target and --checkers is required")
 
-        operators = args.checkers.split(',') if hasattr(args, 'checkers') and args.checkers else [args.target]
+        operators = (
+            args.checkers.split(",")
+            if hasattr(args, "checkers") and args.checkers
+            else [args.target]
+        )
 
         for i in xrange(len(operators)):
-            if not '/' in operators[i]:
+            if "/" not in operators[i]:
                 # if the target is not a path, it refer to a library included one
-                operators[i] = os.path.abspath(os.path.dirname(os.path.realpath(__file__)) + subdir + operators[i])
+                operators[i] = os.path.abspath(
+                    os.path.dirname(os.path.realpath(__file__)) + subdir + operators[i]
+                )
 
             if not os.path.isabs(operators[i]):
-                operators[i] = os.path.abspath(os.getcwd() + '/' + operators[i])
+                operators[i] = os.path.abspath(os.getcwd() + "/" + operators[i])
 
         if op == GEN:
             # convert output to absolute path
             if args.output is not None and not os.path.isabs(args.output):
-                args.output = os.path.abspath(os.getcwd() + '/' + args.output)
+                args.output = os.path.abspath(os.getcwd() + "/" + args.output)
 
             operator = operators[0]
-            
+
             # check if there's a line that starts with +++ in the target
             # if so, then the output file names are left to the target to decide
             # also, if dest-file or dest-extension are supplied, then an error is generated.
-            plusplusplus = reduce(lambda acc, line: True if line.startswith('+++') else acc, open(operator).read().splitlines(), False)
+            plusplusplus = reduce(
+                lambda acc, line: True if line.startswith("+++") else acc,
+                open(operator).read().splitlines(),
+                False,
+            )
 
-            if plusplusplus and args.write_to_file != 'target':
-                parse.error('%s chooses the names of the files that it generates, you must set --write-to-file to "target"' % operator)
+            if plusplusplus and args.write_to_file != "target":
+                parse.error(
+                    '%s chooses the names of the files that it generates, you must set --write-to-file to "target"'
+                    % operator
+                )
 
-            if args.write_to_file != 'single' and (args.dest_file):
-                parse.error('--dest-file requires --write-to-file to be set to "single"')
+            if args.write_to_file != "single" and (args.dest_file):
+                parse.error(
+                    '--dest-file requires --write-to-file to be set to "single"'
+                )
 
-            if args.write_to_file != 'model' and (args.dest_extension):
-                parse.error('--dest-extension requires --write-to-file to be set to "model"')
-            
+            if args.write_to_file != "model" and (args.dest_extension):
+                parse.error(
+                    '--dest-extension requires --write-to-file to be set to "model"'
+                )
+
         else:
             if args.write_to_file or args.dest_extension:
-                parse.error('Checkers cannot write to files')
+                parse.error("Checkers cannot write to files")
 
         inputs = []
 
         for fname in args.files:
             if not os.path.isabs(fname):
-                inputs.append(os.path.abspath(os.getcwd() + '/' + fname))
+                inputs.append(os.path.abspath(os.getcwd() + "/" + fname))
             else:
                 inputs.append(fname)
 
         args.files = inputs
 
-        if op==GEN:
+        if op == GEN:
             generated = XOSProcessor.process(args, operators[0])
             if not args.output and not args.write_to_file:
-                print generated
-        elif op==CHECK:
+                print(generated)
+        elif op == CHECK:
             for o in operators:
                 verdict_str = XOSProcessor.process(args, o)
-                vlst = verdict_str.split('\n')
+                vlst = verdict_str.split("\n")
 
                 try:
                     verdict = next(v for v in vlst if v.strip())
-                    status_code, status_string = verdict.split(' ', 1)
+                    status_code, status_string = verdict.split(" ", 1)
                     status_code = int(status_code)
-                except:
-                    print "Checker %s returned mangled output" % o
+                except BaseException:
+                    print("Checker %s returned mangled output" % o)
                     exit(1)
 
                 if status_code != 200:
-                    print '%s: %s - %s' % (o, status_code, status_string)
+                    print("%s: %s - %s" % (o, status_code, status_string))
                     exit(1)
                 else:
-                    print '%s: OK'%o
+                    print("%s: OK" % o)