From cf7ec42f6152a3d51df9edefe80c0e35a3d0f768 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Barrois?= Date: Wed, 13 Nov 2013 00:18:45 +0100 Subject: [PATCH] [Py3] Fix raise/except --- Demo/Lib/ldap/async/deltree.py | 4 ++-- Demo/paged_search_ext_s.py | 2 +- Demo/pyasn1/dds.py | 6 +++--- Demo/pyasn1/noopsearch.py | 4 ++-- Demo/pyasn1/ppolicy.py | 4 ++-- Demo/pyasn1/psearch.py | 2 +- Demo/pyasn1/sessiontrack.py | 4 ++-- Demo/pyasn1/syncrepl.py | 4 ++-- Demo/sasl_bind.py | 4 ++-- Demo/schema.py | 2 +- Demo/schema_tree.py | 2 +- Lib/dsml.py | 4 ++-- Lib/ldap/controls/__init__.py | 4 ++-- Lib/ldap/functions.py | 2 +- Lib/ldap/ldapobject.py | 10 +++++----- Lib/ldap/schema/subentry.py | 2 +- Tests/t_cext.py | 2 +- 17 files changed, 31 insertions(+), 31 deletions(-) diff --git a/Demo/Lib/ldap/async/deltree.py b/Demo/Lib/ldap/async/deltree.py index 58df3b3..9d82c91 100644 --- a/Demo/Lib/ldap/async/deltree.py +++ b/Demo/Lib/ldap/async/deltree.py @@ -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 diff --git a/Demo/paged_search_ext_s.py b/Demo/paged_search_ext_s.py index d0e0982..2a9849f 100644 --- a/Demo/paged_search_ext_s.py +++ b/Demo/paged_search_ext_s.py @@ -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: diff --git a/Demo/pyasn1/dds.py b/Demo/pyasn1/dds.py index 656b439..e690d91 100644 --- a/Demo/pyasn1/dds.py +++ b/Demo/pyasn1/dds.py @@ -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 ' 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: diff --git a/Demo/pyasn1/noopsearch.py b/Demo/pyasn1/noopsearch.py index a22f394..87d7775 100644 --- a/Demo/pyasn1/noopsearch.py +++ b/Demo/pyasn1/noopsearch.py @@ -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) diff --git a/Demo/pyasn1/ppolicy.py b/Demo/pyasn1/ppolicy.py index 2bb24a2..948abbd 100644 --- a/Demo/pyasn1/ppolicy.py +++ b/Demo/pyasn1/ppolicy.py @@ -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 ' 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: diff --git a/Demo/pyasn1/psearch.py b/Demo/pyasn1/psearch.py index 86bdb37..b6c4031 100644 --- a/Demo/pyasn1/psearch.py +++ b/Demo/pyasn1/psearch.py @@ -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) diff --git a/Demo/pyasn1/sessiontrack.py b/Demo/pyasn1/sessiontrack.py index dd4797e..5a0238f 100644 --- a/Demo/pyasn1/sessiontrack.py +++ b/Demo/pyasn1/sessiontrack.py @@ -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 ' % (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) diff --git a/Demo/pyasn1/syncrepl.py b/Demo/pyasn1/syncrepl.py index c1185e6..a97bf5c 100644 --- a/Demo/pyasn1/syncrepl.py +++ b/Demo/pyasn1/syncrepl.py @@ -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) diff --git a/Demo/sasl_bind.py b/Demo/sasl_bind.py index 05af652..7416902 100644 --- a/Demo/sasl_bind.py +++ b/Demo/sasl_bind.py @@ -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)) diff --git a/Demo/schema.py b/Demo/schema.py index c8103f3..d6249f6 100644 --- a/Demo/schema.py +++ b/Demo/schema.py @@ -48,7 +48,7 @@ try: ('usage',range(2)), ] ) -except KeyError,e: +except KeyError as e: print '***KeyError',str(e) diff --git a/Demo/schema_tree.py b/Demo/schema_tree.py index 3b3a091..221a5b2 100644 --- a/Demo/schema_tree.py +++ b/Demo/schema_tree.py @@ -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' diff --git a/Lib/dsml.py b/Lib/dsml.py index 1cc3b2f..74cf04d 100644 --- a/Lib/dsml.py +++ b/Lib/dsml.py @@ -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'): diff --git a/Lib/ldap/controls/__init__.py b/Lib/ldap/controls/__init__.py index 214d92c..673a451 100644 --- a/Lib/ldap/controls/__init__.py +++ b/Lib/ldap/controls/__init__.py @@ -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 diff --git a/Lib/ldap/functions.py b/Lib/ldap/functions.py index 8ba0130..2a977a6 100644 --- a/Lib/ldap/functions.py +++ b/Lib/ldap/functions.py @@ -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 diff --git a/Lib/ldap/ldapobject.py b/Lib/ldap/ldapobject.py index f29d316..dd0947d 100644 --- a/Lib/ldap/ldapobject.py +++ b/Lib/ldap/ldapobject.py @@ -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) diff --git a/Lib/ldap/schema/subentry.py b/Lib/ldap/schema/subentry.py index 60fca93..24c72fa 100644 --- a/Lib/ldap/schema/subentry.py +++ b/Lib/ldap/schema/subentry.py @@ -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] diff --git a/Tests/t_cext.py b/Tests/t_cext.py index b6a2601..c49e97e 100644 --- a/Tests/t_cext.py +++ b/Tests/t_cext.py @@ -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)