diff options
author | Chris Liechti <cliechti@gmx.net> | 2015-08-07 00:02:44 +0200 |
---|---|---|
committer | Chris Liechti <cliechti@gmx.net> | 2015-08-07 00:02:44 +0200 |
commit | 5fe3bdd03b62e05d84a47e0007b8c9ba46d65909 (patch) | |
tree | 3a00ac47387a2e435051035c7ba3d9d54b377dbe | |
parent | ef6b7b4f10369bfa7c9f0a129d20ae2250e23641 (diff) | |
download | pyserial-git-5fe3bdd03b62e05d84a47e0007b8c9ba46d65909.tar.gz |
hwgrep: fix port property access and python 3 support
-rw-r--r-- | serial/urlhandler/protocol_hwgrep.py | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/serial/urlhandler/protocol_hwgrep.py b/serial/urlhandler/protocol_hwgrep.py index 7ce9dfe..f7bf2e7 100644 --- a/serial/urlhandler/protocol_hwgrep.py +++ b/serial/urlhandler/protocol_hwgrep.py @@ -6,7 +6,7 @@ # This module implements a special URL handler that uses the port listing to # find ports by searching the string descriptions. # -# (C) 2011 Chris Liechti <cliechti@gmx.net> +# (C) 2011-2015 Chris Liechti <cliechti@gmx.net> # this is distributed under a free software license, see license.txt # # URL format: hwgrep://regexp @@ -14,15 +14,21 @@ import serial import serial.tools.list_ports +try: + basestring +except NameError: + basestring = str # python 3 + class Serial(serial.Serial): - """Just inherit the native Serial port implementation and patch the open function.""" + """Just inherit the native Serial port implementation and patch the port property.""" - def setPort(self, value): + @serial.Serial.port.setter + def port(self, value): """translate port name before storing it""" if isinstance(value, basestring) and value.startswith('hwgrep://'): - serial.Serial.setPort(self, self.fromURL(value)) + serial.Serial.port.__set__(self, self.fromURL(value)) else: - serial.Serial.setPort(self, value) + serial.Serial.port.__set__(self, value) def fromURL(self, url): """extract host and port from an URL string""" @@ -33,9 +39,6 @@ class Serial(serial.Serial): else: raise serial.SerialException('no ports found matching regexp %r' % (url,)) - # override property - port = property(serial.Serial.getPort, setPort, doc="Port setting") - # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - if __name__ == '__main__': #~ s = Serial('hwgrep://ttyS0') |