

def import_string(import_name, silent=False):
    'Imports an object based on a string.  This is useful if you want to\n    use import paths as endpoints or something similar.  An import path can\n    be specified either in dotted notation (``xml.sax.saxutils.escape``)\n    or with a colon as object delimiter (``xml.sax.saxutils:escape``).\n\n    If `silent` is True the return value will be `None` if the import fails.\n\n    :param import_name: the dotted name for the object to import.\n    :param silent: if set to `True` import errors are ignored and\n                   `None` is returned instead.\n    :return: imported object\n    '
    assert isinstance(import_name, string_types)
    import_name = str(import_name)
    try:
        if (':' in import_name):
            (module, obj) = import_name.split(':', 1)
        elif ('.' in import_name):
            (module, obj) = import_name.rsplit('.', 1)
        else:
            return __import__(import_name)
        if (PY2 and isinstance(obj, unicode)):
            obj = obj.encode('utf-8')
        try:
            return getattr(__import__(module, None, None, [obj]), obj)
        except (ImportError, AttributeError):
            modname = ((module + '.') + obj)
            __import__(modname)
            return sys.modules[modname]
    except ImportError as e:
        if (not silent):
            reraise(ImportStringError, ImportStringError(import_name, e), sys.exc_info()[2])

dataset/ETHPy150Open tony/tmuxp/tmuxp/testsuite/__init__.py import_string/original