summaryrefslogtreecommitdiffstats
path: root/bindings/python
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2020-02-17 13:12:12 +0100
committerDavid Robillard <d@drobilla.net>2020-02-17 13:12:12 +0100
commit411a93bd837fcba108a5976be2bec07311e037bc (patch)
tree3513970fe83d630a1e7a8e8baed87418fa0542b9 /bindings/python
parent5ae973b8f7f38f32a28b6b23bfe622b51bb64c51 (diff)
downloadlilv-411a93bd837fcba108a5976be2bec07311e037bc.tar.gz
lilv-411a93bd837fcba108a5976be2bec07311e037bc.tar.bz2
lilv-411a93bd837fcba108a5976be2bec07311e037bc.zip
Add portable Python _is_string() utility and use it everywhere
Diffstat (limited to 'bindings/python')
-rw-r--r--bindings/python/lilv.py17
1 files changed, 12 insertions, 5 deletions
diff --git a/bindings/python/lilv.py b/bindings/python/lilv.py
index c548e98..2ba5c43 100644
--- a/bindings/python/lilv.py
+++ b/bindings/python/lilv.py
@@ -36,6 +36,13 @@ class _LilvLib:
c = _LilvLib()
+def _is_string(obj):
+ if sys.version_info[0] == 3:
+ return isinstance(obj, str)
+ else:
+ return isinstance(obj, basestring)
+
+
def _as_uri(obj):
"""Utility function for converting some object into a URI node"""
if type(obj) in [Plugin, PluginClass, UI]:
@@ -336,8 +343,8 @@ class Plugin(Structure):
Note this function is slower than get_port_by_index(),
especially on plugins with a very large number of ports.
"""
- assert type(symbol) == str or isinstance(symbol, Node)
- if type(symbol) == str:
+ assert _is_string(symbol) or isinstance(symbol, Node)
+ if _is_string(symbol):
symbol = self.world.new_string(symbol)
assert isinstance(symbol, Node)
@@ -671,7 +678,7 @@ class UI(Structure):
return str(self.get_uri())
def __eq__(self, other):
- if type(other) == str or type(other) == Node:
+ if _is_string(other) or type(other) == Node:
return self.get_uri() == other
return self.get_uri() == other.get_uri()
@@ -1119,7 +1126,7 @@ class Namespace:
def __init__(self, world, prefix):
assert isinstance(world, World)
- assert type(prefix) == str
+ assert _is_string(prefix)
self.world = world
self.prefix = prefix
@@ -1526,7 +1533,7 @@ class VariadicFunction(object):
class String(str):
# Wrapper for string parameters to pass as raw C UTF-8 strings
def from_param(cls, obj):
- assert isinstance(obj, str)
+ assert _is_string(obj)
return obj.encode("utf-8")
from_param = classmethod(from_param)