From: Ville Skyttä Date: Fri, 15 Sep 2017 21:08:07 +0000 (+0300) Subject: Simplify Linux distro specific explicit timezone setting search X-Git-Tag: v2.6.0~15^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F528%2Fhead;p=thirdparty%2Fbabel.git Simplify Linux distro specific explicit timezone setting search --- 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