'Find a Python object for "name", perhaps using the given module
and/or classname.  Returns a list of (name, object entry) tuples.'

def find_obj(self, env, modname, classname, name, type, searchmode=0):

    if (name[(-2):] == '()'):
        name = name[:(-2)]
    if (not name):
        return []
    objects = self.data['objects']
    matches = []
    newname = None
    if (searchmode == 1):
        if (type is None):
            objtypes = list(self.object_types)
        else:
            objtypes = self.objtypes_for_role(type)
        if (objtypes is not None):
            if (modname and classname):
                fullname = ((((modname + '.') + classname) + '.') + name)
                if ((fullname in objects) and (objects[fullname][1] in objtypes)):
                    newname = fullname
            if (not newname):
                if (modname and (((modname + '.') + name) in objects) and (objects[((modname + '.') + name)][1] in objtypes)):
                    newname = ((modname + '.') + name)
                elif ((name in objects) and (objects[name][1] in objtypes)):
                    newname = name
                else:
                    searchname = ('.' + name)
                    matches = [(oname, objects[oname]) for oname in objects if (oname.endswith(searchname) and (objects[oname][1] in objtypes))]
    elif (name in objects):
        newname = name
    elif (type == 'mod'):
        return []
    elif (classname and (((classname + '.') + name) in objects)):
        newname = ((classname + '.') + name)
    elif (modname and (((modname + '.') + name) in objects)):
        newname = ((modname + '.') + name)
    elif (modname and classname and (((((modname + '.') + classname) + '.') + name) in objects)):
        newname = ((((modname + '.') + classname) + '.') + name)
    elif ((type == 'exc') and ('.' not in name) and (('exceptions.' + name) in objects)):
        newname = ('exceptions.' + name)
    elif ((type in ('func', 'meth')) and ('.' not in name) and (('object.' + name) in objects)):
        newname = ('object.' + name)
    if (newname is not None):
        matches.append((newname, objects[newname]))
    return matches
