[Py3] Fix raise/except

This commit is contained in:
Raphaël Barrois 2013-11-13 00:18:45 +01:00 committed by Christian Heimes
parent 5b8236dc1c
commit cf7ec42f61
17 changed files with 31 additions and 31 deletions

View File

@ -15,7 +15,7 @@ class DeleteLeafs(ldap.async.AsyncSearchHandler):
def startSearch(self,searchRoot,searchScope):
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.deletedEntries = 0
ldap.async.AsyncSearchHandler.startSearch(
@ -45,7 +45,7 @@ class DeleteLeafs(ldap.async.AsyncSearchHandler):
else:
try:
self._l.delete_s(dn)
except ldap.NOT_ALLOWED_ON_NONLEAF,e:
except ldap.NOT_ALLOWED_ON_NONLEAF as e:
self.nonLeafEntries.append(dn)
else:
self.deletedEntries = self.deletedEntries+1

View File

@ -72,7 +72,7 @@ class PagedResultsSearchObject:
else:
break # no more pages available
except ldap.SERVER_DOWN,e:
except ldap.SERVER_DOWN as e:
try:
self.reconnect(self._uri)
except AttributeError:

View File

@ -16,7 +16,7 @@ import sys,ldap,ldapurl,getpass
try:
ldap_url = ldapurl.LDAPUrl(sys.argv[1])
request_ttl = int(sys.argv[2])
except IndexError,ValueError:
except (IndexError, ValueError):
print 'Usage: dds.py <LDAP URL> <TTL>'
sys.exit(1)
@ -38,7 +38,7 @@ if ldap_url.cred is None:
try:
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)
sys.exit(1)
@ -46,7 +46,7 @@ else:
extreq = RefreshRequest(entryName=ldap_url.dn,requestTtl=request_ttl)
try:
extop_resp_obj = ldap_conn.extop_s(extreq,extop_resp_class=RefreshResponse)
except ldap.LDAPError,e:
except ldap.LDAPError as e:
print str(e)
else:
if extop_resp_obj.responseTtl!=request_ttl:

View File

@ -42,7 +42,7 @@ if ldap_url.who and ldap_url.cred is None:
try:
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)
sys.exit(1)
@ -56,7 +56,7 @@ try:
serverctrls=[SearchNoOpControl(criticality=True)],
)
_,_,_,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)
sys.exit(1)

View File

@ -16,7 +16,7 @@ from ldap.controls.ppolicy import PasswordPolicyError,PasswordPolicyControl
try:
ldap_url = ldapurl.LDAPUrl(sys.argv[1])
except IndexError,ValueError:
except (IndexError,ValueError):
print 'Usage: ppolicy.py <LDAP URL>'
sys.exit(1)
@ -38,7 +38,7 @@ if ldap_url.cred is None:
try:
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)
except ldap.INVALID_CREDENTIALS,e:
except ldap.INVALID_CREDENTIALS as e:
print 'Simple bind failed:',str(e)
sys.exit(1)
else:

View File

@ -39,7 +39,7 @@ if ldap_url.cred is None:
try:
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)
sys.exit(1)

View File

@ -16,7 +16,7 @@ from ldap.controls.sessiontrack import SessionTrackingControl,SESSION_TRACKING_F
try:
ldap_url = ldapurl.LDAPUrl(sys.argv[1])
except IndexError,ValueError:
except (IndexError, ValueError):
print 'Usage: %s <LDAP URL>' % (sys.argv[0])
sys.exit(1)
@ -38,7 +38,7 @@ if ldap_url.who and ldap_url.cred is None:
try:
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)
sys.exit(1)

View File

@ -149,7 +149,7 @@ while watcher_running:
# Now we login to the LDAP server
try:
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)
sys.exit(1)
except ldap.SERVER_DOWN:
@ -174,7 +174,7 @@ while watcher_running:
# User asked to exit
commenceShutdown()
pass
except Exception, e:
except Exception as e:
# Handle any exception
if watcher_running:
print 'Encountered a problem, going to retry. Error:', str(e)

View File

@ -67,13 +67,13 @@ for ldap_uri,sasl_mech,sasl_cb_value_dict in [
l.protocol_version = 3
try:
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)
else:
print 'Sucessfully bound using SASL mechanism:',sasl_auth.mech
try:
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)
try:
print 'OPT_X_SASL_USERNAME',repr(l.get_option(ldap.OPT_X_SASL_USERNAME))

View File

@ -48,7 +48,7 @@ try:
('usage',range(2)),
]
)
except KeyError,e:
except KeyError as e:
print '***KeyError',str(e)

View File

@ -51,7 +51,7 @@ if subschemasubentry_dn is None:
try:
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]'
html_output = options and options[0][0]=='--html'

View File

@ -195,7 +195,7 @@ else:
self._oc_value = ''
# Unhandled tags
else:
raise ValueError,'Unknown tag %s' % (raw_name)
raise ValueError('Unknown tag %s' % (raw_name))
def endElement(self,raw_name):
assert raw_name.startswith('dsml:'),'Illegal name'
@ -230,7 +230,7 @@ else:
del self._oc_value
# Unhandled tags
else:
raise ValueError,'Unknown tag %s' % (raw_name)
raise ValueError('Unknown tag %s' % (raw_name))
def characters(self,ch):
if self.__dict__.has_key('_oc_value'):

View File

@ -145,9 +145,9 @@ def DecodeControlTuples(ldapControlTuples,knownLDAPControls=None):
control.controlType,control.criticality = controlType,criticality
try:
control.decodeControlValue(encodedControlValue)
except PyAsn1Error,e:
except PyAsn1Error:
if criticality:
raise e
raise
else:
result.append(control)
return result

View File

@ -65,7 +65,7 @@ def _ldap_function_call(lock,func,*args,**kwargs):
finally:
if lock:
lock.release()
except LDAPError,e:
except LDAPError as e:
if __debug__ and ldap._trace_level>=2:
ldap._trace_file.write('=> LDAPError: %s\n' % (str(e)))
raise

View File

@ -109,7 +109,7 @@ class SimpleLDAPObject:
diagnostic_message_success = self._l.get_option(ldap.OPT_DIAGNOSTIC_MESSAGE)
finally:
self._ldap_object_lock.release()
except LDAPError,e:
except LDAPError as e:
if __debug__ and self._trace_level>=2:
self._trace_file.write('=> LDAPError - %s: %s\n' % (e.__class__.__name__,str(e)))
raise
@ -132,9 +132,9 @@ class SimpleLDAPObject:
elif self.__dict__.has_key(name):
return self.__dict__[name]
else:
raise AttributeError,'%s has no attribute %s' % (
raise AttributeError('%s has no attribute %s' % (
self.__class__.__name__,repr(name)
)
))
def fileno():
"""
@ -863,14 +863,14 @@ class ReconnectLDAPObject(SimpleLDAPObject):
SimpleLDAPObject.start_tls_s(self)
# Repeat last simple or SASL 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:
self._trace_file.write('*** %s reconnect to %s failed\n' % (
counter_text,uri
))
reconnect_counter = reconnect_counter-1
if not reconnect_counter:
raise e
raise
if __debug__ and self._trace_level>=1:
self._trace_file.write('=> delay %s...\n' % (retry_delay))
time.sleep(retry_delay)

View File

@ -434,7 +434,7 @@ class SubSchema:
schema_attr_type = self.sed[AttributeType][a]
except 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
# but still KeyError is to be ignored we filter it away
del l[a]

View File

@ -211,7 +211,7 @@ class TestLdapCExtension(unittest.TestCase):
got_timeout = False
try:
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
self.assertTrue(got_timeout)