From f2626a8793575c291ed8d9edbb0b99778a964dfa Mon Sep 17 00:00:00 2001 From: =?utf8?q?Ville=20Skytt=C3=A4?= Date: Sat, 16 Sep 2017 00:08:07 +0300 Subject: [PATCH] Simplify Linux distro specific explicit timezone setting search --- babel/localtime/_unix.py | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/babel/localtime/_unix.py b/babel/localtime/_unix.py index 561de0d6..8f25fe7b 100644 --- a/babel/localtime/_unix.py +++ b/babel/localtime/_unix.py @@ -100,9 +100,7 @@ def _get_localzone(_root='/'): # OpenSUSE has a TIMEZONE setting in /etc/sysconfig/clock and # Gentoo has a TIMEZONE setting in /etc/conf.d/clock # We look through these files for a timezone: - zone_re = re.compile(r'\s*ZONE\s*=\s*"') - timezone_re = re.compile(r'\s*TIMEZONE\s*=\s*"') - end_re = re.compile(r'"') + timezone_re = re.compile(r'\s*(TIME)?ZONE\s*=\s*"(?P.+)"') for filename in ('etc/sysconfig/clock', 'etc/conf.d/clock'): tzpath = os.path.join(_root, filename) @@ -110,17 +108,10 @@ def _get_localzone(_root='/'): continue with open(tzpath, 'rt') as tzfile: for line in tzfile: - # Look for the ZONE= setting. - match = zone_re.match(line) - if match is None: - # No ZONE= setting. Look for the TIMEZONE= setting. - match = timezone_re.match(line) + match = timezone_re.match(line) if match is not None: - # Some setting existed - line = line[match.end():] - etctz = line[:end_re.search(line).start()] - # We found a timezone + etctz = match.group("etctz") return pytz.timezone(etctz.replace(' ', '_')) # No explicit setting existed. Use localtime -- 2.47.2