source: orange/Orange/OrangeCanvas/scheme/utils.py @ 11101:e5aa7c1c5b23

Revision 11101:e5aa7c1c5b23, 926 bytes checked in by Ales Erjavec <ales.erjavec@…>, 19 months ago (diff)

Added scheme package, containing the scheme graph workflow data structure/model.

Line 
1"""
2Utility functions.
3
4"""
5
6
7def name_lookup(qualified_name, globals={}):
8    """Return the object referenced by a qualified name (doted name).
9    """
10    module_name, class_name = qualified_name.rsplit(".", 1)
11    module = __import__(module_name, fromlist=[class_name], globals=globals)
12    return getattr(module, class_name)
13
14
15def qualified_name(qualified_object):
16    """Return a qualifeid name for `qualified_obj` (type or function).
17    """
18    return "%s.%s" % (qualified_object.__module__, qualified_object.__name__)
19
20
21def check_type(obj, type_or_tuple):
22    if not isinstance(obj, type_or_tuple):
23        raise TypeError("Expected %r. Got %r" % (type_or_tuple, type(obj)))
24
25
26def check_subclass(cls, class_or_tuple):
27    if not issubclass(cls, class_or_tuple):
28        raise TypeError("Expected %r. Got %r" % (class_or_tuple, type(cls)))
29
30
31def check_arg(pred, value):
32    if not pred:
33        raise ValueError(value)
Note: See TracBrowser for help on using the repository browser.