We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN 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]:
```

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `nikola/packages/tzlocal/unix.py`
Content:
```
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 FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

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

{"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"}], "after_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                tested_tz = dateutil.tz.gettz(tzpath)\n                if tested_tz:\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"}]}