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 @classmethod
def find_by_path(cls, path): def find_by_path(cls, path):
if isinstance(path, bytes):
path = path.decode()
path = path.replace('%s:' % cls.PATH_PREFIX, '') path = path.replace('%s:' % cls.PATH_PREFIX, '')
for transport in BridgeTransport.enumerate(): for transport in BridgeTransport.enumerate():
if path is None or transport.device['path'] == path: if path is None or transport.device['path'] == path:
return transport return transport

View File

@ -98,8 +98,12 @@ class HidTransport(Transport):
@classmethod @classmethod
def find_by_path(cls, path=None): 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(): for transport in HidTransport.enumerate():
print(path, transport.device['path'])
if path is None or transport.device['path'] == path: if path is None or transport.device['path'] == path:
return transport return transport
raise TransportException('HID device not found') raise TransportException('HID device not found')

View File

@ -70,7 +70,10 @@ class UdpTransport(Transport):
@classmethod @classmethod
def find_by_path(cls, path=None): 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) return UdpTransport(path)
def open(self): def open(self):