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

Source Code for Module ldaptor.protocols.ldap.ldaperrors

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