From 501ed8effc592d80971d4c471ed7abd6dcbf20e2 Mon Sep 17 00:00:00 2001 From: Chris Talkington Date: Mon, 13 Apr 2020 00:13:23 -0500 Subject: [PATCH 1/4] Update models.py --- pyipp/models.py | 91 ++++++++++++++++++++++++++----------------------- 1 file changed, 49 insertions(+), 42 deletions(-) diff --git a/pyipp/models.py b/pyipp/models.py index 8bdf30d7c..8f77502f5 100644 --- a/pyipp/models.py +++ b/pyipp/models.py @@ -142,50 +142,11 @@ class Printer: uris: List[Uri] @staticmethod - def merge_uri_data(data): - """Return URI data from IPP response.""" - uris = [] - ulen = 0 - - _uris = [] - auth = [] - security = [] - - if isinstance(data.get("printer-uri-supported"), List): - _uris = data["printer-uri-supported"] - ulen = len(_uris) - - for k in range(ulen): - auth.append(None) - security.append(None) - - if isinstance(data.get("uri-authentication-supported"), List): - for k, v in enumerate(data["uri-authentication-supported"]): - if k < ulen: - auth[k] = v - - if isinstance(data.get("uri-security-supported"), List): - for k, v in enumerate(data["uri-security-supported"]): - if k < ulen: - security[k] = v - - if isinstance(_uris, List) and ulen > 0: - uris = [ - Uri( - uri=_uris[uri_id], - authentication=auth[uri_id], - security=security[uri_id], - ) - for uri_id in range(ulen) - ] - - return uris - - @staticmethod - def from_dict(data): - """Return Printer object from IPP response.""" + def merge_marker_data(data): + """Return Marker data from IPP response.""" markers = [] mlen = 0 + marker_colors = [] marker_levels = [] marker_types = [] @@ -244,6 +205,52 @@ def from_dict(data): ] markers.sort(key=lambda x: x.name) + return markers + + + @staticmethod + def merge_uri_data(data): + """Return URI data from IPP response.""" + uris = [] + ulen = 0 + + _uris = [] + auth = [] + security = [] + + if isinstance(data.get("printer-uri-supported"), List): + _uris = data["printer-uri-supported"] + ulen = len(_uris) + + for k in range(ulen): + auth.append(None) + security.append(None) + + if isinstance(data.get("uri-authentication-supported"), List): + for k, v in enumerate(data["uri-authentication-supported"]): + if k < ulen: + auth[k] = v + + if isinstance(data.get("uri-security-supported"), List): + for k, v in enumerate(data["uri-security-supported"]): + if k < ulen: + security[k] = v + + if isinstance(_uris, List) and ulen > 0: + uris = [ + Uri( + uri=_uris[uri_id], + authentication=auth[uri_id], + security=security[uri_id], + ) + for uri_id in range(ulen) + ] + + return uris + + @staticmethod + def from_dict(data): + """Return Printer object from IPP response.""" return Printer( info=Info.from_dict(data), markers=markers, From 579842aa0abc3f26f288572ced859655b0d26207 Mon Sep 17 00:00:00 2001 From: Chris Talkington Date: Mon, 13 Apr 2020 00:15:15 -0500 Subject: [PATCH 2/4] Update models.py --- pyipp/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyipp/models.py b/pyipp/models.py index 8f77502f5..b7217c659 100644 --- a/pyipp/models.py +++ b/pyipp/models.py @@ -253,7 +253,7 @@ def from_dict(data): """Return Printer object from IPP response.""" return Printer( info=Info.from_dict(data), - markers=markers, + markers=Printer.merge_marker_data(data), state=State.from_dict(data), uris=Printer.merge_uri_data(data), ) From e4cbbcf94e00e42f9a87e4588880d38a6b227dc8 Mon Sep 17 00:00:00 2001 From: Chris Talkington Date: Mon, 13 Apr 2020 00:17:18 -0500 Subject: [PATCH 3/4] Update models.py --- pyipp/models.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/pyipp/models.py b/pyipp/models.py index b7217c659..494c7c060 100644 --- a/pyipp/models.py +++ b/pyipp/models.py @@ -141,6 +141,16 @@ class Printer: state: State uris: List[Uri] + @staticmethod + def from_dict(data): + """Return Printer object from IPP response.""" + return Printer( + info=Info.from_dict(data), + markers=Printer.merge_marker_data(data), + state=State.from_dict(data), + uris=Printer.merge_uri_data(data), + ) + @staticmethod def merge_marker_data(data): """Return Marker data from IPP response.""" @@ -247,13 +257,3 @@ def merge_uri_data(data): ] return uris - - @staticmethod - def from_dict(data): - """Return Printer object from IPP response.""" - return Printer( - info=Info.from_dict(data), - markers=Printer.merge_marker_data(data), - state=State.from_dict(data), - uris=Printer.merge_uri_data(data), - ) From 9385902f590d7e9ed3c33d4bae08b6ae744fe212 Mon Sep 17 00:00:00 2001 From: Chris Talkington Date: Mon, 13 Apr 2020 00:18:21 -0500 Subject: [PATCH 4/4] Update models.py --- pyipp/models.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pyipp/models.py b/pyipp/models.py index 494c7c060..7b5a601cb 100644 --- a/pyipp/models.py +++ b/pyipp/models.py @@ -217,7 +217,6 @@ def merge_marker_data(data): return markers - @staticmethod def merge_uri_data(data): """Return URI data from IPP response."""