human
Complete the below
def ldap_auth(server='ldap', port=None, base_dn='ou=users,dc=domain,dc=com', mode='uid', secure=False, self_signed_certificate=None, cert_path=None, cert_file=None, cacert_path=None, cacert_file=None, key_file=None, bind_dn=None, bind_pw=None, filterstr='objectClass=*', username_attrib='uid', custom_scope='subtree', allowed_groups=None, manage_user=False, user_firstname_attrib='cn:1', user_lastname_attrib='cn:2', user_mail_attrib='mail', manage_groups=False, manage_groups_callback=[], db=None, group_dn=None, group_name_attrib='cn', group_member_attrib='memberUid', group_filterstr='objectClass=*', group_mapping={}, tls=False, logging_level='error'):

    ''''to use ldap login with MS Active Directory:
    from gluon.contrib.login_methods.ldap_auth import ldap_auth
    auth.settings.login_methods.append(ldap_auth(
    mode=\'ad\', server=\'my.domain.controller\',
    base_dn=\'ou=Users,dc=domain,dc=com\'))
    to use ldap login with Notes Domino:
    auth.settings.login_methods.append(ldap_auth(
    mode=\'domino\',server=\'my.domino.server\'))
    to use ldap login with OpenLDAP:
    auth.settings.login_methods.append(ldap_auth(
    server=\'my.ldap.server\', base_dn=\'ou=Users,dc=domain,dc=com\'))
    to use ldap login with OpenLDAP and subtree search and (optionally)
    multiple DNs:
    auth.settings.login_methods.append(ldap_auth(
    mode=\'uid_r\', server=\'my.ldap.server\',
    base_dn=[\'ou=Users,dc=domain,dc=com\',\'ou=Staff,dc=domain,dc=com\']))
    or (if using CN):
    auth.settings.login_methods.append(ldap_auth(
    mode=\'cn\', server=\'my.ldap.server\',
    base_dn=\'ou=Users,dc=domain,dc=com\'))
    or you can full customize the search for user:
    auth.settings.login_methods.append(ldap_auth(
    mode=\'custom\', server=\'my.ldap.server\',
    base_dn=\'ou=Users,dc=domain,dc=com\',
    username_attrib=\'uid\',
    custom_scope=\'subtree\'))
    the custom_scope can be: base, onelevel, subtree.
    If using secure ldaps:// pass secure=True and cert_path="..."
    If ldap is using GnuTLS then you need cert_file="..." instead cert_path
    because cert_path isn\'t implemented in GnuTLS :(
    To enable TLS, set tls=True:
    auth.settings.login_methods.append(ldap_auth(
    server=\'my.ldap.server\',
    base_dn=\'ou=Users,dc=domain,dc=com\',
    tls=True))
    If you need to bind to the directory with an admin account in order to
    search it then specify bind_dn & bind_pw to use for this.
    - currently only implemented for Active Directory
    If you need to restrict the set of allowed users (e.g. to members of a
    department) then specify an rfc4515 search filter string.
    - currently only implemented for mode in [\'ad\', \'company\',...'''
 ... What is a the Python code you requested?
assistant
#Here is the Python code you requested.
    if self_signed_certificate:
        ldap.set_option(ldap.OPT_X_TLS_REQUIRE_CERT, ldap.OPT_X_TLS_NEVER)
    logger = logging.getLogger('web2py.auth.ldap_auth')
    if (logging_level == 'error'):
        logger.setLevel(logging.ERROR)
    elif (logging_level == 'warning'):
        logger.setLevel(logging.WARNING)
    elif (logging_level == 'info'):
        logger.setLevel(logging.INFO)
    elif (logging_level == 'debug'):
        logger.setLevel(logging.DEBUG)
    def ldap_auth_aux(username, password, ldap_server=server, ldap_port=port, ldap_basedn=base_dn, ldap_mode=mode, ldap_binddn=bind_dn, ldap_bindpw=bind_pw, secure=secure, cert_path=cert_path, cert_file=cert_file, cacert_file=cacert_file, key_file=key_file, filterstr=filterstr, username_attrib=username_attrib, custom_scope=custom_scope, manage_user=manage_user, user_firstname_attrib=user_firstname_attrib, user_lastname_attrib=user_lastname_attrib, user_mail_attrib=user_mail_attrib, manage_groups=manage_groups, allowed_groups=allowed_groups, group_mapping=group_mapping, db=db):
        if (password == ''):
            logger.warning('blank    password    not    allowed')
            return False
        logger.debug(('mode:    [%s]    manage_user:    [%s]    custom_scope:    [%s]    manage_groups:    [%s]' % (str(mode), str(manage_user), str(custom_scope), str(manage_groups))))
        if manage_user:
            if (user_firstname_attrib.count(':') > 0):
                (user_firstname_attrib, user_firstname_part) = user_firstname_attrib.split(':', 1)
                user_firstname_part = (int(user_firstname_part) - 1)
            else:
                user_firstname_part = None
            if (user_lastname_attrib.count(':') > 0):
                (user_lastname_attrib, user_lastname_part) = user_lastname_attrib.split(':', 1)
                user_lastname_part = (int(user_lastname_part) - 1)
            else:
                user_lastname_part = None
            user_firstname_attrib = ldap.filter.escape_filter_chars(user_firstname_attrib)
           ...