Fix handling of bytes/str in transport paths

This commit is contained in:
slush 2018-02-02 20:16:42 +01:00
parent 29ad78d57b
commit 81db1da68f
3 changed files with 12 additions and 2 deletions

View File

@ -66,7 +66,10 @@ class BridgeTransport(Transport):
@classmethod
def find_by_path(cls, path):
if isinstance(path, bytes):
path = path.decode()
path = path.replace('%s:' % cls.PATH_PREFIX, '')
for transport in BridgeTransport.enumerate():
if path is None or transport.device['path'] == path:
return transport

View File

@ -98,8 +98,12 @@ class HidTransport(Transport):
@classmethod
def find_by_path(cls, path=None):
path = path.replace('%s:' % cls.PATH_PREFIX, '').encode() # Remove prefix from __str__()
if isinstance(path, str):
path = path.encode()
path = path.replace(b'%s:' % cls.PATH_PREFIX.encode(), b'')
for transport in HidTransport.enumerate():
print(path, transport.device['path'])
if path is None or transport.device['path'] == path:
return transport
raise TransportException('HID device not found')

View File

@ -70,7 +70,10 @@ class UdpTransport(Transport):
@classmethod
def find_by_path(cls, path=None):
path = path.replace('%s:' % cls.PATH_PREFIX , '') # Remove prefix from __str__()
if isinstance(path, str):
path = path.encode()
path = path.replace(b'%s:' % cls.PATH_PREFIX.encode(), b'')
return UdpTransport(path)
def open(self):