diff options
author | Chris Liechti <cliechti@gmx.net> | 2016-09-14 18:01:45 +0200 |
---|---|---|
committer | Chris Liechti <cliechti@gmx.net> | 2016-09-14 18:01:45 +0200 |
commit | 143ff760b04d259d7731184593b1fbeef6ddeac5 (patch) | |
tree | 733e4b0ea9a671bdcb2cf0602077a641fe29608b | |
parent | 43dd68b7a5dab16514b519e53cae3c174954d004 (diff) | |
download | pyserial-git-143ff760b04d259d7731184593b1fbeef6ddeac5.tar.gz |
refactor: simplify to_bytes
-rw-r--r-- | serial/serialutil.py | 11 |
1 files changed, 3 insertions, 8 deletions
diff --git a/serial/serialutil.py b/serial/serialutil.py index 547dc56..636a10c 100644 --- a/serial/serialutil.py +++ b/serial/serialutil.py @@ -62,14 +62,9 @@ def to_bytes(seq): elif isinstance(seq, unicode): raise TypeError('unicode strings are not supported, please encode to bytes: {!r}'.format(seq)) else: - b = bytearray() - for item in seq: - # this one handles int and bytes in Python 2.7 - # add conversion in case of Python 3.x - if isinstance(item, bytes): - item = ord(item) - b.append(item) - return bytes(b) + # handle list of integers and bytes (one or more items) for Python 2 and 3 + return bytes(bytearray(seq)) + # create control bytes XON = to_bytes([17]) |