From 894953c221a9f10004a2a8c4699435c4ca46c478 Mon Sep 17 00:00:00 2001 From: Matthew Royle Date: Tue, 23 May 2023 21:26:02 +0200 Subject: [PATCH 1/3] Cater for markers and URIs being single values as opposed to a list. --- src/pyipp/models.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/pyipp/models.py b/src/pyipp/models.py index 71ee2d9fa..0389fa8d1 100644 --- a/src/pyipp/models.py +++ b/src/pyipp/models.py @@ -178,30 +178,50 @@ def merge_marker_data(data): marker_highs.append(100) marker_lows.append(0) + elif isinstance(data.get("marker-names"), str): + marker_names = [data["marker-names"]] + + mlen = 1 + marker_colors.append("") + marker_levels.append(-2) + marker_types.append("unknown") + marker_highs.append(100) + marker_lows.append(0) + if isinstance(data.get("marker-colors"), list): for index, list_value in enumerate(data["marker-colors"]): if index < mlen: marker_colors[index] = list_value + elif isinstance(data.get("marker-colors"), str) and mlen == 1: + marker_colors[0] = data.get("marker-colors") if isinstance(data.get("marker-levels"), list): for index, list_value in enumerate(data["marker-levels"]): if index < mlen: marker_levels[index] = list_value + elif isinstance(data.get("marker-levels"), int) and mlen == 1: + marker_levels[0] = data.get("marker-levels") if isinstance(data.get("marker-high-levels"), list): for index, list_value in enumerate(data["marker-high-levels"]): if index < mlen: marker_highs[index] = list_value + elif isinstance(data.get("marker-high-levels"), int) and mlen == 1: + marker_highs[0] = data.get("marker-high-levels") if isinstance(data.get("marker-low-levels"), list): for index, list_value in enumerate(data["marker-low-levels"]): if index < mlen: marker_lows[index] = list_value + elif isinstance(data.get("marker--low-levels"), int) and mlen == 1: + marker_lows[0] = data.get("marker-low-levels") if isinstance(data.get("marker-types"), list): for index, list_value in enumerate(data["marker-types"]): if index < mlen: marker_types[index] = list_value + elif isinstance(data.get("marker-types"), str) and mlen == 1: + marker_types[0] = data.get("marker-types") if isinstance(marker_names, list) and mlen > 0: markers = [ @@ -237,16 +257,27 @@ def merge_uri_data(data): for _k in range(ulen): auth.append(None) security.append(None) + + elif isinstance(data.get("printer-uri-supported"), str): + _uris = [data["printer-uri-supported"]] + ulen = 1 + + auth.append(None) + security.append(None) if isinstance(data.get("uri-authentication-supported"), list): for k, list_value in enumerate(data["uri-authentication-supported"]): if k < ulen: auth[k] = list_value if list_value != "none" else None + elif isinstance(data.get("uri-authentication-supported"), str) and ulen == 1: + auth[0] = data["uri-authentication-supported"] if data["uri-authentication-supported"] != "none" else None if isinstance(data.get("uri-security-supported"), list): for k, list_value in enumerate(data["uri-security-supported"]): if k < ulen: security[k] = list_value if list_value != "none" else None + elif isinstance(data.get("uri-security-supported"), str) and ulen == 1: + security[0] = data["uri-security-supported"] if data["uri-security-supported"] != "none" else None if isinstance(_uris, list) and ulen > 0: uris = [ From ca5dca8f9deae804a896ed0c5988fc9f16124162 Mon Sep 17 00:00:00 2001 From: Matthew Royle Date: Wed, 24 May 2023 09:54:47 +0200 Subject: [PATCH 2/3] Fix formatting --- src/pyipp/models.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/pyipp/models.py b/src/pyipp/models.py index 0389fa8d1..1a867d492 100644 --- a/src/pyipp/models.py +++ b/src/pyipp/models.py @@ -257,7 +257,7 @@ def merge_uri_data(data): for _k in range(ulen): auth.append(None) security.append(None) - + elif isinstance(data.get("printer-uri-supported"), str): _uris = [data["printer-uri-supported"]] ulen = 1 @@ -270,14 +270,22 @@ def merge_uri_data(data): if k < ulen: auth[k] = list_value if list_value != "none" else None elif isinstance(data.get("uri-authentication-supported"), str) and ulen == 1: - auth[0] = data["uri-authentication-supported"] if data["uri-authentication-supported"] != "none" else None + auth[0] = ( + data["uri-authentication-supported"] + if data["uri-authentication-supported"] != "none" + else None + ) if isinstance(data.get("uri-security-supported"), list): for k, list_value in enumerate(data["uri-security-supported"]): if k < ulen: security[k] = list_value if list_value != "none" else None elif isinstance(data.get("uri-security-supported"), str) and ulen == 1: - security[0] = data["uri-security-supported"] if data["uri-security-supported"] != "none" else None + security[0] = ( + data["uri-security-supported"] + if data["uri-security-supported"] != "none" + else None + ) if isinstance(_uris, list) and ulen > 0: uris = [ From 67e35a0fa8f576e92a42fba57ecdd3c832a29cd3 Mon Sep 17 00:00:00 2001 From: Matthew Royle Date: Thu, 25 May 2023 09:14:52 +0200 Subject: [PATCH 3/3] Update src/pyipp/models.py Co-authored-by: Chris Talkington --- src/pyipp/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pyipp/models.py b/src/pyipp/models.py index 1a867d492..84e11e3f1 100644 --- a/src/pyipp/models.py +++ b/src/pyipp/models.py @@ -213,7 +213,7 @@ def merge_marker_data(data): for index, list_value in enumerate(data["marker-low-levels"]): if index < mlen: marker_lows[index] = list_value - elif isinstance(data.get("marker--low-levels"), int) and mlen == 1: + elif isinstance(data.get("marker-low-levels"), int) and mlen == 1: marker_lows[0] = data.get("marker-low-levels") if isinstance(data.get("marker-types"), list):