From c694157c5112c3ae08bcf7fe6ef32985675e8132 Mon Sep 17 00:00:00 2001
From: Jennifer Taylor <dragonminded@dragonminded.com>
Date: Sat, 4 Apr 2020 20:08:33 +0000
Subject: [PATCH] Fix cython issue and compile the rest of protocol.

---
 bemani/protocol/node.py | 10 +++++++---
 setup.py                |  2 ++
 2 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/bemani/protocol/node.py b/bemani/protocol/node.py
index b0e30d8..ec96a0d 100644
--- a/bemani/protocol/node.py
+++ b/bemani/protocol/node.py
@@ -1,6 +1,6 @@
 import copy
 import struct
-from typing import Any, Dict, List, Optional
+from typing import Any, Dict, List, Optional, Union
 
 
 class NodeException(Exception):
@@ -634,7 +634,7 @@ class Node:
         if is_array != self.__array:
             raise NodeException(f'Input {"is" if is_array else "is not"} array, expected {"array" if self.__array else "scalar"}')
 
-        def val_to_str(val: Any) -> str:
+        def val_to_str(val: Any) -> Union[str, bytes]:
             if self.__translated_type['name'] == 'bool':
                 # Support user-built boolean types
                 if val is True:
@@ -661,6 +661,7 @@ class Node:
             elif self.__translated_type['int']:
                 return str(val)
             else:
+                # This could return either a string or bytes.
                 return val
 
         if is_array or self.__translated_type['composite']:
@@ -676,17 +677,20 @@ class Node:
         Returns:
             A mixed value corresponding to this node's value. The returned value will be of the correct data type.
         """
-        def str_to_val(string: str) -> Any:
+        def str_to_val(string: Union[str, bytes]) -> Any:
             if self.__translated_type['name'] == 'bool':
                 return True if string == 'true' else False
             elif self.__translated_type['name'] == 'float':
                 return float(string)
             elif self.__translated_type['name'] == 'ip4':
+                if not isinstance(string, str):
+                    raise Exception('Logic error, expected a string!')
                 ip = [int(tup) for tup in string.split('.')]
                 return struct.pack('BBBB', ip[0], ip[1], ip[2], ip[3])
             elif self.__translated_type['int']:
                 return int(string)
             else:
+                # At this point, we could be a string or bytes.
                 return string
 
         if self.__array or self.__translated_type['composite']:
diff --git a/setup.py b/setup.py
index d8a335e..ac01823 100644
--- a/setup.py
+++ b/setup.py
@@ -75,6 +75,8 @@ setup(
         [
             "bemani/protocol/binary.py",
             "bemani/protocol/lz77.py",
+            "bemani/protocol/node.py",
+            "bemani/protocol/protocol.py",
             "bemani/protocol/stream.py",
             "bemani/protocol/xml.py",
         ],