Package ldaptor :: Package protocols :: Package ldap :: Module ldaperrors
[hide private]
[frames] | no frames]

Source Code for Module ldaptor.protocols.ldap.ldaperrors

  1  # Copyright (C) 2001 Tommi Virtanen 
  2  # 
  3  # This library is free software; you can redistribute it and/or 
  4  # modify it under the terms of version 2.1 of the GNU Lesser General Public 
  5  # License as published by the Free Software Foundation. 
  6  # 
  7  # This library is distributed in the hope that it will be useful, 
  8  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
  9  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
 10  # Lesser General Public License for more details. 
 11  # 
 12  # You should have received a copy of the GNU Lesser General Public 
 13  # License along with this library; if not, write to the Free Software 
 14  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
 15   
 16  # make pyflakes not complain about undefined names 
 17  reverse = None 
 18  LDAPOther = None 
 19   
20 -def get(resultCode, errorMessage):
21 """Get an instance of the correct exception for this resultCode.""" 22 23 klass = reverse.get(resultCode) 24 if klass is not None: 25 return klass(errorMessage) 26 else: 27 return LDAPUnknownError(resultCode, errorMessage)
28
29 -class LDAPResult:
30 resultCode=None 31 name=None
32
33 -class Success(LDAPResult):
34 resultCode=0 35 name='success' 36
37 - def __init__(self, msg):
38 pass
39
40 -class LDAPException(Exception, LDAPResult):
41
42 - def _get_message(self): return self.__message
43 - def _set_message(self, value): self.__message = value
44 message = property(_get_message, _set_message) 45
46 - def __init__(self, message=None):
47 Exception.__init__(self) 48 self.message=message
49
50 - def __str__(self):
51 message=self.message 52 if message: 53 return '%s: %s' % (self.name, message) 54 elif self.name: 55 return self.name 56 else: 57 return 'Unknown LDAP error %r' % self
58
59 -class LDAPUnknownError(LDAPException):
60 resultCode=None 61
62 - def __init__(self, resultCode, message=None):
63 assert resultCode not in reverse, \ 64 "resultCode %r must be unknown" % resultCode 65 self.code=resultCode 66 LDAPException.__init__(self, message)
67
68 - def __str__(self):
69 codeName='unknownError(%d)'%self.code 70 if self.message: 71 return '%s: %s' % (codeName, self.message) 72 else: 73 return codeName
74 75 import new
76 -def init(**errors):
77 global reverse 78 reverse = {} 79 for name, value in errors.items(): 80 if value == errors['success']: 81 klass = Success 82 else: 83 classname = 'LDAP'+name[0].upper()+name[1:] 84 klass = new.classobj(classname, 85 (LDAPException,), 86 { 'resultCode': value, 87 'name': name, 88 }) 89 globals()[classname] = klass 90 reverse[value] = klass
91 92 init( 93 success=0, 94 operationsError=1, 95 protocolError=2, 96 timeLimitExceeded=3, 97 sizeLimitExceeded=4, 98 compareFalse=5, 99 compareTrue=6, 100 authMethodNotSupported=7, 101 strongAuthRequired=8, 102 # 9 reserved 103 referral=10 , 104 adminLimitExceeded=11 , 105 unavailableCriticalExtension=12 , 106 confidentialityRequired=13 , 107 saslBindInProgress=14 , 108 noSuchAttribute=16, 109 undefinedAttributeType=17, 110 inappropriateMatching=18, 111 constraintViolation=19, 112 attributeOrValueExists=20, 113 invalidAttributeSyntax=21, 114 # 22-31 unused 115 noSuchObject=32, 116 aliasProblem=33, 117 invalidDNSyntax=34, 118 # 35 reserved for undefined isLeaf 119 aliasDereferencingProblem=36, 120 # 37-47 unused 121 inappropriateAuthentication=48, 122 invalidCredentials=49, 123 insufficientAccessRights=50, 124 busy=51, 125 unavailable=52, 126 unwillingToPerform=53, 127 loopDetect=54, 128 # 55-63 unused 129 namingViolation=64, 130 objectClassViolation=65, 131 notAllowedOnNonLeaf=66, 132 notAllowedOnRDN=67, 133 entryAlreadyExists=68, 134 objectClassModsProhibited=69, 135 # 70 reserved for CLDAP 136 affectsMultipleDSAs=71, 137 # 72-79 unused 138 other=80, 139 # 81-90 reserved for APIs 140 ) 141 142 other=LDAPOther.resultCode 143