Merge pull request #2 from elliottbinder/patch-1

Update trilobytes.py
This commit is contained in:
Neale Pickett 2018-07-11 21:52:11 -06:00 committed by GitHub
commit 1f12c3bc25
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 2 deletions

View File

@ -39,6 +39,12 @@ class TriloBytes:
>>> bytes(tb) >>> bytes(tb)
b'hiOPDROPD' b'hiOPDROPD'
>>> tb = TriloBytes(b'00')^1
>>> tb[0]
1
>>> bytes(TriloBytes(b'00'))
b'\x00'
""" """
def __init__(self, initializer=(), drop=b'?'): def __init__(self, initializer=(), drop=b'?'):
@ -84,7 +90,7 @@ class TriloBytes:
yield val yield val
def __bytes__(self): 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): def __add__(self, other):
try: try:
@ -107,7 +113,7 @@ class TriloBytes:
mask[0] mask[0]
except TypeError: except TypeError:
mask = [mask] 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): def __repr__(self):
""" """