From 79bcc04d0a72e3ad9fb57248d3a1f08a84982587 Mon Sep 17 00:00:00 2001 From: Valentin Lorentz Date: Wed, 14 Sep 2016 20:09:00 +0200 Subject: [PATCH] Fix Python 3.6 support of utils.python.glob2re. --- src/utils/python.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/utils/python.py b/src/utils/python.py index 4d28cae71..41fd004ad 100644 --- a/src/utils/python.py +++ b/src/utils/python.py @@ -108,11 +108,21 @@ class MetaSynchronized(type): return newclass Synchronized = MetaSynchronized('Synchronized', (), {}) -# Translate glob to regular expression, trimming the "match EOL" portion of -# the regular expression. -# Post-2.6 uses \Z(?ms) per http://issues.python.org/6665 def glob2re(g): - return fnmatch.translate(g)[:-7] + pattern = fnmatch.translate(g) + if pattern.startswith('(?s:') and pattern.endswith(')\\Z'): + # Python >= 3.6 + return pattern[4:-3] + '\\Z' + elif pattern.endswith('\\Z(?ms)'): + # Python >= 2.6 and < 3.6 + # + # Translate glob to regular expression, trimming the "match EOL" + # portion of the regular expression. + # Some Python versions use \Z(?ms) per + # https://bugs.python.org/issue6665 + return pattern[:-7] + else: + assert False, 'Python < 2.6, or unknown behavior of fnmatch.translate.' _debug_software_name = 'Limnoria'