[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/jinja2_extensions/gui.py b/lib/xos-genx/xosgenx/jinja2_extensions/gui.py
index 50bcf0e..245bbda 100644
--- a/lib/xos-genx/xosgenx/jinja2_extensions/gui.py
+++ b/lib/xos-genx/xosgenx/jinja2_extensions/gui.py
@@ -1,4 +1,3 @@
-
# Copyright 2017-present Open Networking Foundation
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -16,74 +15,78 @@
from base import xproto_string_type, unquote
+
def xproto_type_to_ui_type(f):
try:
- content_type = f['options']['content_type']
+ content_type = f["options"]["content_type"]
content_type = eval(content_type)
- except:
+ except BaseException:
content_type = None
pass
- if 'choices' in f['options']:
- return 'select';
- elif content_type == 'date':
- return 'date'
- elif f['type'] == 'bool':
- return 'boolean'
- elif f['type'] == 'string':
- return xproto_string_type(f['options'])
- elif f['type'] in ['int','uint32','int32'] or 'link' in f:
- return 'number'
- elif f['type'] in ['double','float']:
- return 'string'
+ if "choices" in f["options"]:
+ return "select"
+ elif content_type == "date":
+ return "date"
+ elif f["type"] == "bool":
+ return "boolean"
+ elif f["type"] == "string":
+ return xproto_string_type(f["options"])
+ elif f["type"] in ["int", "uint32", "int32"] or "link" in f:
+ return "number"
+ elif f["type"] in ["double", "float"]:
+ return "string"
+
def xproto_options_choices_to_dict(choices):
list = []
for c in eval(choices):
- list.append({'id': c[0], 'label': c[1]})
+ list.append({"id": c[0], "label": c[1]})
if len(list) > 0:
return list
else:
return None
+
def xproto_validators(f):
# To be cleaned up when we formalize validation in xproto
validators = []
# bound-based validators
- bound_validators = [('max_length','maxlength'), ('min', 'min'), ('max', 'max')]
+ bound_validators = [("max_length", "maxlength"), ("min", "min"), ("max", "max")]
for v0, v1 in bound_validators:
try:
- validators.append({'name':v1, 'int_value':int(f['options'][v0])})
+ validators.append({"name": v1, "int_value": int(f["options"][v0])})
except KeyError:
pass
# validators based on content_type
- content_type_validators = ['ip', 'url', 'email']
+ content_type_validators = ["ip", "url", "email"]
for v in content_type_validators:
- #if f['name']=='ip': pdb.set_trace()
+ # if f['name']=='ip': pdb.set_trace()
try:
- val = unquote(f['options']['content_type'])==v
+ val = unquote(f["options"]["content_type"]) == v
if not val:
raise KeyError
- validators.append({'name':v, 'bool_value': True})
+ validators.append({"name": v, "bool_value": True})
except KeyError:
pass
# required validator
try:
- required = f['options']['blank']=='False' and f['options']['null']=='False'
+ required = f["options"]["blank"] == "False" and f["options"]["null"] == "False"
if required:
- validators.append({'name':'required', 'bool_value':required})
+ validators.append({"name": "required", "bool_value": required})
except KeyError:
pass
return validators
+
def is_number(s):
try:
float(s)
@@ -91,16 +94,17 @@
except ValueError:
return False
+
def xproto_default_to_gui(default):
val = "null"
if is_number(default):
val = str(default)
- elif eval(default) == True:
- val = 'true'
- elif eval(default) == False:
- val = 'false'
- elif eval(default) == None:
- val = 'null'
+ elif eval(default) is True:
+ val = "true"
+ elif eval(default) is False:
+ val = "false"
+ elif eval(default) is None:
+ val = "null"
else:
val = str(default)
return val
@@ -111,17 +115,20 @@
seen = []
for l in llst:
try:
- t = l['link_type']
- except KeyError, e:
+ t = l["link_type"]
+ except KeyError as e:
raise e
- if l['peer']['fqn'] not in seen and t != 'manytomany':
- on_field = 'null'
- if l['link_type'] == 'manytoone':
- on_field = l['src_port']
- elif l['link_type'] == 'onetomany':
- on_field = l['dst_port']
- outlist.append('- {model: %s, type: %s, on_field: %s}\n' % (l['peer']['name'], l['link_type'], on_field))
- seen.append(l['peer'])
+ if l["peer"]["fqn"] not in seen and t != "manytomany":
+ on_field = "null"
+ if l["link_type"] == "manytoone":
+ on_field = l["src_port"]
+ elif l["link_type"] == "onetomany":
+ on_field = l["dst_port"]
+ outlist.append(
+ "- {model: %s, type: %s, on_field: %s}\n"
+ % (l["peer"]["name"], l["link_type"], on_field)
+ )
+ seen.append(l["peer"])
return outlist