From b8b263fd9956aef078b8a5c988813c7b911ba477 Mon Sep 17 00:00:00 2001 From: Tiberiu Danciu Date: Fri, 16 Aug 2019 14:34:09 +0300 Subject: Added color parsing support --- tests/test_parse.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'tests/test_parse.py') diff --git a/tests/test_parse.py b/tests/test_parse.py index f9d445f..1a2913a 100644 --- a/tests/test_parse.py +++ b/tests/test_parse.py @@ -36,9 +36,8 @@ class TestParse(object): vs = ViewState(raw=b'\xff\x01\x10\x67\x68\x67') assert vs.decode() == (True, False, True) - @pytest.mark.skip(reason='Color parsing is not yet supported') def test_color(self): - vs = ViewState(raw=b'\xff\x01\n\x91\x01') + vs = ViewState(raw=b'\xff\x01\n\x91') assert vs.decode() == 'Color: Salmon' def test_rgba(self): -- cgit v1.3.1 From faefccc37dfe5858aaf54e158454fd0d9cbbd1c5 Mon Sep 17 00:00:00 2001 From: Tiberiu Danciu Date: Fri, 16 Aug 2019 20:42:12 +0300 Subject: Fixed major flaw in parsing colors. --- tests/test_parse.py | 3 +++ viewstate/parse.py | 25 ++++++++++++++----------- 2 files changed, 17 insertions(+), 11 deletions(-) (limited to 'tests/test_parse.py') diff --git a/tests/test_parse.py b/tests/test_parse.py index 1a2913a..e971955 100644 --- a/tests/test_parse.py +++ b/tests/test_parse.py @@ -39,6 +39,9 @@ class TestParse(object): def test_color(self): vs = ViewState(raw=b'\xff\x01\n\x91') assert vs.decode() == 'Color: Salmon' + + vs = ViewState(raw=b'\xff\x01\n\x8d\x01') + assert vs.decode() == 'Color: Red' def test_rgba(self): vs = ViewState(raw=b'\xff\x01\x09\x10\x20\x30\x40') diff --git a/viewstate/parse.py b/viewstate/parse.py index 6646c39..cae0300 100644 --- a/viewstate/parse.py +++ b/viewstate/parse.py @@ -41,15 +41,6 @@ class Const(Parser): return cls.const, remain -class Noop(Parser): - # This class is not up to specification. No value should be added to the parsed tree. - marker = 0x01 - - @staticmethod - def parse(b): - return None, b - - class NoneConst(Const): marker = 0x64 const = None @@ -310,10 +301,17 @@ class Color(Parser): "MenuHighlight", ] + color = 'Unknown' try: - return 'Color: {}'.format(color_table[b[0]]), b[1:] + color = 'Color: {}'.format(color_table[b[0]]) except IndexError: - return 'Color: Unknown', b[1:] + pass + + # If color packet ends with `\x01` + if len(b) > 1 and b[1] == 1: + return color, b[2:] + else: + return color, b[1:] class Pair(Parser): @@ -385,10 +383,15 @@ class Array(Parser): @staticmethod def parse(b): n, remain = Integer.parse(b) + if n > 400: + n, remain = Integer.parse(b) + l = [] for _ in range(n): val, remain = Parser.parse(remain) l.append(val) + if n>400: + print("lel") return l, remain -- cgit v1.3.1