From fba9d0103562c1435e4ab72753accf755f9729f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= Date: Thu, 9 Mar 2017 11:09:35 +0200 Subject: [PATCH] Python 3.6 invalid escape sequence deprecation fixes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://docs.python.org/3/whatsnew/3.6.html#deprecated-python-behavior A backslash-character pair that is not a valid escape sequence now generates a DeprecationWarning. Although this will eventually become a SyntaxError, that will not be for several Python releases. The problem appears when you use '-W error': $ python3 -W error -c 'import re; re.findall("[^a-zA-Z0-9_\-\.]", " *%$")' File "", line 1 SyntaxError: invalid escape sequence \- Signed-off-by: Ville Skyttä [ Edited commit message as per suggestion from Petr Lautrbach ] Signed-off-by: Stephen Smalley --- python/semanage/seobject.py | 4 ++-- python/sepolgen/src/sepolgen/module.py | 2 +- python/sepolicy/sepolicy/generate.py | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/python/semanage/seobject.py b/python/semanage/seobject.py index c836cc5a..94bd3687 100644 --- a/python/semanage/seobject.py +++ b/python/semanage/seobject.py @@ -192,8 +192,8 @@ class nulllogger: def validate_level(raw): sensitivity = "s[0-9]*" category = "c[0-9]*" - cat_range = category + "(\." + category + ")?" - categories = cat_range + "(\," + cat_range + ")*" + cat_range = category + r"(\." + category + ")?" + categories = cat_range + r"(\," + cat_range + ")*" reg = sensitivity + "(-" + sensitivity + ")?" + "(:" + categories + ")?" return re.search("^" + reg + "$", raw) diff --git a/python/sepolgen/src/sepolgen/module.py b/python/sepolgen/src/sepolgen/module.py index c09676aa..8766dd9d 100644 --- a/python/sepolgen/src/sepolgen/module.py +++ b/python/sepolgen/src/sepolgen/module.py @@ -40,7 +40,7 @@ from . import defaults def is_valid_name(modname): """Check that a module name is valid. """ - m = re.findall("[^a-zA-Z0-9_\-\.]", modname) + m = re.findall(r"[^a-zA-Z0-9_\-\.]", modname) if len(m) == 0 and modname[0].isalpha(): return True else: diff --git a/python/sepolicy/sepolicy/generate.py b/python/sepolicy/sepolicy/generate.py index 5696110c..596891a4 100644 --- a/python/sepolicy/sepolicy/generate.py +++ b/python/sepolicy/sepolicy/generate.py @@ -1329,7 +1329,7 @@ allow %s_t %s_t:%s_socket name_%s; self.add_dir("/var/lib/%s" % self.name) if os.path.isfile("/etc/rc.d/init.d/%s" % self.name): - self.set_init_script("/etc/rc\.d/init\.d/%s" % self.name) + self.set_init_script(r"/etc/rc\.d/init\.d/%s" % self.name) # we don't want to have subdir in the .fc policy file # if we already specify labeling for parent dir