From 94ef0aba57be764f108e952716de691eff0a73a7 Mon Sep 17 00:00:00 2001 From: elliottbinder Date: Wed, 11 Jul 2018 08:30:53 -0600 Subject: [PATCH 1/3] Update trilobytes.py Check byte for None instead of truthiness -- bytes with value of zero were getting overwritten by None. --- netarch/trilobytes.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/netarch/trilobytes.py b/netarch/trilobytes.py index 28fac17..dd93d8d 100644 --- a/netarch/trilobytes.py +++ b/netarch/trilobytes.py @@ -84,7 +84,7 @@ class TriloBytes: yield val def __bytes__(self): - return bytes((v or d for v,d in zip(self,itertools.cycle(self._drop)))) + return bytes((d if v is None else v for v,d in zip(self,itertools.cycle(self._drop)))) def __add__(self, other): try: @@ -107,7 +107,7 @@ class TriloBytes: mask[0] except TypeError: mask = [mask] - return TriloBytes(((x^y if x else None) for x,y in zip(self._contents, itertools.cycle(mask))), drop=self._drop) + return TriloBytes(((None if x is None or y is None else x^y) for x,y in zip(self._contents, itertools.cycle(mask))), drop=self._drop) def __repr__(self): """ From 0b7bcfd6334ee02c65ea4e26ea9462e9773b521e Mon Sep 17 00:00:00 2001 From: elliottbinder Date: Wed, 11 Jul 2018 19:36:43 -0600 Subject: [PATCH 2/3] Update trilobytes.py --- netarch/trilobytes.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/netarch/trilobytes.py b/netarch/trilobytes.py index dd93d8d..b371f47 100644 --- a/netarch/trilobytes.py +++ b/netarch/trilobytes.py @@ -39,6 +39,12 @@ class TriloBytes: >>> bytes(tb) b'hiOPDROPD' + >>> tb = TriloBytes(b'00')^1 + >>> tb[0] + 1 + >>> bytes(TriloBytes(b'00')) + b'\x00' + """ def __init__(self, initializer=(), drop=b'?'): From 56bd32000574ac22b50e202ce52c41238f3172fd Mon Sep 17 00:00:00 2001 From: elliottbinder Date: Wed, 11 Jul 2018 19:37:27 -0600 Subject: [PATCH 3/3] Update trilobytes.py Add docstring tests for xor and bytes fixes. --- netarch/trilobytes.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/netarch/trilobytes.py b/netarch/trilobytes.py index b371f47..45c21bb 100644 --- a/netarch/trilobytes.py +++ b/netarch/trilobytes.py @@ -42,9 +42,9 @@ class TriloBytes: >>> tb = TriloBytes(b'00')^1 >>> tb[0] 1 + >>> bytes(TriloBytes(b'00')) b'\x00' - """ def __init__(self, initializer=(), drop=b'?'):