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
43 - def _get_message(self): return self.__message
44 - def _set_message(self, value): self.__message = value
45 message = property(_get_message, _set_message) 46
47 - def __init__(self, message=None):
48 Exception.__init__(self) 49 self.message=message
50
51 - def __str__(self):
52 message=self.message 53 if message: 54 return '%s: %s' % (self.name, message) 55 elif self.name: 56 return self.name 57 else: 58 return 'Unknown LDAP error %r' % self
59
60 -class LDAPUnknownError(LDAPException):
61 resultCode=None 62
63 - def __init__(self, resultCode, message=None):
64 assert resultCode not in reverse, \ 65 "resultCode %r must be unknown" % resultCode 66 self.code=resultCode 67 LDAPException.__init__(self, message)
68
69 - def __str__(self):
70 codeName='unknownError(%d)'%self.code 71 if self.message: 72 return '%s: %s' % (codeName, self.message) 73 else: 74 return codeName
75 76 import new
77 -def init(**errors):
78 global reverse 79 reverse = {} 80 for name, value in errors.items(): 81 if value == errors['success']: 82 klass = Success 83 else: 84 classname = 'LDAP'+name[0].upper()+name[1:] 85 klass = new.classobj(classname, 86 (LDAPException,), 87 { 'resultCode': value, 88 'name': name, 89 }) 90 globals()[classname] = klass 91 reverse[value] = klass
92 93 init( 94 success=0, 95 operationsError=1, 96 protocolError=2, 97 timeLimitExceeded=3, 98 sizeLimitExceeded=4, 99 compareFalse=5, 100 compareTrue=6, 101 authMethodNotSupported=7, 102 strongAuthRequired=8, 103 # 9 reserved 104 referral=10 , 105 adminLimitExceeded=11 , 106 unavailableCriticalExtension=12 , 107 confidentialityRequired=13 , 108 saslBindInProgress=14 , 109 noSuchAttribute=16, 110 undefinedAttributeType=17, 111 inappropriateMatching=18, 112 constraintViolation=19, 113 attributeOrValueExists=20, 114 invalidAttributeSyntax=21, 115 # 22-31 unused 116 noSuchObject=32, 117 aliasProblem=33, 118 invalidDNSyntax=34, 119 # 35 reserved for undefined isLeaf 120 aliasDereferencingProblem=36, 121 # 37-47 unused 122 inappropriateAuthentication=48, 123 invalidCredentials=49, 124 insufficientAccessRights=50, 125 busy=51, 126 unavailable=52, 127 unwillingToPerform=53, 128 loopDetect=54, 129 # 55-63 unused 130 namingViolation=64, 131 objectClassViolation=65, 132 notAllowedOnNonLeaf=66, 133 notAllowedOnRDN=67, 134 entryAlreadyExists=68, 135 objectClassModsProhibited=69, 136 # 70 reserved for CLDAP 137 affectsMultipleDSAs=71, 138 # 72-79 unused 139 other=80, 140 # 81-90 reserved for APIs 141 ) 142 143 other=LDAPOther.resultCode 144