Skip to contentSkip to conversation

sepolgen: add support for python3

PATCH In review Robert Kuska 3 participants 5 messages Jul 13, 2015 – Jul 15, 2015 1 message not in the archive SELinux security module

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

PATCH 1/1 sepolgen: add support for python3

Hello everyone,

this is my first mail to this mailing list so I would like to introduce myself a bit.

I am Robert Kuska, member of python-sig in Fedora and co-owner of change Python3 as default. In Fedora many packages depends on policycoreutils which ships python modules from selinux, the problem is (at least for us as we want to have default installation clean of Python2) that not all of them work with Python3. Therefore I've decided to make a patch(es) for all modules (except for GUI) to make them work with python3.

As a first I've picked a sepolgen as it seemed it will be the hardest. Please note that I have no previous experience with coding for selinux project.

You can find my patch as an attachment to this mail, as it is a rather big one (I didn't split the patch because it fixes mostly same syntax errors).

I have tested the patch with python2.7 and python3.4. I had no issue with python2.7 except for test_module.TestModuleCompiler.test which was failing even before my patch.

Following failures (number vary, from 1 to 6) were seen with python3.4:

https://paste.fedoraproject.org/243817/36795382/

The origin of these failures lies within change in hash function of sets and dicts, hash now uses random seed in python3 and tests rely on frozen order of items which is imho bad. I didn't fix those tests as I wanted to know firstly if this is just a issue with tests and such frozen order is not expected.

--
Robert Kuska
{rkuska}

From 103d5863af9199d12a15a7d69bc895708153f939 Mon Sep 17 00:00:00 2001
From: Robert Kuska <[email protected]>
Date: Mon, 13 Jul 2015 15:11:04 +0200
Subject: [PATCH] Sepolgen: Add Python3 support for module

This patch adds support for Python3 in sepolgen module. Apart from obvious fixes reported by 2to3 following issues were fixed:
* use rich comparisons instead of __cmp__
* when sorting use key function instead of cmp
* encode text before hashing

---
 sepolgen/src/sepolgen/access.py      |  57 ++++++----
 sepolgen/src/sepolgen/audit.py       |   6 +-
 sepolgen/src/sepolgen/classperms.py  |  10 +-
 sepolgen/src/sepolgen/defaults.py    |   4 +-
 sepolgen/src/sepolgen/interfaces.py  |  12 +--
 sepolgen/src/sepolgen/lex.py         | 158 +++++++++++++--------------
 sepolgen/src/sepolgen/matching.py    |  51 +++++----
 sepolgen/src/sepolgen/module.py      |  16 +--
 sepolgen/src/sepolgen/objectmodel.py |   2 +-
 sepolgen/src/sepolgen/output.py      |   4 +-
 sepolgen/src/sepolgen/policygen.py   |  17 +--
 sepolgen/src/sepolgen/refparser.py   |  26 ++---
 sepolgen/src/sepolgen/refpolicy.py   |  38 +++----
 sepolgen/src/sepolgen/util.py        |  12 +++
 sepolgen/src/sepolgen/yacc.py        | 203 +++++++++++++++++++----------------
 sepolgen/tests/test_access.py        |  41 ++++---
 sepolgen/tests/test_audit.py         | 108 +++++++++----------
 sepolgen/tests/test_interfaces.py    |  28 ++---
 sepolgen/tests/test_matching.py      |   8 +-
 sepolgen/tests/test_refpolicy.py     |  50 ++++-----
 20 files changed, 457 insertions(+), 394 deletions(-)
sepolgen/src/sepolgen/access.py +36 -21
index cf13210..03a54a4 100644
@@ -31,7 +31,8 @@ and sets of that access (AccessVectorSet). These objects are used in Madison
 in a variety of ways, but they are the fundamental representation of access.
 """
 
-import refpolicy
+from . import refpolicy
+
 from selinux import audit2why
 
 def is_idparam(id):
@@ -88,6 +89,7 @@ class AccessVector:
             self.audit_msgs = []
             self.type = audit2why.TERULE
             self.data = []
+        self.__hash__ = None
 
         # The direction of the information flow represented by this
         # access vector - used for matching
@@ -133,23 +135,36 @@ class AccessVector:
         return "allow %s %s:%s %s;" % (self.src_type, self.tgt_type,
                                         self.obj_class, self.perms.to_space_str())
 
-    def __cmp__(self, other):
-        if self.src_type != other.src_type:
-            return cmp(self.src_type, other.src_type)
-        if self.tgt_type != other.tgt_type:
-            return cmp(self.tgt_type, other.tgt_type)
-        if self.obj_class != self.obj_class:
-            return cmp(self.obj_class, other.obj_class)
-        if len(self.perms) != len(other.perms):
-            return cmp(len(self.perms), len(other.perms))
-        x = list(self.perms)
-        x.sort()
-        y = list(other.perms)
-        y.sort()
-        for pa, pb in zip(x, y):
-            if pa != pb:
-                return cmp(pa, pb)
-        return 0
+    def _compare(self, other, method):
+        try:
+            x = list(self.perms)
+            x.sort()
+            a = (self.src_type, self.tgt_type, self.obj_class, x)
+            y = list(other.perms)
+            y.sort()
+            b = (other.src_type, other.tgt_type, other.obj_class, y)
+            return method(a, b)
+        except (AttributeError, TypeError):
+            # trying to compare to foreign type
+            return NotImplemented
+
+    def __eq__(self, other):
+        return self._compare(other, lambda a, b: a == b)
+
+    def __lt__(self, other):
+        return self._compare(other, lambda a, b: a < b)
+
+    def __le__(self, other):
+        return self._compare(other, lambda a, b: a <= b)
+
+    def __ge__(self, other):
+        return self._compare(other, lambda a, b: a >= b)
+
+    def __gt__(self, other):
+        return self._compare(other, lambda a, b: a > b)
+
+    def __ne__(self, other):
+        return self._compare(other, lambda a, b: a != b)
 
 def avrule_to_access_vectors(avrule):
     """Convert an avrule into a list of access vectors.
@@ -262,7 +277,7 @@ class AccessVectorSet:
         tgt = self.src.setdefault(src_type, { })
         cls = tgt.setdefault(tgt_type, { })
         
-        if cls.has_key((obj_class, avc_type)):
+        if (obj_class, avc_type) in cls:
             access = cls[obj_class, avc_type]
         else:
             access = AccessVector()
@@ -293,7 +308,7 @@ def avs_extract_types(avs):
 def avs_extract_obj_perms(avs):
     perms = { }
     for av in avs:
-        if perms.has_key(av.obj_class):
+        if av.obj_class in perms:
             s = perms[av.obj_class]
         else:
             s = refpolicy.IdSet()
@@ -321,7 +336,7 @@ class RoleTypeSet:
         return len(self.role_types.keys())
 
     def add(self, role, type):
-        if self.role_types.has_key(role):
+        if role in self.role_types:
             role_type = self.role_types[role]
         else:
             role_type = refpolicy.RoleType()
sepolgen/src/sepolgen/audit.py +3 -3
index 56919be..83efac3 100644
@@ -17,11 +17,11 @@
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 #
 
-import refpolicy
-import access
 import re
 import sys
 
+from . import refpolicy
+from . import access
 # Convenience functions
 
 def get_audit_boot_msgs():
@@ -430,7 +430,7 @@ class AuditParser:
 
         # Group by audit header
         if msg.header != "":
-            if self.by_header.has_key(msg.header):
+            if msg.header in self.by_header:
                 self.by_header[msg.header].append(msg)
             else:
                 self.by_header[msg.header] = [msg]
sepolgen/src/sepolgen/classperms.py +5 -5
index c925dee..f4fd899 100644
@@ -49,10 +49,10 @@ def t_NAME(t):
     return t
 
 def t_error(t):
-    print "Illegal character '%s'" % t.value[0]
+    print("Illegal character '%s'" % t.value[0])
     t.skip(1)
 
-import lex
+from . import lex
 lex.lex()
 
 def p_statements(p):
@@ -90,9 +90,9 @@ def p_names(p):
         p[0] = [p[1]] + p[2]
 
 def p_error(p):
-    print "Syntax error on line %d %s [type=%s]" % (p.lineno, p.value, p.type)
+    print("Syntax error on line %d %s [type=%s]" % (p.lineno, p.value, p.type))
     
-import yacc
+from . import yacc
 yacc.yacc()
 
 
@@ -112,5 +112,5 @@ test2 = """define(`all_filesystem_perms',`{ mount remount unmount getattr relabe
 define(`all_security_perms',`{ compute_av compute_create compute_member check_context load_policy compute_relabel compute_user setenforce setbool setsecparam setcheckreqprot }')
 """
 result = yacc.parse(txt)
-print result
+print(result)
     
sepolgen/src/sepolgen/defaults.py +2 -2
index 218bc7c..9591063 100644
@@ -36,14 +36,14 @@ class PathChoooser(object):
             if ignore.match(line): continue
             mo = consider.match(line)
             if not mo:
-                raise ValueError, "%s:%d: line is not in key = value format" % (pathname, lineno+1)
+                raise ValueError("%s:%d: line is not in key = value format" % (pathname, lineno+1))
             self.config[mo.group(1)] = mo.group(2)
 
     # We're only exporting one useful function, so why not be a function
     def __call__(self, testfilename, pathset="SELINUX_DEVEL_PATH"):
         paths = self.config.get(pathset, None)
         if paths is None:
-            raise ValueError, "%s was not in %s" % (pathset, self.config_pathname)
+            raise ValueError("%s was not in %s" % (pathset, self.config_pathname))
         paths = paths.split(":")
         for p in paths:
             target = os.path.join(p, testfilename)
sepolgen/src/sepolgen/interfaces.py +6 -6
index 88a6dc3..d34f562 100644
@@ -21,13 +21,13 @@
 Classes for representing and manipulating interfaces.
 """
 
-import access
-import refpolicy
 import itertools
-import objectmodel
-import matching
 
-from sepolgeni18n import _
+from . import access
+from . import refpolicy
+from . import objectmodel
+from . import matching
+from .sepolgeni18n import _
 
 import copy
 
@@ -276,7 +276,7 @@ class InterfaceVector:
         if attributes:
             for typeattribute in interface.typeattributes():
                 for attr in typeattribute.attributes:
-                    if not attributes.attributes.has_key(attr):
+                    if attr not in attributes.attributes:
                         # print "missing attribute " + attr
                         continue
                     attr_vec = attributes.attributes[attr]
sepolgen/src/sepolgen/lex.py +80 -78

415 lines not on this page · raw message

sepolgen/src/sepolgen/matching.py +32 -19

65 lines not on this page · raw message

sepolgen/src/sepolgen/module.py +10 -6
index 7fc9443..d5b3f75 100644
@@ -22,18 +22,22 @@ Utilities for dealing with the compilation of modules and creation
 of module tress.
 """
 
-import defaults
-
-import selinux
-
 import re
 import tempfile
-import commands
+try:
+    from subprocess import getstatusoutput
+except ImportError:
+    from commands import getstatusoutput
 import os
 import os.path
 import subprocess
 import shutil
 
+import selinux
+
+from . import defaults
+
+
 def is_valid_name(modname):
     """Check that a module name is valid.
     """
@@ -130,7 +134,7 @@ class ModuleCompiler:
 
     def run(self, command):
         self.o(command)
-        rc, output = commands.getstatusoutput(command)
+        rc, output = getstatusoutput(command)
         self.o(output)
         
         return rc
sepolgen/src/sepolgen/objectmodel.py +1 -1
index 88c8a1f..d05d721 100644
@@ -118,7 +118,7 @@ class PermMappings:
                 continue
             if fields[0] == "class":
                 c = fields[1]
-                if self.classes.has_key(c):
+                if c in self.classes:
                     raise ValueError("duplicate class in perm map")
                 self.classes[c] = { }
                 cur = self.classes[c]
sepolgen/src/sepolgen/output.py +2 -2
index 739452d..4244a74 100644
@@ -27,8 +27,8 @@ generating policy. This keeps the semantic / syntactic issues
 cleanly separated from the formatting issues.
 """
 
-import refpolicy
-import util
+from . import refpolicy
+from . import util
 
 class ModuleWriter:
     def __init__(self):
sepolgen/src/sepolgen/policygen.py +9 -8
index 5f38577..9203f6d 100644
@@ -24,17 +24,18 @@ classes and algorithms for the generation of SELinux policy.
 import itertools
 import textwrap
 
-import refpolicy
-import objectmodel
-import access
-import interfaces
-import matching
 import selinux.audit2why as audit2why
 try:
     from setools import *
 except:
     pass
 
+from . import refpolicy
+from . import objectmodel
+from . import access
+from . import interfaces
+from . import matching
+
 # Constants for the level of explanation from the generation
 # routines
 NO_EXPLANATION    = 0
@@ -167,7 +168,7 @@ class PolicyGenerator:
 
             if av.type == audit2why.BOOLEAN:
                 if len(av.data) > 1:
-                    rule.comment += "\n#!!!! This avc can be allowed using one of the these booleans:\n#     %s" % ", ".join(map(lambda x: x[0], av.data))
+                    rule.comment += "\n#!!!! This avc can be allowed using one of the these booleans:\n#     %s" % ", ".join([x[0] for x in av.data])
                 else:
                     rule.comment += "\n#!!!! This avc can be allowed using the boolean '%s'" % av.data[0][0]
 
@@ -186,7 +187,7 @@ class PolicyGenerator:
                         self.domains = seinfo(ATTRIBUTE, name="domain")[0]["types"]
                     types=[]
 
-                    for i in map(lambda x: x[TCONTEXT], sesearch([ALLOW], {SCONTEXT: av.src_type, CLASS: av.obj_class, PERMS: av.perms})):
+                    for i in [x[TCONTEXT] for x in sesearch([ALLOW], {SCONTEXT: av.src_type, CLASS: av.obj_class, PERMS: av.perms})]:
                         if i not in self.domains:
                             types.append(i)
                     if len(types) == 1:
@@ -296,7 +297,7 @@ def call_interface(interface, av):
         elif params[i].type == refpolicy.OBJ_CLASS:
             ifcall.args.append(av.obj_class)
         else:
-            print params[i].type
+            print(params[i].type)
             assert(0)
 
     assert(len(ifcall.args) > 0)
sepolgen/src/sepolgen/refparser.py +13 -13
index 83542d3..7589e49 100644
@@ -34,12 +34,12 @@ import os
 import re
 import traceback
 
-import refpolicy
-import access
-import defaults
+from . import refpolicy
+from . import access
+from . import defaults
 
-import lex
-import yacc
+from . import lex
+from . import yacc
 
 # :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 #
@@ -269,7 +269,7 @@ def t_comment(t):
     t.lexer.lineno += 1
 
 def t_error(t):
-    print "Illegal character '%s'" % t.value[0]
+    print("Illegal character '%s'" % t.value[0])
     t.skip(1)
 
 def t_newline(t):
@@ -311,7 +311,7 @@ def collect(stmts, parent, val=None):
 
 def expand(ids, s):
     for id in ids:
-        if spt.has_key(id):
+        if id in spt:
             s.update(spt.by_name(id))
         else:
             s.add(id)
@@ -971,7 +971,7 @@ def p_optional_semi(p):
 def p_error(tok):
     global error, parse_file, success, parser
     error = "%s: Syntax error on line %d %s [type=%s]" % (parse_file, tok.lineno, tok.value, tok.type)
-    print error
+    print(error)
     success = False
 
 def prep_spt(spt):
@@ -1008,7 +1008,7 @@ def parse(text, module=None, support=None, debug=False):
 
     try:
         parser.parse(text, debug=debug, lexer=lexer)
-    except Exception, e:
+    except Exception as e:
         parser = None
         lexer = None
         error = "internal parser error: %s" % str(e) + "\n" + traceback.format_exc()
@@ -1041,7 +1041,7 @@ def list_headers(root):
 
 
 def parse_headers(root, output=None, expand=True, debug=False):
-    import util
+    from . import util
 
     headers = refpolicy.Headers()
 
@@ -1075,9 +1075,9 @@ def parse_headers(root, output=None, expand=True, debug=False):
             fd.close()
             parse_file = f
             parse(txt, module, spt, debug)
-        except IOError, e:
+        except IOError as e:
             return
-        except ValueError, e:
+        except ValueError as e:
             raise ValueError("error parsing file %s: %s" % (f, str(e)))
 
     spt = None
@@ -1113,7 +1113,7 @@ def parse_headers(root, output=None, expand=True, debug=False):
                 parse_file(x[1], m, spt)
             else:
                 parse_file(x[1], m)
-        except ValueError, e:
+        except ValueError as e:
             o(str(e) + "\n")
             failures.append(x[1])
             continue
sepolgen/src/sepolgen/refpolicy.py +19 -19
index b8ed5c1..4bdba13 100644
@@ -85,53 +85,53 @@ class Node(PolicyBase):
     # Top level nodes
 
     def nodes(self):
-        return itertools.ifilter(lambda x: isinstance(x, Node), walktree(self))
+        return filter(lambda x: isinstance(x, Node), walktree(self))
 
     def modules(self):
-        return itertools.ifilter(lambda x: isinstance(x, Module), walktree(self))
+        return filter(lambda x: isinstance(x, Module), walktree(self))
 
     def interfaces(self):
-        return itertools.ifilter(lambda x: isinstance(x, Interface), walktree(self))
+        return filter(lambda x: isinstance(x, Interface), walktree(self))
 
     def templates(self):
-        return itertools.ifilter(lambda x: isinstance(x, Template), walktree(self))
+        return filter(lambda x: isinstance(x, Template), walktree(self))
 
     def support_macros(self):
-        return itertools.ifilter(lambda x: isinstance(x, SupportMacros), walktree(self))
+        return filter(lambda x: isinstance(x, SupportMacros), walktree(self))
 
     # Common policy statements
 
     def module_declarations(self):
-        return itertools.ifilter(lambda x: isinstance(x, ModuleDeclaration), walktree(self))
+        return filter(lambda x: isinstance(x, ModuleDeclaration), walktree(self))
 
     def interface_calls(self):
-        return itertools.ifilter(lambda x: isinstance(x, InterfaceCall), walktree(self))
+        return filter(lambda x: isinstance(x, InterfaceCall), walktree(self))
 
     def avrules(self):
-        return itertools.ifilter(lambda x: isinstance(x, AVRule), walktree(self))
+        return filter(lambda x: isinstance(x, AVRule), walktree(self))
 
     def typerules(self):
-        return itertools.ifilter(lambda x: isinstance(x, TypeRule), walktree(self))
+        return filter(lambda x: isinstance(x, TypeRule), walktree(self))
 
     def typeattributes(self):
         """Iterate over all of the TypeAttribute children of this Interface."""
-        return itertools.ifilter(lambda x: isinstance(x, TypeAttribute), walktree(self))
+        return filter(lambda x: isinstance(x, TypeAttribute), walktree(self))
 
     def roleattributes(self):
         """Iterate over all of the RoleAttribute children of this Interface."""
-        return itertools.ifilter(lambda x: isinstance(x, RoleAttribute), walktree(self))
+        return filter(lambda x: isinstance(x, RoleAttribute), walktree(self))
 
     def requires(self):
-        return itertools.ifilter(lambda x: isinstance(x, Require), walktree(self))
+        return filter(lambda x: isinstance(x, Require), walktree(self))
 
     def roles(self):
-        return itertools.ifilter(lambda x: isinstance(x, Role), walktree(self))
+        return filter(lambda x: isinstance(x, Role), walktree(self))
 
     def role_allows(self):
-        return itertools.ifilter(lambda x: isinstance(x, RoleAllow), walktree(self))
+        return filter(lambda x: isinstance(x, RoleAllow), walktree(self))
 
     def role_types(self):
-        return itertools.ifilter(lambda x: isinstance(x, RoleType), walktree(self))
+        return filter(lambda x: isinstance(x, RoleType), walktree(self))
 
     def __str__(self):
         if self.comment:
@@ -291,7 +291,7 @@ class SecurityContext(Leaf):
         self.type = fields[2]
         if len(fields) > 3:
             # FUTURE - normalize level fields to allow more comparisons to succeed.
-            self.level = string.join(fields[3:], ':')
+            self.level = ':'.join(fields[3:])
         else:
             self.level = None
 
@@ -703,7 +703,7 @@ def print_tree(head):
         s = ""
         for i in range(depth):
             s = s + "\t"
-        print s + str(node)
+        print(s + str(node))
 
 
 class Headers(Node):
@@ -810,7 +810,7 @@ class SupportMacros(Node):
         # are ordered correctly so that no macro is used before
         # it is defined
         s = set()
-        if self.map.has_key(perm):
+        if perm in self.map:
             for p in self.by_name(perm):
                 s.update(self.__expand_perm(p))
         else:
@@ -833,7 +833,7 @@ class SupportMacros(Node):
     def has_key(self, name):
         if not self.map:
             self.__gen_map()
-        return self.map.has_key(name)
+        return name in self.map
 
 class Require(Leaf):
     def __init__(self, parent=None):
sepolgen/src/sepolgen/util.py +12 -0
index 74a11f5..0ab3e3f 100644
@@ -16,6 +16,18 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 #
+import sys
+
+
+PY2 = sys.version_info[0] == 2
+PY3 = sys.version_info[0] == 3
+
+if PY2:
+    bytes_type=str
+    string_type=unicode
+else:
+    bytes_type=bytes
+    string_type=str
 
 class ConsoleProgressBar:
     def __init__(self, out, steps=100, indicator='#'):
sepolgen/src/sepolgen/yacc.py +111 -92

592 lines not on this page · raw message

sepolgen/tests/test_access.py +19 -22

110 lines not on this page · raw message

sepolgen/tests/test_audit.py +54 -54

164 lines not on this page · raw message

sepolgen/tests/test_interfaces.py +14 -14
index b589bdf..a10ce2d 100644
@@ -202,11 +202,11 @@ class TestInterfaceSet(unittest.TestCase):
         i = interfaces.InterfaceSet()
         i.add_headers(h)
 
-        self.assertEquals(len(i.interfaces), 1)
+        self.assertEqual(len(i.interfaces), 1)
         for key, interface in i.interfaces.items():
-            self.assertEquals(key, interface.name)
-            self.assertEquals(key, "foo")
-            self.assertEquals(len(interface.access), 2)
+            self.assertEqual(key, interface.name)
+            self.assertEqual(key, "foo")
+            self.assertEqual(len(interface.access), 2)
 
             # Check the access vectors
             comp_avs = [["$1", "usr_t", "dir", "create", "add_name"],
@@ -215,21 +215,21 @@ class TestInterfaceSet(unittest.TestCase):
             self.assertTrue(ret)
 
             # Check the params
-            self.assertEquals(len(interface.params), 1)
+            self.assertEqual(len(interface.params), 1)
             for param in interface.params.values():
-                self.assertEquals(param.type, refpolicy.SRC_TYPE)
-                self.assertEquals(param.name, "$1")
-                self.assertEquals(param.num, 1)
-                self.assertEquals(param.required, True)
+                self.assertEqual(param.type, refpolicy.SRC_TYPE)
+                self.assertEqual(param.name, "$1")
+                self.assertEqual(param.num, 1)
+                self.assertEqual(param.required, True)
 
     def test_expansion(self):
         h = refparser.parse(test_expansion)
         i = interfaces.InterfaceSet()
         i.add_headers(h)
 
-        self.assertEquals(len(i.interfaces), 3)
+        self.assertEqual(len(i.interfaces), 3)
         for key, interface in i.interfaces.items():
-            self.assertEquals(key, interface.name)
+            self.assertEqual(key, interface.name)
             if key == "foo":
                 comp_avs = [["$1", "usr_t", "dir", "create", "add_name"],
                             ["$1", "usr_t", "file", "read", "write"]]
@@ -277,6 +277,6 @@ class TestInterfaceSet(unittest.TestCase):
             if ifv.name == "files_exec_usr_files":
                 if_status[2] = True
 
-        self.assertEquals(if_status[0], True)
-        self.assertEquals(if_status[1], True)
-        self.assertEquals(if_status[2], True)
+        self.assertEqual(if_status[0], True)
+        self.assertEqual(if_status[1], True)
+        self.assertEqual(if_status[2], True)
sepolgen/tests/test_matching.py +4 -4
index 161e001..4a85e68 100644
@@ -35,13 +35,13 @@ class TestMatch(unittest.TestCase):
 
         self.assertEquals(a, b)
         b.info_dir_change = False
-        self.assertEquals(cmp(a, b), 1)
-        self.assertEquals(cmp(b, a), -1)
+        self.assertTrue((a > b))
+        self.assertTrue((b < a))
 
         b.dist = 200
 
-        self.assertEquals(cmp(a, b), -1)
-        self.assertEquals(cmp(b, a), 1)
+        self.assertTrue((a < b))
+        self.assertTrue((b > a))
 
 class TestMatchList(unittest.TestCase):
     def test_append(self):
sepolgen/tests/test_refpolicy.py +25 -25

111 lines not on this page · raw message

Signature · 1 line
2.4.3
#2 lore raw
Quoted 17 lines · Robert Kuska

Hello everyone,

this is my first mail to this mailing list so I would like to introduce myself a bit.

I am Robert Kuska, member of python-sig in Fedora and co-owner of change Python3 as default. In Fedora many packages depends on policycoreutils which ships python modules from selinux, the problem is (at least for us as we want to have default installation clean of Python2) that not all of them work with Python3. Therefore I've decided to make a patch(es) for all modules (except for GUI) to make them work with python3.

As a first I've picked a sepolgen as it seemed it will be the hardest. Please note that I have no previous experience with coding for selinux project.

Quoted 7 lines

You can find my patch as an attachment to this mail, as it is a rather big one (I didn't split the patch because it fixes mostly same syntax errors).

I have tested the patch with python2.7 and python3.4. I had no issue with python2.7 except for test_module.TestModuleCompiler.test which was failing even before my patch.

Do you have selinux-policy-devel installed?

Quoted 10 lines

Following failures (number vary, from 1 to 6) were seen with python3.4:

https://paste.fedoraproject.org/243817/36795382/

The origin of these failures lies within change in hash function of sets and dicts, hash now uses random seed in python3 and tests rely on frozen order of items which is imho bad. I didn't fix those tests as I wanted to know firstly if this is just a issue with tests and such frozen order is not expected.

I didn't write sepolgen, but it is certainly the case that the order in which permissions or types are listed in a policy rule makes no difference to its semantics.

#3 lore raw

----- Original Message -----

Quoted 27 lines

From: "Stephen Smalley" <[email protected]>
To: "Robert Kuska" <[email protected]>, [email protected]
Sent: Monday, July 13, 2015 4:28:42 PM
Subject: Re: [PATCH] sepolgen: add support for python3

Quoted 21 lines · Robert Kuska

Hello everyone,

this is my first mail to this mailing list so I would like to introduce myself a bit.

I am Robert Kuska, member of python-sig in Fedora and co-owner of change Python3 as default. In Fedora many packages depends on policycoreutils which ships python modules from selinux, the problem is (at least for us as we want to have default installation clean of Python2) that not all of them work with Python3. Therefore I've decided to make a patch(es) for all modules (except for GUI) to make them work with python3.

As a first I've picked a sepolgen as it seemed it will be the hardest. Please note that I have no previous experience with coding for selinux project.

You can find my patch as an attachment to this mail, as it is a rather big one (I didn't split the patch because it fixes mostly same syntax errors).

Quoted 5 lines
Quoted 3 lines

I have tested the patch with python2.7 and python3.4. I had no issue with python2.7 except for test_module.TestModuleCompiler.test which was failing even before my patch.

Do you have selinux-policy-devel installed?

My bad, after installing the devel package all tests pass (on python2).

Thank you.

Quoted 12 lines
Quoted 11 lines

Following failures (number vary, from 1 to 6) were seen with python3.4:

https://paste.fedoraproject.org/243817/36795382/

The origin of these failures lies within change in hash function of sets and dicts, hash now uses random seed in python3 and tests rely on frozen order of items which is imho bad. I didn't fix those tests as I wanted to know firstly if this is just a issue with tests and such frozen order is not expected.

Quoted 3 lines

I didn't write sepolgen, but it is certainly the case that the order in which permissions or types are listed in a policy rule makes no difference to its semantics.

Jason Zaman said the same thing on irc, I just wanted to be sure, I can send another patch with fixed tests.

Quoted 3 lines

--
Robert Kuska
{rkuska}

#4 lore raw

----- Original Message -----

Quoted 58 lines

From: "Robert Kuska" <[email protected]>
To: "Stephen Smalley" <[email protected]>
Cc: [email protected]
Sent: Monday, July 13, 2015 8:34:23 PM
Subject: Re: [PATCH] sepolgen: add support for python3

----- Original Message -----

Quoted 27 lines

From: "Stephen Smalley" <[email protected]>
To: "Robert Kuska" <[email protected]>, [email protected]
Sent: Monday, July 13, 2015 4:28:42 PM
Subject: Re: [PATCH] sepolgen: add support for python3

Quoted 21 lines · Robert Kuska

Hello everyone,

this is my first mail to this mailing list so I would like to introduce myself a bit.

I am Robert Kuska, member of python-sig in Fedora and co-owner of change Python3 as default. In Fedora many packages depends on policycoreutils which ships python modules from selinux, the problem is (at least for us as we want to have default installation clean of Python2) that not all of them work with Python3. Therefore I've decided to make a patch(es) for all modules (except for GUI) to make them work with python3.

As a first I've picked a sepolgen as it seemed it will be the hardest. Please note that I have no previous experience with coding for selinux project.

You can find my patch as an attachment to this mail, as it is a rather big one (I didn't split the patch because it fixes mostly same syntax errors).

Quoted 5 lines
Quoted 3 lines

I have tested the patch with python2.7 and python3.4. I had no issue with python2.7 except for test_module.TestModuleCompiler.test which was failing even before my patch.

Do you have selinux-policy-devel installed?

My bad, after installing the devel package all tests pass (on python2).

Thank you.

Quoted 12 lines
Quoted 11 lines

Following failures (number vary, from 1 to 6) were seen with python3.4:

https://paste.fedoraproject.org/243817/36795382/

The origin of these failures lies within change in hash function of sets and dicts, hash now uses random seed in python3 and tests rely on frozen order of items which is imho bad. I didn't fix those tests as I wanted to know firstly if this is just a issue with tests and such frozen order is not expected.

Quoted 7 lines
Quoted 3 lines

I didn't write sepolgen, but it is certainly the case that the order in which permissions or types are listed in a policy rule makes no difference to its semantics.

Jason Zaman said the same thing on irc, I just wanted to be sure, I can send another patch with fixed tests.

I've managed to split patch into smaller (11) patches. As seems that the big one is not attracting any reviewers :-).

Should I create a new thread for each patch or can I continue within this one?

Quoted 6 lines
Quoted 3 lines
Quoted 10 lines

--
Robert Kuska
{rkuska}
_______________________________________________
Selinux mailing list
[email protected]
To unsubscribe, send email to [email protected]. To get help, send an email containing "help" to [email protected].

--
Robert Kuska
{rkuska}

#5 lore raw
Quoted 65 lines · Robert Kuska

----- Original Message -----

Quoted 62 lines

From: "Robert Kuska" <[email protected]>
To: "Stephen Smalley" <[email protected]>
Cc: [email protected]
Sent: Monday, July 13, 2015 8:34:23 PM
Subject: Re: [PATCH] sepolgen: add support for python3

----- Original Message -----

Quoted 27 lines

From: "Stephen Smalley" <[email protected]>
To: "Robert Kuska" <[email protected]>, [email protected]
Sent: Monday, July 13, 2015 4:28:42 PM
Subject: Re: [PATCH] sepolgen: add support for python3

Quoted 21 lines · Robert Kuska

Hello everyone,

this is my first mail to this mailing list so I would like to introduce myself a bit.

I am Robert Kuska, member of python-sig in Fedora and co-owner of change Python3 as default. In Fedora many packages depends on policycoreutils which ships python modules from selinux, the problem is (at least for us as we want to have default installation clean of Python2) that not all of them work with Python3. Therefore I've decided to make a patch(es) for all modules (except for GUI) to make them work with python3.

As a first I've picked a sepolgen as it seemed it will be the hardest. Please note that I have no previous experience with coding for selinux project.

You can find my patch as an attachment to this mail, as it is a rather big one (I didn't split the patch because it fixes mostly same syntax errors).

Quoted 5 lines
Quoted 3 lines

I have tested the patch with python2.7 and python3.4. I had no issue with python2.7 except for test_module.TestModuleCompiler.test which was failing even before my patch.

Do you have selinux-policy-devel installed?

My bad, after installing the devel package all tests pass (on python2).

Thank you.

Quoted 15 lines
Quoted 11 lines

Following failures (number vary, from 1 to 6) were seen with python3.4:

https://paste.fedoraproject.org/243817/36795382/

The origin of these failures lies within change in hash function of sets and dicts, hash now uses random seed in python3 and tests rely on frozen order of items which is imho bad. I didn't fix those tests as I wanted to know firstly if this is just a issue with tests and such frozen order is not expected.

I didn't write sepolgen, but it is certainly the case that the order in which permissions or types are listed in a policy rule makes no difference to its semantics.

Quoted 8 lines
Quoted 3 lines

Jason Zaman said the same thing on irc, I just wanted to be sure, I can send another patch with fixed tests.

I've managed to split patch into smaller (11) patches. As seems that the big one is not attracting any reviewers :-).

Should I create a new thread for each patch or can I continue within this one?

Sending inline with git format-patch and git send-email is probably the best, it does it correctly.

-- Jason