Skip to content

Commit ef8c019

Browse files
committed
Fix a bug in Device._matches()
list(string) makes a list of characters contained in the string, and not a list with single string entry as I thought. Also, clean up self._path if no device was connected.
1 parent ea4fc6b commit ef8c019

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

ev3dev/ev3dev.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ def __init__(self, class_name, name='*', **kwargs ):
6363

6464
classpath = os.path.abspath( Device.DEVICE_ROOT_PATH + '/' + class_name )
6565
self.filehandle_cache = {}
66-
self.connected = False
6766

6867
for file in os.listdir( classpath ):
6968
if fnmatch.fnmatch(file, name):
@@ -74,13 +73,19 @@ def __init__(self, class_name, name='*', **kwargs ):
7473
self.connected = True
7574
return
7675

76+
self._path = ''
77+
self.connected = False
78+
7779
def _matches(self, attribute, pattern):
7880
"""Test if attribute value matches pattern (that is, if pattern is a
7981
substring of attribute value). If pattern is a list, then a match with
8082
any one entry is enough.
8183
"""
8284
value = self._get_attribute(attribute)
83-
return any([value.find(pat) >= 0 for pat in list(pattern)])
85+
if isinstance(pattern, list):
86+
return any([value.find(pat) >= 0 for pat in pattern])
87+
else:
88+
return value.find(pattern) >= 0
8489

8590
def _attribute_file( self, attribute, mode, reopen=False ):
8691
"""Manages the file handle cache and opening the files in the correct mode"""

0 commit comments

Comments
 (0)