<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def users(self, base_dn, samaccountnames=(), attributes=(), explicit_membership_only=False):
 """Gathers a list of ADUser objects :param str base_dn: The base DN to search within :param list attributes: Object attributes to populate, defaults to all :param list samaccountnames: A list of usernames for which objects will be created, defaults to all users if unspecified :param bool explicit_membership_only: If set True, memberof will only list groups for which users are directly referenced members :return: A list of populated ADUser objects :rtype: list """

        ad_users = []

        search_filter = '(&(objectClass=user)(!(objectClass=group))(!(objectClass=computer)){0})'
        # If no samaccountnames specified, filter will pull all user objects under
        # base_dn
        if not samaccountnames:
            search_filter = search_filter.format('(sAMAccountName=*)')
        else:
            # Extensible filter: http://bit.ly/1Qh4eyV
            if len(samaccountnames) == 1:
                account_names = '(sAMAccountName={0})'.format(samaccountnames[0])
            else:
                account_names = '(|{0})'.format(''.join(['(sAMAccountName={0})'.format(username) \
                                                for username in samaccountnames]))

            search_filter = search_filter.format(account_names)


        logging.debug('%s Search filter: %s', self.__class__.__name__, search_filter)

        results = self.adq.search(base_dn, search_filter, attributes)

        for search_result in results:
            adu = self._object_factory(search_result)
            # Each results index 0 of the tuple is the DN
            if not explicit_membership_only and 'memberof' in dir(adu):
                memberof = [g[0] for g in self.adq.search(base_dn,
                                                          '(member:1.2.840.113556.1.4.1941:={0})'.\
                                                          format(search_result[0]),
                                                          attributes=['memberof'])]
                adu.memberof = memberof
            ad_users.append(adu)


        return ad_users