Skip to content

Commit

Permalink
Python3: fixed string type checking in iio.NetworkContext to be compa…
Browse files Browse the repository at this point in the history
…tible with Python 2 and Python 3.

Signed-off-by: Matej Kenda <[email protected]>
  • Loading branch information
matejk committed Jan 8, 2020
1 parent 1036e51 commit e641094
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion bindings/python/iio.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ def _checkNegative(result, func, arguments):
else:
raise OSError(-result, _strerror(-result))

# Python 2 and Python 3 compatible _isstring function.
def _isstring(s):
try:
# attempt to evaluate basestring (Python 2)
return isinstance(s, basestring)
except NameError:
# No basestring --> Python 3
return isinstance(s, str)

class _ScanContext(Structure):
pass
class _ContextInfo(Structure):
Expand Down Expand Up @@ -739,7 +748,7 @@ def __init__(self, _context=None):

if(_context is None):
self._context = _new_default()
elif type(_context) is str or type(_context) is unicode:
elif _isstring(_context):
self._context = _new_uri(_context.encode('ascii'))
else:
self._context = _context
Expand Down

0 comments on commit e641094

Please sign in to comment.