def segment_mapper(self, text, notfound="_"): try: iterator = regular(text, notfound) while True: char = next(iterator) # Convert from std MAX7219 segment mappings a = char >> 6 & 0x01 b = char >> 5 & 0x01 c = char >> 4 & 0x01 d = char >> 3 & 0x01 e = char >> 2 & 0x01 f = char >> 1 & 0x01 g = char >> 0 & 0x01 # To NeoSegment positions yield \ b << 6 | \ a << 5 | \ f << 4 | \ g << 3 | \ c << 2 | \ d << 1 | \ e << 0 except StopIteration: pass
def segment_mapper(self, text, notfound="_"): for char in regular(text, notfound): # Convert from std MAX7219 segment mappings a = char >> 6 & 0x01 b = char >> 5 & 0x01 c = char >> 4 & 0x01 d = char >> 3 & 0x01 e = char >> 2 & 0x01 f = char >> 1 & 0x01 g = char >> 0 & 0x01 # To NeoSegment positions yield \ b << 6 | \ a << 5 | \ f << 4 | \ g << 3 | \ c << 2 | \ d << 1 | \ e << 0
def test_regular_with_notfound(): buf = mutable_string("B&B") results = regular(buf, notfound='_') assert list(results) == [0x7f, 0x08, 0x7f]
def test_regular_skips_unknown(): buf = mutable_string("B&B") results = regular(buf, notfound=None) assert list(results) == [0x7f, 0x7f]
def test_regular_empty_buf(): buf = mutable_string("") results = regular(buf) assert list(results) == []
def test_regular_with_multiple_dot(): buf = mutable_string("127.0.0.1") results = regular(buf) assert list(results) == [0x30, 0x6d, 0x70, 0x80, 0x7e, 0x80, 0x7e, 0x80, 0x30]
def test_regular_with_dot(): buf = mutable_string("3.14159") results = regular(buf) assert list(results) == [0x79, 0x80, 0x30, 0x33, 0x30, 0x5b, 0x7b]
def test_regular_without_dots(): buf = mutable_string("Hello world") results = regular(buf, notfound='_') assert list(results) == [0x37, 0x6f, 0x06, 0x06, 0x1d, 0x00, 0x08, 0x1d, 0x05, 0x06, 0x3d]
def test_regular_with_notfound(): buf = mutable_string("B&B") results = regular(buf, notfound='_') assert list(results) == [0x7f, 0x08, 0x7f]
def test_regular_skips_unknown(): buf = mutable_string("B&B") results = regular(buf, notfound=None) assert list(results) == [0x7f, 0x7f]
def test_regular_empty_buf(): buf = mutable_string("") results = regular(buf) assert list(results) == []
def test_regular_with_multiple_dot(): buf = mutable_string("127.0.0.1") results = regular(buf) assert list(results) == [0x30, 0x6d, 0x70, 0x80, 0x7e, 0x80, 0x7e, 0x80, 0x30]
def test_regular_with_dot(): buf = mutable_string("3.14159") results = regular(buf) assert list(results) == [0x79, 0x80, 0x30, 0x33, 0x30, 0x5b, 0x7b]
def test_regular_without_dots(): buf = mutable_string("Hello world") results = regular(buf, notfound='_') assert list(results) == [0x37, 0x6f, 0x06, 0x06, 0x1d, 0x00, 0x14, 0x1d, 0x05, 0x06, 0x3d]