From 88c95474ad6411ab59fd68a61831c0d1d3db5c68 Mon Sep 17 00:00:00 2001 From: Antoine Goutenoir Date: Tue, 12 May 2020 23:38:25 +0200 Subject: [PATCH] Improve perfs of friendly regex. --- flaskr/controllers/main_controller.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/flaskr/controllers/main_controller.py b/flaskr/controllers/main_controller.py index 8f37565..8d522d7 100644 --- a/flaskr/controllers/main_controller.py +++ b/flaskr/controllers/main_controller.py @@ -157,13 +157,15 @@ def gather_addresses(from_list, from_file): addresses = from_list.replace("\r", '').split("\n") clean_addresses = [] + # Ignore inevitable copy/paste bloopers + to_ignore = re.compile(r"City\s*,\s*Country", re.I & re.U) for address in addresses: if not address: continue if type(address).__name__ == 'str': address = unicode(address, 'utf-8') - if re.match(r"City\s*,\s*Country", address, re.I & re.U) is not None: - continue # ignore inevitable copy/paste bloopers + if to_ignore.match(address) is not None: + continue clean_addresses.append(address) addresses = clean_addresses -- libgit2 0.21.2