]> git.ipfire.org Git - thirdparty/babel.git/commitdiff
Simplify Linux distro specific explicit timezone setting search 528/head
authorVille Skyttä <ville.skytta@iki.fi>
Fri, 15 Sep 2017 21:08:07 +0000 (00:08 +0300)
committerVille Skyttä <ville.skytta@upcloud.com>
Sun, 17 Dec 2017 15:37:19 +0000 (17:37 +0200)
babel/localtime/_unix.py

index 561de0d6a30574f03f1fda317788e748b44626a9..8f25fe7b80497545087fea9d6014a8f49ff281b7 100644 (file)
@@ -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<etctz>.+)"')
 
     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