Skip to content

Commit

Permalink
Fix yaml conversion of multiple addresses with same label
Browse files Browse the repository at this point in the history
  • Loading branch information
lucc committed Sep 6, 2023
1 parent 971e341 commit 5c1403e
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions khard/helpers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def yaml_dicts(
return data_dict


def yaml_addresses(addresses: Optional[Dict[str, Any]],
def yaml_addresses(addresses: Optional[Dict[str, List]],
address_properties: List[str],
defaults: Optional[List[str]] = None
) -> Optional[Dict[str, Any]]:
Expand All @@ -135,13 +135,15 @@ def yaml_addresses(addresses: Optional[Dict[str, Any]],
return {address_type: address_fields for address_type in defaults}

address_dict = {}
for address_type, address in addresses.items():
if isinstance(address, list):
address = address[0]
address_dict[address_type] = {
key: yaml_clean(address.get(f"{key[0].lower()}{key[1:]}"))
for key in address_properties
}
for address_type, addresses_ in addresses.items():
entry = [
{key: yaml_clean(address.get(f"{key[0].lower()}{key[1:]}"))
for key in address_properties}
for address in addresses_
]
if len(entry) == 1:
entry = entry[0]
address_dict[address_type] = entry
return address_dict


Expand Down

0 comments on commit 5c1403e

Please sign in to comment.