* [PATCH] sepolgen: Use key function in sort()
@ 2015-11-13 11:52 Petr Lautrbach
2015-11-13 15:46 ` Joshua Brindle
0 siblings, 1 reply; 2+ messages in thread
From: Petr Lautrbach @ 2015-11-13 11:52 UTC (permalink / raw)
To: selinux
In Py3.0, the cmp parameter in sort() function was removed and key keyword is
available since Py2.4.
Fixes: # cat avc.log | audit2allow -R
Traceback (most recent call last):
File "/usr/bin/audit2allow", line 363, in <module>
app.main()
File "/usr/bin/audit2allow", line 351, in main
self.__output()
File "/usr/bin/audit2allow", line 308, in __output
g.set_gen_refpol(ifs, perm_maps)
File "/usr/lib64/python3.4/site-packages/sepolgen/policygen.py", line 101, in set_gen_refpol
self.ifgen = InterfaceGenerator(if_set, perm_maps)
File "/usr/lib64/python3.4/site-packages/sepolgen/policygen.py", line 353, in __init__
self.hack_check_ifs(ifs)
File "/usr/lib64/python3.4/site-packages/sepolgen/policygen.py", line 365, in hack_check_ifs
params.sort(param_comp)
TypeError: must use keyword argument for key function
Signed-off-by: Petr Lautrbach <plautrba@redhat.com>
---
sepolgen/src/sepolgen/policygen.py | 9 ++-------
1 file changed, 2 insertions(+), 7 deletions(-)
diff --git a/sepolgen/src/sepolgen/policygen.py b/sepolgen/src/sepolgen/policygen.py
index 4438a11..34c8401 100644
--- a/sepolgen/src/sepolgen/policygen.py
+++ b/sepolgen/src/sepolgen/policygen.py
@@ -36,8 +36,6 @@ from . import access
from . import interfaces
from . import matching
from . import util
-if util.PY3:
- from .util import cmp
# Constants for the level of explanation from the generation
# routines
NO_EXPLANATION = 0
@@ -278,15 +276,12 @@ def explain_access(av, ml=None, verbosity=SHORT_EXPLANATION):
explain_interfaces()
return s
-def param_comp(a, b):
- return cmp(b.num, a.num)
-
def call_interface(interface, av):
params = []
args = []
params.extend(interface.params.values())
- params.sort(param_comp)
+ params.sort(key=lambda param: param.num, reverse=True)
ifcall = refpolicy.InterfaceCall()
ifcall.ifname = interface.name
@@ -321,7 +316,7 @@ class InterfaceGenerator:
for x in ifs.interfaces.values():
params = []
params.extend(x.params.values())
- params.sort(param_comp)
+ params.sort(key=lambda param: param.num, reverse=True)
for i in range(len(params)):
# Check that the paramater position matches
# the number (e.g., $1 is the first arg). This
--
2.6.2
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] sepolgen: Use key function in sort()
2015-11-13 11:52 [PATCH] sepolgen: Use key function in sort() Petr Lautrbach
@ 2015-11-13 15:46 ` Joshua Brindle
0 siblings, 0 replies; 2+ messages in thread
From: Joshua Brindle @ 2015-11-13 15:46 UTC (permalink / raw)
To: Petr Lautrbach; +Cc: selinux
Petr Lautrbach wrote:
> In Py3.0, the cmp parameter in sort() function was removed and key keyword is
> available since Py2.4.
>
> Fixes: # cat avc.log | audit2allow -R
> Traceback (most recent call last):
> File "/usr/bin/audit2allow", line 363, in<module>
> app.main()
> File "/usr/bin/audit2allow", line 351, in main
> self.__output()
> File "/usr/bin/audit2allow", line 308, in __output
> g.set_gen_refpol(ifs, perm_maps)
> File "/usr/lib64/python3.4/site-packages/sepolgen/policygen.py", line 101, in set_gen_refpol
> self.ifgen = InterfaceGenerator(if_set, perm_maps)
> File "/usr/lib64/python3.4/site-packages/sepolgen/policygen.py", line 353, in __init__
> self.hack_check_ifs(ifs)
> File "/usr/lib64/python3.4/site-packages/sepolgen/policygen.py", line 365, in hack_check_ifs
> params.sort(param_comp)
> TypeError: must use keyword argument for key function
>
> Signed-off-by: Petr Lautrbach<plautrba@redhat.com>
Thanks, Applied.
> ---
> sepolgen/src/sepolgen/policygen.py | 9 ++-------
> 1 file changed, 2 insertions(+), 7 deletions(-)
>
> diff --git a/sepolgen/src/sepolgen/policygen.py b/sepolgen/src/sepolgen/policygen.py
> index 4438a11..34c8401 100644
> --- a/sepolgen/src/sepolgen/policygen.py
> +++ b/sepolgen/src/sepolgen/policygen.py
> @@ -36,8 +36,6 @@ from . import access
> from . import interfaces
> from . import matching
> from . import util
> -if util.PY3:
> - from .util import cmp
> # Constants for the level of explanation from the generation
> # routines
> NO_EXPLANATION = 0
> @@ -278,15 +276,12 @@ def explain_access(av, ml=None, verbosity=SHORT_EXPLANATION):
> explain_interfaces()
> return s
>
> -def param_comp(a, b):
> - return cmp(b.num, a.num)
> -
> def call_interface(interface, av):
> params = []
> args = []
>
> params.extend(interface.params.values())
> - params.sort(param_comp)
> + params.sort(key=lambda param: param.num, reverse=True)
>
> ifcall = refpolicy.InterfaceCall()
> ifcall.ifname = interface.name
> @@ -321,7 +316,7 @@ class InterfaceGenerator:
> for x in ifs.interfaces.values():
> params = []
> params.extend(x.params.values())
> - params.sort(param_comp)
> + params.sort(key=lambda param: param.num, reverse=True)
> for i in range(len(params)):
> # Check that the paramater position matches
> # the number (e.g., $1 is the first arg). This
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2015-11-13 15:46 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-11-13 11:52 [PATCH] sepolgen: Use key function in sort() Petr Lautrbach
2015-11-13 15:46 ` Joshua Brindle
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.