prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  Incorrect time zone guessing on macOS
  On macOS Big Sur 11.2, we guess the full path to the zoneinfo file (instead of just the zone name).
  
  ```
  $ nikola init
  …
  Time zone [private/var/db/timezone/tz/2021a.1.0/zoneinfo/Europe/Warsaw]:
  ```
  
  </issue>
  <code>
  [start of nikola/packages/tzlocal/unix.py]
  1 """Unix support for tzlocal."""
  2 import os
  3 import re
  4 
  5 import dateutil.tz
  6 
  7 _cache_tz = None
  8 
  9 
  10 def _try_tz_from_env():
  11     tzenv = os.environ.get("TZ")
  12     if tzenv and tzenv[0] == ":":
  13         tzenv = tzenv[1:]
  14     try:
  15         if tzenv:
  16             dateutil.tz.gettz(tzenv)
  17             return tzenv
  18     except Exception:
  19         pass
  20 
  21 
  22 def _get_localzone(_root="/"):
  23     """Try to find the local timezone configuration.
  24 
  25     The parameter _root makes the function look for files like /etc/localtime
  26     beneath the _root directory. This is primarily used by the tests.
  27     In normal usage you call the function without parameters.
  28     """
  29     tzenv = _try_tz_from_env()
  30     if tzenv:
  31         return tzenv
  32 
  33     # Are we under Termux on Android?
  34     if os.path.exists("/system/bin/getprop"):
  35         import subprocess
  36 
  37         androidtz = (
  38             subprocess.check_output(["getprop", "persist.sys.timezone"])
  39             .strip()
  40             .decode()
  41         )
  42         return androidtz
  43 
  44     # Now look for distribution specific configuration files
  45     # that contain the timezone name.
  46     for configfile in ("etc/timezone", "var/db/zoneinfo"):
  47         tzpath = os.path.join(_root, configfile)
  48         try:
  49             with open(tzpath, "rb") as tzfile:
  50                 data = tzfile.read()
  51 
  52                 # Issue #3 was that /etc/timezone was a zoneinfo file.
  53                 # That's a misconfiguration, but we need to handle it gracefully:
  54                 if data[:5] == b"TZif2":
  55                     continue
  56 
  57                 etctz = data.strip().decode()
  58                 if not etctz:
  59                     # Empty file, skip
  60                     continue
  61                 for etctz in data.decode().splitlines():
  62                     # Get rid of host definitions and comments:
  63                     if " " in etctz:
  64                         etctz, dummy = etctz.split(" ", 1)
  65                     if "#" in etctz:
  66                         etctz, dummy = etctz.split("#", 1)
  67                     if not etctz:
  68                         continue
  69                     tz = etctz.replace(" ", "_")
  70                     return tz
  71 
  72         except IOError:
  73             # File doesn't exist or is a directory
  74             continue
  75 
  76     # CentOS has a ZONE setting in /etc/sysconfig/clock,
  77     # OpenSUSE has a TIMEZONE setting in /etc/sysconfig/clock and
  78     # Gentoo has a TIMEZONE setting in /etc/conf.d/clock
  79     # We look through these files for a timezone:
  80 
  81     zone_re = re.compile(r"\s*ZONE\s*=\s*\"")
  82     timezone_re = re.compile(r"\s*TIMEZONE\s*=\s*\"")
  83     end_re = re.compile('"')
  84 
  85     for filename in ("etc/sysconfig/clock", "etc/conf.d/clock"):
  86         tzpath = os.path.join(_root, filename)
  87         try:
  88             with open(tzpath, "rt") as tzfile:
  89                 data = tzfile.readlines()
  90 
  91             for line in data:
  92                 # Look for the ZONE= setting.
  93                 match = zone_re.match(line)
  94                 if match is None:
  95                     # No ZONE= setting. Look for the TIMEZONE= setting.
  96                     match = timezone_re.match(line)
  97                 if match is not None:
  98                     # Some setting existed
  99                     line = line[match.end():]
  100                     etctz = line[: end_re.search(line).start()]
  101 
  102                     # We found a timezone
  103                     tz = etctz.replace(" ", "_")
  104                     return tz
  105 
  106         except IOError:
  107             # File doesn't exist or is a directory
  108             continue
  109 
  110     # systemd distributions use symlinks that include the zone name,
  111     # see manpage of localtime(5) and timedatectl(1)
  112     tzpath = os.path.join(_root, "etc/localtime")
  113     if os.path.exists(tzpath) and os.path.islink(tzpath):
  114         tzpath = os.path.realpath(tzpath)
  115         start = tzpath.find("/") + 1
  116         while start != 0:
  117             tzpath = tzpath[start:]
  118             try:
  119                 dateutil.tz.gettz(tzpath)
  120                 return tzpath
  121             except Exception:
  122                 pass
  123             start = tzpath.find("/") + 1
  124 
  125     # Nothing found, return UTC
  126     return None
  127 
  128 
  129 def get_localzone():
  130     """Get the computers configured local timezone, if any."""
  131     global _cache_tz
  132     if _cache_tz is None:
  133         _cache_tz = _get_localzone()
  134 
  135     return _cache_tz
  136 
  137 
  138 def reload_localzone():
  139     """Reload the cached localzone. You need to call this if the timezone has changed."""
  140     global _cache_tz
  141     _cache_tz = _get_localzone()
  142     return _cache_tz
  143
  [end of nikola/packages/tzlocal/unix.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/nikola/packages/tzlocal/unix.py b/nikola/packages/tzlocal/unix.py
  --- a/nikola/packages/tzlocal/unix.py
  +++ b/nikola/packages/tzlocal/unix.py
  @@ -116,8 +116,9 @@
           while start != 0:
               tzpath = tzpath[start:]
               try:
  -                dateutil.tz.gettz(tzpath)
  -                return tzpath
  +                tested_tz = dateutil.tz.gettz(tzpath)
  +                if tested_tz:
  +                    return tzpath
               except Exception:
                   pass
               start = tzpath.find("/") + 1
  
verification_info: {"golden_diff": "diff --git a/nikola/packages/tzlocal/unix.py b/nikola/packages/tzlocal/unix.py\n--- a/nikola/packages/tzlocal/unix.py\n+++ b/nikola/packages/tzlocal/unix.py\n@@ -116,8 +116,9 @@\n         while start != 0:\n             tzpath = tzpath[start:]\n             try:\n-                dateutil.tz.gettz(tzpath)\n-                return tzpath\n+                tested_tz = dateutil.tz.gettz(tzpath)\n+                if tested_tz:\n+                    return tzpath\n             except Exception:\n                 pass\n             start = tzpath.find(\"/\") + 1\n", "issue": "Incorrect time zone guessing on macOS\nOn macOS Big Sur 11.2, we guess the full path to the zoneinfo file (instead of just the zone name).\r\n\r\n```\r\n$ nikola init\r\n\u2026\r\nTime zone [private/var/db/timezone/tz/2021a.1.0/zoneinfo/Europe/Warsaw]:\r\n```\n", "before_files": [{"content": "\"\"\"Unix support for tzlocal.\"\"\"\nimport os\nimport re\n\nimport dateutil.tz\n\n_cache_tz = None\n\n\ndef _try_tz_from_env():\n    tzenv = os.environ.get(\"TZ\")\n    if tzenv and tzenv[0] == \":\":\n        tzenv = tzenv[1:]\n    try:\n        if tzenv:\n            dateutil.tz.gettz(tzenv)\n            return tzenv\n    except Exception:\n        pass\n\n\ndef _get_localzone(_root=\"/\"):\n    \"\"\"Try to find the local timezone configuration.\n\n    The parameter _root makes the function look for files like /etc/localtime\n    beneath the _root directory. This is primarily used by the tests.\n    In normal usage you call the function without parameters.\n    \"\"\"\n    tzenv = _try_tz_from_env()\n    if tzenv:\n        return tzenv\n\n    # Are we under Termux on Android?\n    if os.path.exists(\"/system/bin/getprop\"):\n        import subprocess\n\n        androidtz = (\n            subprocess.check_output([\"getprop\", \"persist.sys.timezone\"])\n            .strip()\n            .decode()\n        )\n        return androidtz\n\n    # Now look for distribution specific configuration files\n    # that contain the timezone name.\n    for configfile in (\"etc/timezone\", \"var/db/zoneinfo\"):\n        tzpath = os.path.join(_root, configfile)\n        try:\n            with open(tzpath, \"rb\") as tzfile:\n                data = tzfile.read()\n\n                # Issue #3 was that /etc/timezone was a zoneinfo file.\n                # That's a misconfiguration, but we need to handle it gracefully:\n                if data[:5] == b\"TZif2\":\n                    continue\n\n                etctz = data.strip().decode()\n                if not etctz:\n                    # Empty file, skip\n                    continue\n                for etctz in data.decode().splitlines():\n                    # Get rid of host definitions and comments:\n                    if \" \" in etctz:\n                        etctz, dummy = etctz.split(\" \", 1)\n                    if \"#\" in etctz:\n                        etctz, dummy = etctz.split(\"#\", 1)\n                    if not etctz:\n                        continue\n                    tz = etctz.replace(\" \", \"_\")\n                    return tz\n\n        except IOError:\n            # File doesn't exist or is a directory\n            continue\n\n    # CentOS has a ZONE setting in /etc/sysconfig/clock,\n    # OpenSUSE has a TIMEZONE setting in /etc/sysconfig/clock and\n    # Gentoo has a TIMEZONE setting in /etc/conf.d/clock\n    # We look through these files for a timezone:\n\n    zone_re = re.compile(r\"\\s*ZONE\\s*=\\s*\\\"\")\n    timezone_re = re.compile(r\"\\s*TIMEZONE\\s*=\\s*\\\"\")\n    end_re = re.compile('\"')\n\n    for filename in (\"etc/sysconfig/clock\", \"etc/conf.d/clock\"):\n        tzpath = os.path.join(_root, filename)\n        try:\n            with open(tzpath, \"rt\") as tzfile:\n                data = tzfile.readlines()\n\n            for line in data:\n                # Look for the ZONE= setting.\n                match = zone_re.match(line)\n                if match is None:\n                    # No ZONE= setting. Look for the TIMEZONE= setting.\n                    match = timezone_re.match(line)\n                if match is not None:\n                    # Some setting existed\n                    line = line[match.end():]\n                    etctz = line[: end_re.search(line).start()]\n\n                    # We found a timezone\n                    tz = etctz.replace(\" \", \"_\")\n                    return tz\n\n        except IOError:\n            # File doesn't exist or is a directory\n            continue\n\n    # systemd distributions use symlinks that include the zone name,\n    # see manpage of localtime(5) and timedatectl(1)\n    tzpath = os.path.join(_root, \"etc/localtime\")\n    if os.path.exists(tzpath) and os.path.islink(tzpath):\n        tzpath = os.path.realpath(tzpath)\n        start = tzpath.find(\"/\") + 1\n        while start != 0:\n            tzpath = tzpath[start:]\n            try:\n                dateutil.tz.gettz(tzpath)\n                return tzpath\n            except Exception:\n                pass\n            start = tzpath.find(\"/\") + 1\n\n    # Nothing found, return UTC\n    return None\n\n\ndef get_localzone():\n    \"\"\"Get the computers configured local timezone, if any.\"\"\"\n    global _cache_tz\n    if _cache_tz is None:\n        _cache_tz = _get_localzone()\n\n    return _cache_tz\n\n\ndef reload_localzone():\n    \"\"\"Reload the cached localzone. You need to call this if the timezone has changed.\"\"\"\n    global _cache_tz\n    _cache_tz = _get_localzone()\n    return _cache_tz\n", "path": "nikola/packages/tzlocal/unix.py"}]}