<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def _object_factory(self, search_result):
 """Given a single search result, create and return an object :param tuple search_result: a single search result returned by an LDAP query, position 0 is the DN and position 1 is a dictionary of key/value pairs :return: A single AD object instance :rtype: Object (ADUser, ADGroup, etc.) """

        class_name = self.__class__.__name__
        module = self.__module__
        logging.debug('Creating object of type %s for DN: %s', class_name, search_result[0])
        module = importlib.import_module('{0}'.format(module))
        class_ = getattr(module, class_name)
        ado = class_(self.adq)

        # A unique set of all attribute names found
        attribute_names = set()
        # A unique set
        multiples = set()
        for k in search_result[1].keys():
            if k not in attribute_names:
                attribute_names.add(k)
            else:
                multiples.add(k)
        for k, val in search_result[1].iteritems():
            if k in multiples and not hasattr(ado, k):
                setattr(ado, k.lower(), list())
            if hasattr(ado, k):
                value = getattr(ado, k)
                if len(val) == 1:
                    value.append(val[0])
                else:
                    value.append(val)
            else:
                if len(val) == 1:
                    setattr(ado, k.lower(), val[0])
                else:
                    setattr(ado, k.lower(), val)


        logging.debug('Attributes and values for %s object (DN: %s): %s', class_name,
                      search_result[0], ado.__dict__)

        return ado