'parse a LDAP URL and set the class attributes
urlscheme,host,dn,attrs,scope,filterstr,extensions'

def _parse(self, ldap_url):

    if (not isLDAPUrl(ldap_url)):
        raise ValueError, 'Parameter    ldap_url    does    not    seem    to    be    a    LDAP    URL.'
    (scheme, rest) = ldap_url.split('://', 1)
    self.urlscheme = scheme.strip()
    if (not (self.urlscheme in ['ldap', 'ldaps', 'ldapi'])):
        raise ValueError, ('LDAP    URL    contains    unsupported    URL    scheme    %s.' % self.urlscheme)
    slash_pos = rest.find('/')
    qemark_pos = rest.find('?')
    if ((slash_pos == (-1)) and (qemark_pos == (-1))):
        self.hostport = unquote(rest)
        self.dn = ''
        return
    elif ((slash_pos != (-1)) and ((qemark_pos == (-1)) or (slash_pos < qemark_pos))):
        self.hostport = unquote(rest[:slash_pos])
        rest = rest[(slash_pos + 1):]
    elif ((qemark_pos != 1) and ((slash_pos == (-1)) or (slash_pos > qemark_pos))):
        self.hostport = unquote(rest[:qemark_pos])
        rest = rest[qemark_pos:]
    else:
        raise ValueError, 'Something    completely    weird    happened!'
    paramlist = rest.split('?', 4)
    paramlist_len = len(paramlist)
    if (paramlist_len >= 1):
        self.dn = unquote(paramlist[0]).strip()
    if ((paramlist_len >= 2) and paramlist[1]):
        self.attrs = unquote(paramlist[1].strip()).split(',')
    if (paramlist_len >= 3):
        scope = paramlist[2].strip()
        try:
            self.scope = SEARCH_SCOPE[scope]
        except KeyError:
            raise ValueError, ('Search    scope    must    be    either    one    of    base,    one    or    sub.    LDAP    URL    contained    %s' % repr(scope))
    if (paramlist_len >= 4):
        filterstr = paramlist[3].strip()
        if (not filterstr):
            self.filterstr = None
        else:
            self.filterstr = unquote(filterstr)
    if (paramlist_len >= 5):
        if paramlist[4]:
            self.extensions = LDAPUrlExtensions()
            self.extensions.parse(paramlist[4])
        else:
            self.extensions = None
    return
