-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathzoneinfo.patch
More file actions
103 lines (95 loc) · 3.5 KB
/
Copy pathzoneinfo.patch
File metadata and controls
103 lines (95 loc) · 3.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
--- pytz-2026.1.post1/pytz/__init__.py.orig 2026-03-03 08:47:27.000000000 +0100
+++ pytz-2026.1.post1/pytz/__init__.py 2026-04-24 15:50:33.000000000 +0200
@@ -75,12 +75,13 @@
return s.encode('ASCII')
+_tzinfo_dir = os.getenv("TZDIR") or "/usr/share/zoneinfo"
+if _tzinfo_dir.endswith(os.sep):
+ _tzinfo_dir = _tzinfo_dir[:-1]
+
def open_resource(name):
"""Open a resource from the zoneinfo subdir for reading.
- Uses the pkg_resources module if available and no standard file
- found at the calculated location.
-
It is possible to specify different location for zoneinfo
subdir by using the PYTZ_TZDATADIR environment variable.
"""
@@ -92,29 +93,7 @@
if zoneinfo_dir is not None:
filename = os.path.join(zoneinfo_dir, *name_parts)
else:
- filename = os.path.join(os.path.dirname(__file__),
- 'zoneinfo', *name_parts)
- if not os.path.exists(filename):
- # pkg_resources is deprecated, try with importlib first
- try:
- from importlib.resources import files
- except ImportError:
- files = None
-
- if files is not None:
- # retrieve the zoneinfo file Path object and return its file handle
- return files(__name__).joinpath('zoneinfo', *name_parts).open('rb')
-
- # http://bugs.launchpad.net/bugs/383171 - we avoid using this
- # unless absolutely necessary to help when a broken version of
- # pkg_resources is installed.
- try:
- from pkg_resources import resource_stream
- except ImportError:
- resource_stream = None
-
- if resource_stream is not None:
- return resource_stream(__name__, 'zoneinfo/' + name)
+ filename = os.path.join(_tzinfo_dir, *name_parts)
return open(filename, 'rb')
@@ -212,7 +191,7 @@
"""case-insensitively matching timezone, else return zone unchanged"""
global _all_timezones_lower_to_standard
if _all_timezones_lower_to_standard is None:
- _all_timezones_lower_to_standard = dict((tz.lower(), tz) for tz in _all_timezones_unchecked) # noqa
+ _all_timezones_lower_to_standard = dict((tz.lower(), tz) for tz in all_timezones) # noqa
return _all_timezones_lower_to_standard.get(zone.lower()) or zone # noqa
@@ -524,11 +503,37 @@
if __name__ == '__main__':
_test()
-all_timezones = LazyList(
- tz for tz in _all_timezones_unchecked if resource_exists(tz))
-
+all_timezones = []
+for root, dirs, files in os.walk(_tzinfo_dir):
+ for exclude in "posix", "right":
+ if exclude in dirs:
+ del dirs[dirs.index(exclude)]
+
+ all_timezones.extend(
+ os.path.join(root, file)[len(_tzinfo_dir)+1:]
+ for file in files
+ if file != "README" and file != "Theory" and "." not in file
+ )
+all_timezones.sort()
+
all_timezones_set = LazySet(all_timezones)
-common_timezones = LazyList(
- tz for tz in common_timezones if tz in all_timezones)
-
+
+with open(os.path.join(_tzinfo_dir, "zone.tab")) as ztf:
+ common_timezones = [
+ l.split()[2]
+ for l in ztf
+ if l != "" and l[0] != "#"
+ ] + [
+ "GMT",
+ "US/Alaska",
+ "US/Arizona",
+ "US/Central",
+ "US/Eastern",
+ "US/Hawaii",
+ "US/Mountain",
+ "US/Pacific",
+ "UTC",
+ ]
+common_timezones.sort()
+
common_timezones_set = LazySet(common_timezones)