]> git.pld-linux.org Git - packages/python-dateutil.git/blame - system-zoneinfo.patch
system tzdata patch from fedora. just in case
[packages/python-dateutil.git] / system-zoneinfo.patch
CommitLineData
07c95c93
ER
1diff -up python-dateutil-1.5/dateutil/zoneinfo/__init__.py\~ python-dateutil-1.5/dateutil/zoneinfo/__init__.py
2--- python-dateutil-1.5/dateutil/zoneinfo/__init__.py~ 2005-12-22 19:13:50.000000000 +0100
3+++ python-dateutil-1.5/dateutil/zoneinfo/__init__.py 2011-08-17 15:24:29.019214748 +0200
4@@ -15,6 +15,7 @@ __all__ = ["setcachesize", "gettz", "reb
5
6 CACHE = []
7 CACHESIZE = 10
8+USE_SYSTEM_ZONEINFO = True # XXX configure at build time
9
10 class tzfile(tzfile):
11 def __reduce__(self):
12@@ -29,7 +30,8 @@ def getzoneinfofile():
13 return os.path.join(os.path.dirname(__file__), entry)
14 return None
15
16-ZONEINFOFILE = getzoneinfofile()
17+ZONEINFOFILE = getzoneinfofile() if USE_SYSTEM_ZONEINFO else None
18+ZONEINFODIR = (os.getenv("TZDIR") or "/usr/share/zoneinfo").rstrip(os.sep)
19
20 del getzoneinfofile
21
22@@ -39,22 +40,37 @@ def setcachesize(size):
23 del CACHE[size:]
24
25 def gettz(name):
26- tzinfo = None
27- if ZONEINFOFILE:
28- for cachedname, tzinfo in CACHE:
29- if cachedname == name:
30- break
31+ for cachedname, tzinfo in CACHE:
32+ if cachedname == name:
33+ return tzinfo
34+
35+ name_parts = name.lstrip('/').split('/')
36+ for part in name_parts:
37+ if part == os.path.pardir or os.path.sep in part:
38+ raise ValueError('Bad path segment: %r' % part)
39+ filename = os.path.join(ZONEINFODIR, *name_parts)
40+ try:
41+ zonefile = open(filename, "rb")
42+ except:
43+ tzinfo = None
44+ else:
45+ tzinfo = tzfile(zonefile)
46+ zonefile.close()
47+
48+ if tzinfo is None and ZONEINFOFILE:
49+ tf = TarFile.open(ZONEINFOFILE)
50+ try:
51+ zonefile = tf.extractfile(name)
52+ except KeyError:
53+ tzinfo = None
54 else:
55- tf = TarFile.open(ZONEINFOFILE)
56- try:
57- zonefile = tf.extractfile(name)
58- except KeyError:
59- tzinfo = None
60- else:
61- tzinfo = tzfile(zonefile)
62- tf.close()
63- CACHE.insert(0, (name, tzinfo))
64- del CACHE[CACHESIZE:]
65+ tzinfo = tzfile(zonefile)
66+ tf.close()
67+
68+ if tzinfo is not None:
69+ CACHE.insert(0, (name, tzinfo))
70+ del CACHE[CACHESIZE:]
71+
72 return tzinfo
73
74 def rebuild(filename, tag=None, format="gz"):
75diff -up python-dateutil-1.5/setup.py\~ python-dateutil-1.5/setup.py
76--- python-dateutil-1.5/setup.py~ 2010-01-11 10:43:22.000000000 +0100
77+++ python-dateutil-1.5/setup.py 2011-08-17 15:38:13.206304651 +0200
78@@ -15,6 +15,16 @@ TOPDIR = os.path.dirname(__file__) or ".
79 VERSION = re.search('__version__ = "([^"]+)"',
80 open(TOPDIR + "/dateutil/__init__.py").read()).group(1)
81
82+# XXX We would like to bind this to something like
83+# --system-zoneinfo=/path/to/zoneinfo. Any way of doing this short of
84+# overriding build and install commands?
85+if False:
86+ extra_options = dict(
87+ package_data={"": ["*.tar.gz"]},
88+ )
89+else:
90+ extra_options = {}
91+
92
93 setup(name="python-dateutil",
94 version = VERSION,
95@@ -29,7 +39,7 @@ The dateutil module provides powerful ex
96 datetime module, available in Python 2.3+.
97 """,
98 packages = ["dateutil", "dateutil.zoneinfo"],
99- package_data={"": ["*.tar.gz"]},
100 include_package_data=True,
101 zip_safe=False,
102+ **extra_options
103 )
This page took 0.73732 seconds and 4 git commands to generate.