'Wrapper method mainly for serializing calls into OpenLDAP libs
and trace logs'

def _ldap_call(self, func, *args, **kwargs):

    self._ldap_object_lock.acquire()
    if __debug__:
        if (self._trace_level >= 1):
            self._trace_file.write(('***    %s    -    %s    (%s,%s)\n' % (self._uri, ((self.__class__.__name__ + '.') + func.__name__), repr(args), repr(kwargs))))
            if (self._trace_level >= 3):
                traceback.print_stack(limit=self._trace_stack_limit, file=self._trace_file)
    try:
        try:
            result = func(*args, **kwargs)
            if (__debug__ and (self._trace_level >= 2)):
                if (func.__name__ != 'unbind_ext'):
                    diagnostic_message_success = self._l.get_option(ldap.OPT_DIAGNOSTIC_MESSAGE)
                else:
                    diagnostic_message_success = None
        finally:
            self._ldap_object_lock.release()
    except LDAPError as e:
        if (__debug__ and (self._trace_level >= 2)):
            self._trace_file.write(('=>    LDAPError    -    %s:    %s\n' % (e.__class__.__name__, str(e))))
        raise
    else:
        if (__debug__ and (self._trace_level >= 2)):
            if (not (diagnostic_message_success is None)):
                self._trace_file.write(('=>    diagnosticMessage:    %s\n' % repr(diagnostic_message_success)))
            if ((result != None) and (result != (None, None))):
                self._trace_file.write(('=>    result:    %s\n' % repr(result)))
    return result
