diff options
author | Philipp Hahn <hahn@univention.de> | 2020-04-27 06:45:54 +0200 |
---|---|---|
committer | Jano Tomko <jtomko@redhat.com> | 2020-09-01 13:26:01 +0000 |
commit | 4df8e83808791d7aa15a2abdba59118e0014db13 (patch) | |
tree | 5feef6956dcba0594dbc055e12661532c94fcc9f /generator.py | |
parent | 87e0ca639021b1401f0add2e6867e824e1d43224 (diff) | |
download | libvirt-python-4df8e83808791d7aa15a2abdba59118e0014db13.tar.gz |
generator: Convert to defaultdict()
for nested dictionaries allows to remove the case distinction for
"first" from "all other" cases.
Signed-off-by: Philipp Hahn <hahn@univention.de>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Diffstat (limited to 'generator.py')
-rwxr-xr-x | generator.py | 27 |
1 files changed, 7 insertions, 20 deletions
diff --git a/generator.py b/generator.py index c0eb588..8b9b4b8 100755 --- a/generator.py +++ b/generator.py @@ -8,13 +8,14 @@ import re import sys import xml.sax from contextlib import closing +from collections import defaultdict functions = {} lxc_functions = {} qemu_functions = {} -enums = {} # { enumType: { enumConstant: enumValue } } -lxc_enums = {} # { enumType: { enumConstant: enumValue } } -qemu_enums = {} # { enumType: { enumConstant: enumValue } } +enums = defaultdict(dict) # { enumType: { enumConstant: enumValue } } +lxc_enums = defaultdict(dict) # { enumType: { enumConstant: enumValue } } +qemu_enums = defaultdict(dict) # { enumType: { enumConstant: enumValue } } event_ids = [] params = [] # [ (paramName, paramValue)... ] @@ -186,8 +187,6 @@ def lxc_function(name, desc, ret, args, file, module, cond): def enum(type, name, value): - if type not in enums: - enums[type] = {} if (name.startswith('VIR_DOMAIN_EVENT_ID_') or name.startswith('VIR_NETWORK_EVENT_ID_')): event_ids.append(name) @@ -215,16 +214,12 @@ def enum(type, name, value): def lxc_enum(type, name, value): - if type not in lxc_enums: - lxc_enums[type] = {} if onlyOverrides and name not in lxc_enums[type]: return lxc_enums[type][name] = value def qemu_enum(type, name, value): - if type not in qemu_enums: - qemu_enums[type] = {} if value == 'VIR_DOMAIN_AGENT_RESPONSE_TIMEOUT_BLOCK': value = -2 elif value == 'VIR_DOMAIN_AGENT_RESPONSE_TIMEOUT_DEFAULT': @@ -342,7 +337,7 @@ py_types = { 'const virDomainSnapshot *': ('O', "virDomainSnapshot", "virDomainSnapshotPtr", "virDomainSnapshotPtr"), } -unknown_types = {} +unknown_types = defaultdict(list) ####################################################################### # @@ -701,11 +696,7 @@ def print_function_wrapper(module, name, output, export, include): else: if a_type in skipped_types: return 0 - if a_type in unknown_types: - lst = unknown_types[a_type] - lst.append(name) - else: - unknown_types[a_type] = [name] + unknown_types[a_type].append(name) return -1 if format: format += ":%s" % (name) @@ -738,11 +729,7 @@ def print_function_wrapper(module, name, output, export, include): else: if r_type in skipped_types: return 0 - if r_type in unknown_types: - lst = unknown_types[r_type] - lst.append(name) - else: - unknown_types[r_type] = [name] + unknown_types[r_type].append(name) return -1 if cond: |