Exemplo n.º 1
0
 def __getattr__(self, name):
     if name in self.attr2extype:
         extype = self.attr2extype[name]
         if self.extensions and extype in self.extensions and not self.extensions[extype].exvalue is None:
             result = unquote(self.extensions[extype].exvalue)
         else:
             return None
     else:
         raise AttributeError("%s has no attribute %s" % (self.__class__.__name__, name))
     return result  # __getattr__()
Exemplo n.º 2
0
 def __setattr__(self, name, value):
     if name in self.attr2extype:
         extype = self.attr2extype[name]
         if value is None:
             # A value of None means that extension is deleted
             delattr(self, name)
         elif value != None:
             # Add appropriate extension
             self.extensions[extype] = LDAPUrlExtension(extype=extype, exvalue=unquote(value))
     else:
         self.__dict__[name] = value
Exemplo n.º 3
0
 def __setattr__(self, name, value):
     if name in self.attr2extype:
         extype = self.attr2extype[name]
         if value is None:
             # A value of None means that extension is deleted
             delattr(self, name)
         elif value != None:
             # Add appropriate extension
             self.extensions[extype] = LDAPUrlExtension(
                 extype=extype, exvalue=unquote(value))
     else:
         self.__dict__[name] = value
Exemplo n.º 4
0
 def __getattr__(self, name):
     if name in self.attr2extype:
         extype = self.attr2extype[name]
         if self.extensions and \
            extype in self.extensions and \
            not self.extensions[extype].exvalue is None:
             result = unquote(self.extensions[extype].exvalue)
         else:
             return None
     else:
         raise AttributeError('%s has no attribute %s' %
                              (self.__class__.__name__, name))
     return result  # __getattr__()
Exemplo n.º 5
0
 def _parse(self,ldap_url):
   """
   parse a LDAP URL and set the class attributes
   urlscheme,host,dn,attrs,scope,filterstr,extensions
   """
   if not isLDAPUrl(ldap_url):
     raise ValueError('Value %s for ldap_url does not seem to be a LDAP URL.' % (repr(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):
     # No / and ? found at all
     self.hostport = unquote(rest)
     self.dn = ''
     return
   else:
     if slash_pos!=-1 and (qemark_pos==-1 or (slash_pos<qemark_pos)):
       # Slash separates DN from hostport
       self.hostport = unquote(rest[:slash_pos])
       # Eat the slash from rest
       rest = rest[slash_pos+1:]
     elif qemark_pos!=1 and (slash_pos==-1 or (slash_pos>qemark_pos)):
       # Question mark separates hostport from rest, DN is assumed to be empty
       self.hostport = unquote(rest[:qemark_pos])
       # Do not eat question mark
       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('Invalid search scope %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
Exemplo n.º 6
0
 def _parse(self,ldap_url):
   """
   parse a LDAP URL and set the class attributes
   urlscheme,host,dn,attrs,scope,filterstr,extensions
   """
   if not isLDAPUrl(ldap_url):
     raise ValueError('Value %s for ldap_url does not seem to be a LDAP URL.' % (repr(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):
     # No / and ? found at all
     self.hostport = unquote(rest)
     self.dn = ''
     return
   else:
     if slash_pos!=-1 and (qemark_pos==-1 or (slash_pos<qemark_pos)):
       # Slash separates DN from hostport
       self.hostport = unquote(rest[:slash_pos])
       # Eat the slash from rest
       rest = rest[slash_pos+1:]
     elif qemark_pos!=1 and (slash_pos==-1 or (slash_pos>qemark_pos)):
       # Question mark separates hostport from rest, DN is assumed to be empty
       self.hostport = unquote(rest[:qemark_pos])
       # Do not eat question mark
       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('Invalid search scope %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
Exemplo n.º 7
0
 def _parse(self,extension):
   extension = extension.strip()
   if not extension:
     # Don't parse empty strings
     self.extype,self.exvalue = None,None
     return
   self.critical = extension[0]=='!'
   if extension[0]=='!':
     extension = extension[1:].strip()
   try:
     self.extype,self.exvalue = extension.split('=',1)
   except ValueError:
     # No value, just the extype
     self.extype,self.exvalue = extension,None
   else:
     self.exvalue = unquote(self.exvalue.strip())
   self.extype = self.extype.strip()
Exemplo n.º 8
0
 def _parse(self,extension):
   extension = extension.strip()
   if not extension:
     # Don't parse empty strings
     self.extype,self.exvalue = None,None
     return
   self.critical = extension[0]=='!'
   if extension[0]=='!':
     extension = extension[1:].strip()
   try:
     self.extype,self.exvalue = extension.split('=',1)
   except ValueError:
     # No value, just the extype
     self.extype,self.exvalue = extension,None
   else:
     self.exvalue = unquote(self.exvalue.strip())
   self.extype = self.extype.strip()