[Py3] Fix raise/except
This commit is contained in:
parent
5b8236dc1c
commit
cf7ec42f61
@ -15,7 +15,7 @@ class DeleteLeafs(ldap.async.AsyncSearchHandler):
|
|||||||
|
|
||||||
def startSearch(self,searchRoot,searchScope):
|
def startSearch(self,searchRoot,searchScope):
|
||||||
if not searchScope in [ldap.SCOPE_ONELEVEL,ldap.SCOPE_SUBTREE]:
|
if not searchScope in [ldap.SCOPE_ONELEVEL,ldap.SCOPE_SUBTREE]:
|
||||||
raise ValueError, "Parameter searchScope must be either ldap.SCOPE_ONELEVEL or ldap.SCOPE_SUBTREE."
|
raise ValueError("Parameter searchScope must be either ldap.SCOPE_ONELEVEL or ldap.SCOPE_SUBTREE.")
|
||||||
self.nonLeafEntries = []
|
self.nonLeafEntries = []
|
||||||
self.deletedEntries = 0
|
self.deletedEntries = 0
|
||||||
ldap.async.AsyncSearchHandler.startSearch(
|
ldap.async.AsyncSearchHandler.startSearch(
|
||||||
@ -45,7 +45,7 @@ class DeleteLeafs(ldap.async.AsyncSearchHandler):
|
|||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
self._l.delete_s(dn)
|
self._l.delete_s(dn)
|
||||||
except ldap.NOT_ALLOWED_ON_NONLEAF,e:
|
except ldap.NOT_ALLOWED_ON_NONLEAF as e:
|
||||||
self.nonLeafEntries.append(dn)
|
self.nonLeafEntries.append(dn)
|
||||||
else:
|
else:
|
||||||
self.deletedEntries = self.deletedEntries+1
|
self.deletedEntries = self.deletedEntries+1
|
||||||
|
@ -72,7 +72,7 @@ class PagedResultsSearchObject:
|
|||||||
else:
|
else:
|
||||||
break # no more pages available
|
break # no more pages available
|
||||||
|
|
||||||
except ldap.SERVER_DOWN,e:
|
except ldap.SERVER_DOWN as e:
|
||||||
try:
|
try:
|
||||||
self.reconnect(self._uri)
|
self.reconnect(self._uri)
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
|
@ -16,7 +16,7 @@ import sys,ldap,ldapurl,getpass
|
|||||||
try:
|
try:
|
||||||
ldap_url = ldapurl.LDAPUrl(sys.argv[1])
|
ldap_url = ldapurl.LDAPUrl(sys.argv[1])
|
||||||
request_ttl = int(sys.argv[2])
|
request_ttl = int(sys.argv[2])
|
||||||
except IndexError,ValueError:
|
except (IndexError, ValueError):
|
||||||
print 'Usage: dds.py <LDAP URL> <TTL>'
|
print 'Usage: dds.py <LDAP URL> <TTL>'
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
@ -38,7 +38,7 @@ if ldap_url.cred is None:
|
|||||||
try:
|
try:
|
||||||
ldap_conn.simple_bind_s(ldap_url.who or '',ldap_url.cred or '')
|
ldap_conn.simple_bind_s(ldap_url.who or '',ldap_url.cred or '')
|
||||||
|
|
||||||
except ldap.INVALID_CREDENTIALS,e:
|
except ldap.INVALID_CREDENTIALS as e:
|
||||||
print 'Simple bind failed:',str(e)
|
print 'Simple bind failed:',str(e)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
@ -46,7 +46,7 @@ else:
|
|||||||
extreq = RefreshRequest(entryName=ldap_url.dn,requestTtl=request_ttl)
|
extreq = RefreshRequest(entryName=ldap_url.dn,requestTtl=request_ttl)
|
||||||
try:
|
try:
|
||||||
extop_resp_obj = ldap_conn.extop_s(extreq,extop_resp_class=RefreshResponse)
|
extop_resp_obj = ldap_conn.extop_s(extreq,extop_resp_class=RefreshResponse)
|
||||||
except ldap.LDAPError,e:
|
except ldap.LDAPError as e:
|
||||||
print str(e)
|
print str(e)
|
||||||
else:
|
else:
|
||||||
if extop_resp_obj.responseTtl!=request_ttl:
|
if extop_resp_obj.responseTtl!=request_ttl:
|
||||||
|
@ -42,7 +42,7 @@ if ldap_url.who and ldap_url.cred is None:
|
|||||||
try:
|
try:
|
||||||
ldap_conn.simple_bind_s(ldap_url.who or '',ldap_url.cred or '')
|
ldap_conn.simple_bind_s(ldap_url.who or '',ldap_url.cred or '')
|
||||||
|
|
||||||
except ldap.INVALID_CREDENTIALS,e:
|
except ldap.INVALID_CREDENTIALS as e:
|
||||||
print 'Simple bind failed:',str(e)
|
print 'Simple bind failed:',str(e)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
@ -56,7 +56,7 @@ try:
|
|||||||
serverctrls=[SearchNoOpControl(criticality=True)],
|
serverctrls=[SearchNoOpControl(criticality=True)],
|
||||||
)
|
)
|
||||||
_,_,_,search_response_ctrls = ldap_conn.result3(msg_id,all=1,timeout=SEARCH_TIMEOUT)
|
_,_,_,search_response_ctrls = ldap_conn.result3(msg_id,all=1,timeout=SEARCH_TIMEOUT)
|
||||||
except LDAPLimitErrors,e:
|
except LDAPLimitErrors as e:
|
||||||
ldap_conn.abandon(msg_id)
|
ldap_conn.abandon(msg_id)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ from ldap.controls.ppolicy import PasswordPolicyError,PasswordPolicyControl
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
ldap_url = ldapurl.LDAPUrl(sys.argv[1])
|
ldap_url = ldapurl.LDAPUrl(sys.argv[1])
|
||||||
except IndexError,ValueError:
|
except (IndexError,ValueError):
|
||||||
print 'Usage: ppolicy.py <LDAP URL>'
|
print 'Usage: ppolicy.py <LDAP URL>'
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
@ -38,7 +38,7 @@ if ldap_url.cred is None:
|
|||||||
try:
|
try:
|
||||||
msgid = ldap_conn.simple_bind(ldap_url.who,ldap_url.cred,serverctrls=[PasswordPolicyControl()])
|
msgid = ldap_conn.simple_bind(ldap_url.who,ldap_url.cred,serverctrls=[PasswordPolicyControl()])
|
||||||
res_type,res_data,res_msgid,res_ctrls = ldap_conn.result3(msgid)
|
res_type,res_data,res_msgid,res_ctrls = ldap_conn.result3(msgid)
|
||||||
except ldap.INVALID_CREDENTIALS,e:
|
except ldap.INVALID_CREDENTIALS as e:
|
||||||
print 'Simple bind failed:',str(e)
|
print 'Simple bind failed:',str(e)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
else:
|
else:
|
||||||
|
@ -39,7 +39,7 @@ if ldap_url.cred is None:
|
|||||||
try:
|
try:
|
||||||
ldap_conn.simple_bind_s(ldap_url.who,ldap_url.cred)
|
ldap_conn.simple_bind_s(ldap_url.who,ldap_url.cred)
|
||||||
|
|
||||||
except ldap.INVALID_CREDENTIALS,e:
|
except ldap.INVALID_CREDENTIALS as e:
|
||||||
print 'Simple bind failed:',str(e)
|
print 'Simple bind failed:',str(e)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ from ldap.controls.sessiontrack import SessionTrackingControl,SESSION_TRACKING_F
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
ldap_url = ldapurl.LDAPUrl(sys.argv[1])
|
ldap_url = ldapurl.LDAPUrl(sys.argv[1])
|
||||||
except IndexError,ValueError:
|
except (IndexError, ValueError):
|
||||||
print 'Usage: %s <LDAP URL>' % (sys.argv[0])
|
print 'Usage: %s <LDAP URL>' % (sys.argv[0])
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
@ -38,7 +38,7 @@ if ldap_url.who and ldap_url.cred is None:
|
|||||||
try:
|
try:
|
||||||
ldap_conn.simple_bind_s(ldap_url.who or '',ldap_url.cred or '')
|
ldap_conn.simple_bind_s(ldap_url.who or '',ldap_url.cred or '')
|
||||||
|
|
||||||
except ldap.INVALID_CREDENTIALS,e:
|
except ldap.INVALID_CREDENTIALS as e:
|
||||||
print 'Simple bind failed:',str(e)
|
print 'Simple bind failed:',str(e)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
@ -149,7 +149,7 @@ while watcher_running:
|
|||||||
# Now we login to the LDAP server
|
# Now we login to the LDAP server
|
||||||
try:
|
try:
|
||||||
ldap_connection.simple_bind_s(ldap_url.who,ldap_url.cred)
|
ldap_connection.simple_bind_s(ldap_url.who,ldap_url.cred)
|
||||||
except ldap.INVALID_CREDENTIALS, e:
|
except ldap.INVALID_CREDENTIALS as e:
|
||||||
print 'Login to LDAP server failed: ', str(e)
|
print 'Login to LDAP server failed: ', str(e)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
except ldap.SERVER_DOWN:
|
except ldap.SERVER_DOWN:
|
||||||
@ -174,7 +174,7 @@ while watcher_running:
|
|||||||
# User asked to exit
|
# User asked to exit
|
||||||
commenceShutdown()
|
commenceShutdown()
|
||||||
pass
|
pass
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
# Handle any exception
|
# Handle any exception
|
||||||
if watcher_running:
|
if watcher_running:
|
||||||
print 'Encountered a problem, going to retry. Error:', str(e)
|
print 'Encountered a problem, going to retry. Error:', str(e)
|
||||||
|
@ -67,13 +67,13 @@ for ldap_uri,sasl_mech,sasl_cb_value_dict in [
|
|||||||
l.protocol_version = 3
|
l.protocol_version = 3
|
||||||
try:
|
try:
|
||||||
l.sasl_interactive_bind_s("", sasl_auth)
|
l.sasl_interactive_bind_s("", sasl_auth)
|
||||||
except ldap.LDAPError,e:
|
except ldap.LDAPError as e:
|
||||||
print 'Error using SASL mechanism',sasl_auth.mech,str(e)
|
print 'Error using SASL mechanism',sasl_auth.mech,str(e)
|
||||||
else:
|
else:
|
||||||
print 'Sucessfully bound using SASL mechanism:',sasl_auth.mech
|
print 'Sucessfully bound using SASL mechanism:',sasl_auth.mech
|
||||||
try:
|
try:
|
||||||
print 'Result of Who Am I? ext. op:',repr(l.whoami_s())
|
print 'Result of Who Am I? ext. op:',repr(l.whoami_s())
|
||||||
except ldap.LDAPError,e:
|
except ldap.LDAPError as e:
|
||||||
print 'Error using SASL mechanism',sasl_auth.mech,str(e)
|
print 'Error using SASL mechanism',sasl_auth.mech,str(e)
|
||||||
try:
|
try:
|
||||||
print 'OPT_X_SASL_USERNAME',repr(l.get_option(ldap.OPT_X_SASL_USERNAME))
|
print 'OPT_X_SASL_USERNAME',repr(l.get_option(ldap.OPT_X_SASL_USERNAME))
|
||||||
|
@ -48,7 +48,7 @@ try:
|
|||||||
('usage',range(2)),
|
('usage',range(2)),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
except KeyError,e:
|
except KeyError as e:
|
||||||
print '***KeyError',str(e)
|
print '***KeyError',str(e)
|
||||||
|
|
||||||
|
|
||||||
|
@ -51,7 +51,7 @@ if subschemasubentry_dn is None:
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
options,args=getopt.getopt(sys.argv[1:],'',['html'])
|
options,args=getopt.getopt(sys.argv[1:],'',['html'])
|
||||||
except getopt.error,e:
|
except getopt.error:
|
||||||
print 'Error: %s\nUsage: schema_oc_tree.py [--html] [LDAP URL]'
|
print 'Error: %s\nUsage: schema_oc_tree.py [--html] [LDAP URL]'
|
||||||
|
|
||||||
html_output = options and options[0][0]=='--html'
|
html_output = options and options[0][0]=='--html'
|
||||||
|
@ -195,7 +195,7 @@ else:
|
|||||||
self._oc_value = ''
|
self._oc_value = ''
|
||||||
# Unhandled tags
|
# Unhandled tags
|
||||||
else:
|
else:
|
||||||
raise ValueError,'Unknown tag %s' % (raw_name)
|
raise ValueError('Unknown tag %s' % (raw_name))
|
||||||
|
|
||||||
def endElement(self,raw_name):
|
def endElement(self,raw_name):
|
||||||
assert raw_name.startswith('dsml:'),'Illegal name'
|
assert raw_name.startswith('dsml:'),'Illegal name'
|
||||||
@ -230,7 +230,7 @@ else:
|
|||||||
del self._oc_value
|
del self._oc_value
|
||||||
# Unhandled tags
|
# Unhandled tags
|
||||||
else:
|
else:
|
||||||
raise ValueError,'Unknown tag %s' % (raw_name)
|
raise ValueError('Unknown tag %s' % (raw_name))
|
||||||
|
|
||||||
def characters(self,ch):
|
def characters(self,ch):
|
||||||
if self.__dict__.has_key('_oc_value'):
|
if self.__dict__.has_key('_oc_value'):
|
||||||
|
@ -145,9 +145,9 @@ def DecodeControlTuples(ldapControlTuples,knownLDAPControls=None):
|
|||||||
control.controlType,control.criticality = controlType,criticality
|
control.controlType,control.criticality = controlType,criticality
|
||||||
try:
|
try:
|
||||||
control.decodeControlValue(encodedControlValue)
|
control.decodeControlValue(encodedControlValue)
|
||||||
except PyAsn1Error,e:
|
except PyAsn1Error:
|
||||||
if criticality:
|
if criticality:
|
||||||
raise e
|
raise
|
||||||
else:
|
else:
|
||||||
result.append(control)
|
result.append(control)
|
||||||
return result
|
return result
|
||||||
|
@ -65,7 +65,7 @@ def _ldap_function_call(lock,func,*args,**kwargs):
|
|||||||
finally:
|
finally:
|
||||||
if lock:
|
if lock:
|
||||||
lock.release()
|
lock.release()
|
||||||
except LDAPError,e:
|
except LDAPError as e:
|
||||||
if __debug__ and ldap._trace_level>=2:
|
if __debug__ and ldap._trace_level>=2:
|
||||||
ldap._trace_file.write('=> LDAPError: %s\n' % (str(e)))
|
ldap._trace_file.write('=> LDAPError: %s\n' % (str(e)))
|
||||||
raise
|
raise
|
||||||
|
@ -109,7 +109,7 @@ class SimpleLDAPObject:
|
|||||||
diagnostic_message_success = self._l.get_option(ldap.OPT_DIAGNOSTIC_MESSAGE)
|
diagnostic_message_success = self._l.get_option(ldap.OPT_DIAGNOSTIC_MESSAGE)
|
||||||
finally:
|
finally:
|
||||||
self._ldap_object_lock.release()
|
self._ldap_object_lock.release()
|
||||||
except LDAPError,e:
|
except LDAPError as e:
|
||||||
if __debug__ and self._trace_level>=2:
|
if __debug__ and self._trace_level>=2:
|
||||||
self._trace_file.write('=> LDAPError - %s: %s\n' % (e.__class__.__name__,str(e)))
|
self._trace_file.write('=> LDAPError - %s: %s\n' % (e.__class__.__name__,str(e)))
|
||||||
raise
|
raise
|
||||||
@ -132,9 +132,9 @@ class SimpleLDAPObject:
|
|||||||
elif self.__dict__.has_key(name):
|
elif self.__dict__.has_key(name):
|
||||||
return self.__dict__[name]
|
return self.__dict__[name]
|
||||||
else:
|
else:
|
||||||
raise AttributeError,'%s has no attribute %s' % (
|
raise AttributeError('%s has no attribute %s' % (
|
||||||
self.__class__.__name__,repr(name)
|
self.__class__.__name__,repr(name)
|
||||||
)
|
))
|
||||||
|
|
||||||
def fileno():
|
def fileno():
|
||||||
"""
|
"""
|
||||||
@ -863,14 +863,14 @@ class ReconnectLDAPObject(SimpleLDAPObject):
|
|||||||
SimpleLDAPObject.start_tls_s(self)
|
SimpleLDAPObject.start_tls_s(self)
|
||||||
# Repeat last simple or SASL bind
|
# Repeat last simple or SASL bind
|
||||||
self._apply_last_bind()
|
self._apply_last_bind()
|
||||||
except (ldap.SERVER_DOWN,ldap.TIMEOUT),e:
|
except (ldap.SERVER_DOWN,ldap.TIMEOUT):
|
||||||
if __debug__ and self._trace_level>=1:
|
if __debug__ and self._trace_level>=1:
|
||||||
self._trace_file.write('*** %s reconnect to %s failed\n' % (
|
self._trace_file.write('*** %s reconnect to %s failed\n' % (
|
||||||
counter_text,uri
|
counter_text,uri
|
||||||
))
|
))
|
||||||
reconnect_counter = reconnect_counter-1
|
reconnect_counter = reconnect_counter-1
|
||||||
if not reconnect_counter:
|
if not reconnect_counter:
|
||||||
raise e
|
raise
|
||||||
if __debug__ and self._trace_level>=1:
|
if __debug__ and self._trace_level>=1:
|
||||||
self._trace_file.write('=> delay %s...\n' % (retry_delay))
|
self._trace_file.write('=> delay %s...\n' % (retry_delay))
|
||||||
time.sleep(retry_delay)
|
time.sleep(retry_delay)
|
||||||
|
@ -434,7 +434,7 @@ class SubSchema:
|
|||||||
schema_attr_type = self.sed[AttributeType][a]
|
schema_attr_type = self.sed[AttributeType][a]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
if raise_keyerror:
|
if raise_keyerror:
|
||||||
raise KeyError,'No attribute type found in sub schema by name %s' % (a)
|
raise KeyError('No attribute type found in sub schema by name %s' % (a))
|
||||||
# If there's no schema element for this attribute type
|
# If there's no schema element for this attribute type
|
||||||
# but still KeyError is to be ignored we filter it away
|
# but still KeyError is to be ignored we filter it away
|
||||||
del l[a]
|
del l[a]
|
||||||
|
@ -211,7 +211,7 @@ class TestLdapCExtension(unittest.TestCase):
|
|||||||
got_timeout = False
|
got_timeout = False
|
||||||
try:
|
try:
|
||||||
r = l.result4(m, _ldap.MSG_ALL, 0.3) # (timeout /could/ be longer)
|
r = l.result4(m, _ldap.MSG_ALL, 0.3) # (timeout /could/ be longer)
|
||||||
except _ldap.TIMEOUT, e:
|
except _ldap.TIMEOUT as e:
|
||||||
got_timeout = True
|
got_timeout = True
|
||||||
self.assertTrue(got_timeout)
|
self.assertTrue(got_timeout)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user