Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions python/ola/StringUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ def StringEscape(s):
"""Escape unprintable characters in a string."""
# TODO(Peter): How does this interact with the E1.20 Unicode flag?
# We don't use sys.version_info.major to support Python 2.6.
if sys.version_info[0] == 2 and type(s) == str:
if sys.version_info[0] == 2 and isinstance(s, str):
return s.encode('string-escape')
elif sys.version_info[0] == 2 and type(s) == unicode:
elif sys.version_info[0] == 2 and isinstance(s, unicode):
return s.encode('unicode-escape')
elif type(s) == str:
elif isinstance(s, str):
# All strings in Python 3 are unicode
# This encode/decode pair gets us an escaped string
return s.encode('unicode-escape').decode(encoding="ascii",
Expand Down
6 changes: 3 additions & 3 deletions tools/rdm/ResponderTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -612,15 +612,15 @@ def _CheckForAckOrNack(self, response, unpacked_data, unpack_exception):
return True

def _EscapeData(self, data):
if type(data) == list:
if isinstance(data, list):
return [self._EscapeData(i) for i in data]
elif type(data) == dict:
elif isinstance(data, dict):
d = {}
for k, v in data.items():
# We can't escape the key as then it may become a new key
d[k] = self._EscapeData(v)
return d
elif type(data) == str or type(data) == unicode:
elif isinstance(data, str) or isinstance(data, unicode):
return StringEscape(data)
else:
return data
Expand Down
2 changes: 1 addition & 1 deletion tools/rdm/TestHelpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
def ContainsUnprintable(s):
"""Check if a string s contain unprintable characters."""
# TODO(Peter): How does this interact with the E1.20 Unicode flag?
if type(s) == str or type(s) == unicode:
if isinstance(s, str) or isinstance(s, unicode):
# All strings in Python 3 are unicode, Python 2 ones might not be
return s != StringEscape(s)
else:
Expand Down