from sfa.util.xml import XML
from sfa.util.config import Config
+
class ApiVersions:
required_fields = ['version', 'url']
-
+
template = """<api_versions>
<api_version name="" version="" url="" />
-</api_versions>"""
+</api_versions>"""
def __init__(self, string=None, filename=None, create=False):
self.xml = None
else:
# load the default file
c = Config()
- api_versions_file = os.path.sep.join([c.config_path, 'api_versions.xml'])
+ api_versions_file = os.path.sep.join(
+ [c.config_path, 'api_versions.xml'])
self.load(api_versions_file)
-
+
def create(self):
self.xml = XML(string=ApiVersions.template)
def get_versions(self):
versions = {}
- for value in self.xml.todict().values():
+ for value in list(self.xml.todict().values()):
if not value:
continue
if isinstance(value, list):
for item in value:
if isinstance(item, dict) and \
- set(ApiVersions.required_fields).issubset(item.keys()) and \
+ set(ApiVersions.required_fields).issubset(list(item.keys())) and \
item['version'] != '' and item['url'] != '':
versions[str(item['version'])] = item['url']
- return versions
-
-
+ return versions