From 5d12443e50207f0f83cf89d743d7085e3e66327d Mon Sep 17 00:00:00 2001 From: Philipp Hahn Date: Tue, 20 Nov 2018 13:55:26 +0100 Subject: generator: Simplify XML attribute fetching MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Ján Tomko --- generator.py | 40 +++++++++++----------------------------- 1 file changed, 11 insertions(+), 29 deletions(-) (limited to 'generator.py') 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"]: -- cgit v1.2.1