From 78dbadab5756d8bda1a1d9b0ed4d4edf5e0762b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Sat, 2 Apr 2016 23:53:56 +0200 Subject: [PATCH] backup: minor: compile regex once --- qubes/backup.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/qubes/backup.py b/qubes/backup.py index 9cc938db..0b6160c4 100644 --- a/qubes/backup.py +++ b/qubes/backup.py @@ -58,6 +58,7 @@ HEADER_QUBES_XML_MAX_SIZE = 1024 * 1024 BLKSIZE = 512 +_re_alphanum = re.compile(r'^[A-Za-z0-9-]*$') class BackupCanceledError(qubes.exc.QubesException): def __init__(self, msg, tmpdir=None): @@ -109,12 +110,12 @@ class BackupHeader(object): if untrusted_line.count('=') != 1: raise qubes.exc.QubesException("Invalid backup header") (key, value) = untrusted_line.strip().split('=') - if not re.match(r"^[a-zA-Z0-9-]*$", key): + if not _re_alphanum.match(key): raise qubes.exc.QubesException("Invalid backup header (key)") if key not in self.header_keys.keys(): # Ignoring unknown option continue - if not re.match(r"^[a-zA-Z0-9-]*$", value): + if not _re_alphanum.match(value): raise qubes.exc.QubesException("Invalid backup header (value)") if getattr(self, self.header_keys[key]) is not None: raise qubes.exc.QubesException(