summaryrefslogtreecommitdiff
path: root/generator.py
diff options
context:
space:
mode:
authorPhilipp Hahn <hahn@univention.de>2018-11-20 13:55:26 +0100
committerJano Tomko <jtomko@redhat.com>2020-09-01 13:26:01 +0000
commit5d12443e50207f0f83cf89d743d7085e3e66327d (patch)
tree558f1d0af813638be1d11a4287884b8de399c750 /generator.py
parent425901da213d127b9b435e3fcaa03c7036d8f6d7 (diff)
downloadlibvirt-python-5d12443e50207f0f83cf89d743d7085e3e66327d.tar.gz
generator: Simplify XML attribute fetching
Use attr.get(key, default) instead. Also use the empty sting "" as the default value instead of "None": Both are "False" when used as a bool()ean, but "None" would require an explicit check for "not None" in many places as str() and None have different types. Signed-off-by: Philipp Hahn <hahn@univention.de> Reviewed-by: Ján Tomko <jtomko@redhat.com>
Diffstat (limited to 'generator.py')
-rwxr-xr-xgenerator.py40
1 files changed, 11 insertions, 29 deletions
diff --git a/generator.py b/generator.py
index 188d20e..29cf600 100755
--- a/generator.py
+++ b/generator.py
@@ -71,47 +71,29 @@ class docParser(xml.sax.handler.ContentHandler):
if tag == 'function':
self._data = []
self.in_function = True
- self.function = None
self.function_cond = None
self.function_args = []
self.function_descr = None
self.function_return = None
- self.function_file = None
- self.function_module = None
- if 'name' in attrs:
- self.function = attrs['name']
- if 'file' in attrs:
- self.function_file = attrs['file']
- if 'module' in attrs:
- self.function_module = attrs['module']
+ self.function = attrs.get('name', '')
+ self.function_file = attrs.get('file', '')
+ self.function_module = attrs.get('module', '')
elif tag == 'cond':
self._data = []
elif tag == 'info':
self._data = []
elif tag == 'arg':
if self.in_function:
- self.function_arg_name = None
- self.function_arg_type = None
- self.function_arg_info = None
- if 'name' in attrs:
- self.function_arg_name = attrs['name']
- if self.function_arg_name == 'from':
- self.function_arg_name = 'frm'
- if 'type' in attrs:
- self.function_arg_type = attrs['type']
- if 'info' in attrs:
- self.function_arg_info = attrs['info']
+ self.function_arg_name = attrs.get('name', '')
+ if self.function_arg_name == 'from':
+ self.function_arg_name = 'frm'
+ self.function_arg_type = attrs.get('type', '')
+ self.function_arg_info = attrs.get('info', '')
elif tag == 'return':
if self.in_function:
- self.function_return_type = None
- self.function_return_info = None
- self.function_return_field = None
- if 'type' in attrs:
- self.function_return_type = attrs['type']
- if 'info' in attrs:
- self.function_return_info = attrs['info']
- if 'field' in attrs:
- self.function_return_field = attrs['field']
+ self.function_return_type = attrs.get('type', '')
+ self.function_return_info = attrs.get('info', '')
+ self.function_return_field = attrs.get('field', '')
elif tag == 'enum':
# enums come from header files, hence virterror.h
if attrs['file'] in libvirt_headers + ["virerror", "virterror"]: