[Freeipa-devel] [PATCH 007] Remove tuple unpacking from except clause
The patch replaces implicit tuple unpacking from except clauses with explicit unpacking of the exception objects' args attribute. Example: e = RuntimeError('num', 'messages') num, message = e num, message ('num', 'messages') e.args ('num', 'messages') num, message = e.args num, message ('num', 'messages') Christian From 6b57eb232641370f7d91febdc663bfcc62a795e7 Mon Sep 17 00:00:00 2001 From: Christian Heimes chei...@redhat.com Date: Mon, 13 Jul 2015 14:02:29 +0200 Subject: [PATCH] Remove tuple unpacking from except clause Python 3 doesn't support tuple unpacking in except clauses. All implicit tuple unpackings have been replaced with explicit unpacking of e.args. Signed-off-by: Christian Heimes chei...@redhat.com --- contrib/RHEL4/ipachangeconf.py| 4 ++-- ipa-client/ipaclient/ipachangeconf.py | 4 ++-- ipalib/plugins/hbactest.py| 7 --- ipaserver/dcerpc.py | 18 -- 4 files changed, 20 insertions(+), 13 deletions(-) diff --git a/contrib/RHEL4/ipachangeconf.py b/contrib/RHEL4/ipachangeconf.py index 1a361513558f20d65ac8cbb0044e7b8d352e6bad..87b306f5dff336f80b1d02909433253f148108a6 100644 --- a/contrib/RHEL4/ipachangeconf.py +++ b/contrib/RHEL4/ipachangeconf.py @@ -29,13 +29,13 @@ def openLocked(filename, perms): fd = os.open(filename, os.O_RDWR | os.O_CREAT, perms) fcntl.lockf(fd, fcntl.LOCK_EX) -except OSError, (errno, strerr): +except OSError as e: if fd != -1: try: os.close(fd) except OSError: pass -raise IOError(errno, strerr) +raise IOError(e.errno, e.strerror) return os.fdopen(fd, r+) diff --git a/ipa-client/ipaclient/ipachangeconf.py b/ipa-client/ipaclient/ipachangeconf.py index 15d41274f7a99550b0a49314fb949402e65ee1d1..edf34f5ae738eb22b8935c222392dc9b6f08638d 100644 --- a/ipa-client/ipaclient/ipachangeconf.py +++ b/ipa-client/ipaclient/ipachangeconf.py @@ -31,13 +31,13 @@ def openLocked(filename, perms): fd = os.open(filename, os.O_RDWR | os.O_CREAT, perms) fcntl.lockf(fd, fcntl.LOCK_EX) -except OSError, (errno, strerr): +except OSError as e: if fd != -1: try: os.close(fd) except OSError: pass -raise IOError(errno, strerr) +raise IOError(e.errno, e.strerror) return os.fdopen(fd, r+) diff --git a/ipalib/plugins/hbactest.py b/ipalib/plugins/hbactest.py index 068190310bf14d068620bc4a86d1c48ae1437251..c8dedd367e78cbe900b716369f8ef78575a21298 100644 --- a/ipalib/plugins/hbactest.py +++ b/ipalib/plugins/hbactest.py @@ -462,13 +462,14 @@ class hbactest(Command): matched_rules.append(ipa_rule.name) if res == pyhbac.HBAC_EVAL_DENY: notmatched_rules.append(ipa_rule.name) -except pyhbac.HbacError as (code, rule_name): +except pyhbac.HbacError as e: +code, rule_name = e.args if code == pyhbac.HBAC_EVAL_ERROR: error_rules.append(rule_name) self.log.info('Native IPA HBAC rule %s parsing error: %s' % \ (rule_name, pyhbac.hbac_result_string(code))) -except (TypeError, IOError) as (info): -self.log.error('Native IPA HBAC module error: %s' % (info)) +except (TypeError, IOError) as info: +self.log.error('Native IPA HBAC module error: %s' % info) access_granted = len(matched_rules) 0 else: diff --git a/ipaserver/dcerpc.py b/ipaserver/dcerpc.py index a1da0a641064f59a79639d97489ff73181787a4a..4de5afb540e880e8948749c2cfa9a019eb807c47 100644 --- a/ipaserver/dcerpc.py +++ b/ipaserver/dcerpc.py @@ -772,7 +772,8 @@ class TrustDomainInstance(object): try: result = lsa.lsarpc(binding, self.parm, self.creds) return result - except RuntimeError, (num, message): + except RuntimeError as e: + num, message = e.args raise assess_dcerpc_exception(num=num, message=message) def init_lsa_pipe(self, remote_host): @@ -889,7 +890,8 @@ class TrustDomainInstance(object): try: self._policy_handle = self._pipe.OpenPolicy2(u, objectAttribute, security.SEC_FLAG_MAXIMUM_ALLOWED) result = self._pipe.QueryInfoPolicy2(self._policy_handle, lsa.LSA_POLICY_INFO_DNS) -except RuntimeError, (num, message): +except RuntimeError as e: +num, message = e.args raise assess_dcerpc_exception(num=num, message=message) self.info['name'] = unicode(result.name.string) @@ -901,7 +903,8 @@ class TrustDomainInstance(object): try: result = self._pipe.QueryInfoPolicy2(self._policy_handle, lsa.LSA_POLICY_INFO_ROLE) -except RuntimeError,
Re: [Freeipa-devel] [PATCH 007] Remove tuple unpacking from except clause
On 07/13/2015 02:59 PM, Rob Crittenden wrote: Christian Heimes wrote: The patch replaces implicit tuple unpacking from except clauses with explicit unpacking of the exception objects' args attribute. Example: e = RuntimeError('num', 'messages') num, message = e num, message ('num', 'messages') e.args ('num', 'messages') num, message = e.args num, message ('num', 'messages') Not related to this patch directly but I think it would be a good idea to create a Python 3 tracking ticket to make it easy to find python 3-specific changes. Then create tickets to fix particular issues and link those with the tracking ticket. rob ACK Otherwise, I agree with Rob. Can you create an umbrella ticket? I will pushmark the commit there. Tomas -- Manage your subscription for the Freeipa-devel mailing list: https://www.redhat.com/mailman/listinfo/freeipa-devel Contribute to FreeIPA: http://www.freeipa.org/page/Contribute/Code
Re: [Freeipa-devel] [PATCH 007] Remove tuple unpacking from except clause
Christian Heimes wrote: The patch replaces implicit tuple unpacking from except clauses with explicit unpacking of the exception objects' args attribute. Example: e = RuntimeError('num', 'messages') num, message = e num, message ('num', 'messages') e.args ('num', 'messages') num, message = e.args num, message ('num', 'messages') Not related to this patch directly but I think it would be a good idea to create a Python 3 tracking ticket to make it easy to find python 3-specific changes. Then create tickets to fix particular issues and link those with the tracking ticket. rob -- Manage your subscription for the Freeipa-devel mailing list: https://www.redhat.com/mailman/listinfo/freeipa-devel Contribute to FreeIPA: http://www.freeipa.org/page/Contribute/Code
Re: [Freeipa-devel] [PATCH 007] Remove tuple unpacking from except clause
On 2015-07-13 15:21, Tomas Babej wrote: On 07/13/2015 02:59 PM, Rob Crittenden wrote: Christian Heimes wrote: The patch replaces implicit tuple unpacking from except clauses with explicit unpacking of the exception objects' args attribute. Example: e = RuntimeError('num', 'messages') num, message = e num, message ('num', 'messages') e.args ('num', 'messages') num, message = e.args num, message ('num', 'messages') Not related to this patch directly but I think it would be a good idea to create a Python 3 tracking ticket to make it easy to find python 3-specific changes. Then create tickets to fix particular issues and link those with the tracking ticket. rob ACK Otherwise, I agree with Rob. Can you create an umbrella ticket? I will pushmark the commit there. Sure, I'll create a meta ticket for Python 3 and a sub ticket for each task. Christian signature.asc Description: OpenPGP digital signature -- Manage your subscription for the Freeipa-devel mailing list: https://www.redhat.com/mailman/listinfo/freeipa-devel Contribute to FreeIPA: http://www.freeipa.org/page/Contribute/Code
Re: [Freeipa-devel] [PATCH 007] Remove tuple unpacking from except clause
On Mon, 13 Jul 2015, Tomas Babej wrote: On 07/13/2015 02:59 PM, Rob Crittenden wrote: Christian Heimes wrote: The patch replaces implicit tuple unpacking from except clauses with explicit unpacking of the exception objects' args attribute. Example: e = RuntimeError('num', 'messages') num, message = e num, message ('num', 'messages') e.args ('num', 'messages') num, message = e.args num, message ('num', 'messages') Not related to this patch directly but I think it would be a good idea to create a Python 3 tracking ticket to make it easy to find python 3-specific changes. Then create tickets to fix particular issues and link those with the tracking ticket. rob ACK Otherwise, I agree with Rob. Can you create an umbrella ticket? I will pushmark the commit there. Please do not push this specific version of the patch yet. Christian will do the changes with four separate commits as discussed on the IRC, to avoid future problems with maintenance and backports. -- / Alexander Bokovoy -- Manage your subscription for the Freeipa-devel mailing list: https://www.redhat.com/mailman/listinfo/freeipa-devel Contribute to FreeIPA: http://www.freeipa.org/page/Contribute/Code