def fetch(self, searchval=None):
        """:func:`burpui.misc.auth.ldap.LdapLoader.fetch` searches for a user
        object in the LDAP server.

        :param searchval: attribute value to search for
        :type searchval: str

        :returns: dictionary of `distinguishedName` and `commonName` attributes for the
        user if found, otherwise None.
        """
        try:
            if self.filt:
                query = self.filt.format(self.attr, searchval)
            else:
                query = '({0}={1})'.format(self.attr, searchval)
            self.builogger.info('filter: {0} | base: {1}'.format(query, self.base))
            r = None
            with self.ldap:
                self.builogger.debug('LDAP Connection = {0}'.format(str(self.ldap)))
                self.ldap.search(self.base, query, attributes=['cn', self.attr])
                r = self.ldap.response
            if not r:
                raise Exception('no results')
        except Exception as e:
            self.builogger.error('Ooops, LDAP lookup failed: {0}'.format(str(e)))
            return None

        for record in r:
            attrs = record['attributes']
            if self.attr in attrs and searchval in attrs[self.attr]:
                self.builogger.info('Found DN: {0}'.format(record['dn']))
                return {'dn': record['dn'], 'cn': attrs['cn'][0]}
dataset/ETHPy150Open ziirish/burp-ui/burpui/misc/auth/ldap.py/LdapLoader.fetch/original