From 8b88caa110e83b42b1e43189c06b6cb3de712353 Mon Sep 17 00:00:00 2001 From: Petr Viktorin Date: Thu, 30 Jul 2015 17:03:06 +0200 Subject: [PATCH] Modernize function and method attribute names Python 3 uses double-underscored names for internal function attributes. In Python 2.7, these names exist as aliases to the old 'func_*' and 'im_*' names. Reviewed-By: Tomas Babej --- ipalib/parameters.py | 2 +- ipalib/plugins/dns.py | 2 +- ipalib/plugins/group.py | 2 +- ipalib/plugins/permission.py | 2 +- ipalib/plugins/pwpolicy.py | 2 +- ipatests/test_ipalib/test_frontend.py | 8 ++++---- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/ipalib/parameters.py b/ipalib/parameters.py index 7b27b70c2..94bd018ca 100644 --- a/ipalib/parameters.py +++ b/ipalib/parameters.py @@ -203,7 +203,7 @@ class DefaultFrom(ReadOnly): ) self.callback = callback if len(keys) == 0: - fc = callback.func_code + fc = callback.__code__ if fc.co_flags & 0x0c: raise ValueError("callback: variable-length argument list not allowed") self.keys = fc.co_varnames[:fc.co_argcount] diff --git a/ipalib/plugins/dns.py b/ipalib/plugins/dns.py index 4376d83ce..23871a58f 100644 --- a/ipalib/plugins/dns.py +++ b/ipalib/plugins/dns.py @@ -3682,7 +3682,7 @@ class dnsrecord_add(LDAPCreate): return dn def exc_callback(self, keys, options, exc, call_func, *call_args, **call_kwargs): - if call_func.func_name == 'add_entry': + if call_func.__name__ == 'add_entry': if isinstance(exc, errors.DuplicateEntry): # A new record is being added to existing LDAP DNS object # Update can be safely run as old record values has been diff --git a/ipalib/plugins/group.py b/ipalib/plugins/group.py index 381693cf1..18ae6dc36 100644 --- a/ipalib/plugins/group.py +++ b/ipalib/plugins/group.py @@ -397,7 +397,7 @@ class group_mod(LDAPUpdate): def exc_callback(self, keys, options, exc, call_func, *call_args, **call_kwargs): # Check again for GID requirement in case someone tried to clear it # using --setattr. - if call_func.func_name == 'update_entry': + if call_func.__name__ == 'update_entry': if isinstance(exc, errors.ObjectclassViolation): if 'gidNumber' in exc.message and 'posixGroup' in exc.message: raise errors.RequirementError(name='gid') diff --git a/ipalib/plugins/permission.py b/ipalib/plugins/permission.py index 1c636d8c0..012b78fcc 100644 --- a/ipalib/plugins/permission.py +++ b/ipalib/plugins/permission.py @@ -1194,7 +1194,7 @@ class permission_mod(baseldap.LDAPUpdate): return dn def exc_callback(self, keys, options, exc, call_func, *call_args, **call_kwargs): - if call_func.func_name == 'update_entry': + if call_func.__name__ == 'update_entry': self._revert_aci() raise exc diff --git a/ipalib/plugins/pwpolicy.py b/ipalib/plugins/pwpolicy.py index cb8ef29ee..4425a921a 100644 --- a/ipalib/plugins/pwpolicy.py +++ b/ipalib/plugins/pwpolicy.py @@ -506,7 +506,7 @@ class pwpolicy_mod(LDAPUpdate): return dn def exc_callback(self, keys, options, exc, call_func, *call_args, **call_kwargs): - if call_func.func_name == 'update_entry': + if call_func.__name__ == 'update_entry': if isinstance(exc, errors.EmptyModlist): entry_attrs = call_args[0] cosupdate = getattr(context, 'cosupdate') diff --git a/ipatests/test_ipalib/test_frontend.py b/ipatests/test_ipalib/test_frontend.py index 3ca03c39b..76f500fe2 100644 --- a/ipatests/test_ipalib/test_frontend.py +++ b/ipatests/test_ipalib/test_frontend.py @@ -642,7 +642,7 @@ class test_Command(ClassChecker): (api, home) = create_test_api(in_server=True) api.finalize() o = my_cmd(api) - assert o.run.im_func is self.cls.run.im_func + assert o.run.__func__ is self.cls.run.__func__ out = o.run(*args, **kw) assert ('execute', args, kw) == out @@ -650,7 +650,7 @@ class test_Command(ClassChecker): (api, home) = create_test_api(in_server=False) api.finalize() o = my_cmd(api) - assert o.run.im_func is self.cls.run.im_func + assert o.run.__func__ is self.cls.run.__func__ assert ('forward', args, kw) == o.run(*args, **kw) def test_messages(self): @@ -682,14 +682,14 @@ class test_Command(ClassChecker): (api, home) = create_test_api(in_server=True) api.finalize() o = my_cmd(api) - assert o.run.im_func is self.cls.run.im_func + assert o.run.__func__ is self.cls.run.__func__ assert {'name': 'execute', 'messages': expected} == o.run(*args, **kw) # Test in non-server context (api, home) = create_test_api(in_server=False) api.finalize() o = my_cmd(api) - assert o.run.im_func is self.cls.run.im_func + assert o.run.__func__ is self.cls.run.__func__ assert {'name': 'forward', 'messages': expected} == o.run(*args, **kw) def test_validate_output_basic(self):