refactor: raise new instances for PortNotOpenError and SerialTimeoutException
related to #502
fixes #437
diff --git a/serial/urlhandler/protocol_socket.py b/serial/urlhandler/protocol_socket.py
index 11f6a05..2888467 100644
--- a/serial/urlhandler/protocol_socket.py
+++ b/serial/urlhandler/protocol_socket.py
@@ -29,7 +29,7 @@
import urllib.parse as urlparse
from serial.serialutil import SerialBase, SerialException, to_bytes, \
- portNotOpenError, writeTimeoutError, Timeout
+ PortNotOpenError, SerialTimeoutException, Timeout
# map log level names to constants. used in from_url()
LOGGER_LEVELS = {
@@ -136,7 +136,7 @@
def in_waiting(self):
"""Return the number of bytes currently in the input buffer."""
if not self.is_open:
- raise portNotOpenError
+ raise PortNotOpenError()
# Poll the socket to see if it is ready for reading.
# If ready, at least one byte will be to read.
lr, lw, lx = select.select([self._socket], [], [], 0)
@@ -152,7 +152,7 @@
until the requested number of bytes is read.
"""
if not self.is_open:
- raise portNotOpenError
+ raise PortNotOpenError()
read = bytearray()
timeout = Timeout(self._timeout)
while len(read) < size:
@@ -193,7 +193,7 @@
closed.
"""
if not self.is_open:
- raise portNotOpenError
+ raise PortNotOpenError()
d = to_bytes(data)
tx_len = length = len(d)
@@ -209,10 +209,10 @@
# when timeout is set, use select to wait for being ready
# with the time left as timeout
if timeout.expired():
- raise writeTimeoutError
+ raise SerialTimeoutException('Write timeout')
_, ready, _ = select.select([], [self._socket], [], timeout.time_left())
if not ready:
- raise writeTimeoutError
+ raise SerialTimeoutException('Write timeout')
else:
assert timeout.time_left() is None
# wait for write operation
@@ -236,13 +236,13 @@
if e[0] not in (errno.EAGAIN, errno.EALREADY, errno.EWOULDBLOCK, errno.EINPROGRESS, errno.EINTR):
raise SerialException('write failed: {}'.format(e))
if not timeout.is_non_blocking and timeout.expired():
- raise writeTimeoutError
+ raise SerialTimeoutException('Write timeout')
return length - len(d)
def reset_input_buffer(self):
"""Clear input buffer, discarding all that is in the buffer."""
if not self.is_open:
- raise portNotOpenError
+ raise PortNotOpenError()
# just use recv to remove input, while there is some
ready = True
@@ -270,7 +270,7 @@
discarding all that is in the buffer.
"""
if not self.is_open:
- raise portNotOpenError
+ raise PortNotOpenError()
if self.logger:
self.logger.info('ignored reset_output_buffer')
@@ -280,7 +280,7 @@
duration.
"""
if not self.is_open:
- raise portNotOpenError
+ raise PortNotOpenError()
if self.logger:
self.logger.info('ignored send_break({!r})'.format(duration))
@@ -304,7 +304,7 @@
def cts(self):
"""Read terminal status line: Clear To Send"""
if not self.is_open:
- raise portNotOpenError
+ raise PortNotOpenError()
if self.logger:
self.logger.info('returning dummy for cts')
return True
@@ -313,7 +313,7 @@
def dsr(self):
"""Read terminal status line: Data Set Ready"""
if not self.is_open:
- raise portNotOpenError
+ raise PortNotOpenError()
if self.logger:
self.logger.info('returning dummy for dsr')
return True
@@ -322,7 +322,7 @@
def ri(self):
"""Read terminal status line: Ring Indicator"""
if not self.is_open:
- raise portNotOpenError
+ raise PortNotOpenError()
if self.logger:
self.logger.info('returning dummy for ri')
return False
@@ -331,7 +331,7 @@
def cd(self):
"""Read terminal status line: Carrier Detect"""
if not self.is_open:
- raise portNotOpenError
+ raise PortNotOpenError()
if self.logger:
self.logger.info('returning dummy for cd)')
return True