diff options
author | Chris Liechti <cliechti@gmx.net> | 2015-08-17 03:08:55 +0200 |
---|---|---|
committer | Chris Liechti <cliechti@gmx.net> | 2015-08-17 03:08:55 +0200 |
commit | 5eaaa4e6383f13c6507af5d8a07e6e77c20e6129 (patch) | |
tree | f5935ca72f1bf39aa60a4c47188ef8b483afa51c | |
parent | 34290f42b668c8690beaf8c436281e48f1d3c54d (diff) | |
download | pyserial-git-5eaaa4e6383f13c6507af5d8a07e6e77c20e6129.tar.gz |
fix iterbytes to not yield an empty byte at the end
-rw-r--r-- | serial/serialutil.py | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/serial/serialutil.py b/serial/serialutil.py index e20196d..63f8a93 100644 --- a/serial/serialutil.py +++ b/serial/serialutil.py @@ -26,12 +26,14 @@ except (NameError, AttributeError): def iterbytes(b): """Iterate over bytes, returning bytes instead of ints (python3)""" x = 0 - a = True - while a: + while True: a = b[x:x+1] x += 1 - yield a - + if a: + yield a + else: + break + # all Python versions prior 3.x convert ``str([17])`` to '[17]' instead of '\x11' # so a simple ``bytes(sequence)`` doesn't work for all versions def to_bytes(seq): |