summaryrefslogtreecommitdiff
path: root/serial
diff options
context:
space:
mode:
authorcliechti <cliechti@f19166aa-fa4f-0410-85c2-fa1106f25c8a>2013-10-16 15:35:11 +0000
committercliechti <cliechti@f19166aa-fa4f-0410-85c2-fa1106f25c8a>2013-10-16 15:35:11 +0000
commite0984e1bd7e8afc4c8f04d191a11ce87492fdf38 (patch)
tree2b3249e693dd82f7a607c446a4fb97f4edc2f707 /serial
parentf911f1be9b07d0489f4e51c8d39e277c552ed9ae (diff)
downloadpyserial-e0984e1bd7e8afc4c8f04d191a11ce87492fdf38.tar.gz
do not allow negative baudrates, improve Python 3 compatibility of tests
git-svn-id: http://svn.code.sf.net/p/pyserial/code/trunk/pyserial@480 f19166aa-fa4f-0410-85c2-fa1106f25c8a
Diffstat (limited to 'serial')
-rw-r--r--serial/serialutil.py7
1 files changed, 5 insertions, 2 deletions
diff --git a/serial/serialutil.py b/serial/serialutil.py
index f575963..f28ece4 100644
--- a/serial/serialutil.py
+++ b/serial/serialutil.py
@@ -73,7 +73,7 @@ def to_bytes(seq):
else:
b = bytearray()
for item in seq:
- b.append(item) # this one handles int and str
+ b.append(item) # this one handles int and str for our emulation and ints for Python 3.x
return bytes(b)
# create control bytes
@@ -335,10 +335,13 @@ class SerialBase(object):
baud rate is not possible. If the port is closed, then the value is
accepted and the exception is raised when the port is opened."""
try:
- self._baudrate = int(baudrate)
+ b = int(baudrate)
except TypeError:
raise ValueError("Not a valid baudrate: %r" % (baudrate,))
else:
+ if b <= 0:
+ raise ValueError("Not a valid baudrate: %r" % (baudrate,))
+ self._baudrate = b
if self._isOpen: self._reconfigurePort()
def getBaudrate(self):