Blame SOURCES/python-dateutil-1.5-system-zoneinfo.patch

f11e15
diff -up python-dateutil-1.5/dateutil/zoneinfo/__init__.py\~ python-dateutil-1.5/dateutil/zoneinfo/__init__.py
f11e15
--- python-dateutil-1.5/dateutil/zoneinfo/__init__.py~	2005-12-22 19:13:50.000000000 +0100
f11e15
+++ python-dateutil-1.5/dateutil/zoneinfo/__init__.py	2011-08-17 15:24:29.019214748 +0200
f11e15
@@ -15,6 +15,7 @@ __all__ = ["setcachesize", "gettz", "reb
f11e15
 
f11e15
 CACHE = []
f11e15
 CACHESIZE = 10
f11e15
+USE_SYSTEM_ZONEINFO = True # XXX configure at build time
f11e15
 
f11e15
 class tzfile(tzfile):
f11e15
     def __reduce__(self):
f11e15
@@ -29,7 +30,8 @@ def getzoneinfofile():
f11e15
             return os.path.join(os.path.dirname(__file__), entry)
f11e15
     return None
f11e15
 
f11e15
-ZONEINFOFILE = getzoneinfofile()
f11e15
+ZONEINFOFILE = getzoneinfofile() if USE_SYSTEM_ZONEINFO else None
f11e15
+ZONEINFODIR = (os.getenv("TZDIR") or "/usr/share/zoneinfo").rstrip(os.sep)
f11e15
 
f11e15
 del getzoneinfofile
f11e15
 
f11e15
@@ -39,22 +40,37 @@ def setcachesize(size):
f11e15
     del CACHE[size:]
f11e15
 
f11e15
 def gettz(name):
f11e15
-    tzinfo = None
f11e15
-    if ZONEINFOFILE:
f11e15
-        for cachedname, tzinfo in CACHE:
f11e15
-            if cachedname == name:
f11e15
-                break
f11e15
+    for cachedname, tzinfo in CACHE:
f11e15
+        if cachedname == name:
f11e15
+            return tzinfo
f11e15
+
f11e15
+    name_parts = name.lstrip('/').split('/')
f11e15
+    for part in name_parts:
f11e15
+        if part == os.path.pardir or os.path.sep in part:
f11e15
+            raise ValueError('Bad path segment: %r' % part)
f11e15
+    filename = os.path.join(ZONEINFODIR, *name_parts)
f11e15
+    try:
f11e15
+        zonefile = open(filename, "rb")
f11e15
+    except:
f11e15
+        tzinfo = None
f11e15
+    else:
f11e15
+        tzinfo = tzfile(zonefile)
f11e15
+        zonefile.close()
f11e15
+
f11e15
+    if tzinfo is None and ZONEINFOFILE:
f11e15
+        tf = TarFile.open(ZONEINFOFILE)
f11e15
+        try:
f11e15
+            zonefile = tf.extractfile(name)
f11e15
+        except KeyError:
f11e15
+            tzinfo = None
f11e15
         else:
f11e15
-            tf = TarFile.open(ZONEINFOFILE)
f11e15
-            try:
f11e15
-                zonefile = tf.extractfile(name)
f11e15
-            except KeyError:
f11e15
-                tzinfo = None
f11e15
-            else:
f11e15
-                tzinfo = tzfile(zonefile)
f11e15
-            tf.close()
f11e15
-            CACHE.insert(0, (name, tzinfo))
f11e15
-            del CACHE[CACHESIZE:]
f11e15
+            tzinfo = tzfile(zonefile)
f11e15
+        tf.close()
f11e15
+
f11e15
+    if tzinfo is not None:
f11e15
+        CACHE.insert(0, (name, tzinfo))
f11e15
+        del CACHE[CACHESIZE:]
f11e15
+
f11e15
     return tzinfo
f11e15
 
f11e15
 def rebuild(filename, tag=None, format="gz"):
f11e15
diff -up python-dateutil-1.5/setup.py\~ python-dateutil-1.5/setup.py
f11e15
--- python-dateutil-1.5/setup.py~	2010-01-11 10:43:22.000000000 +0100
f11e15
+++ python-dateutil-1.5/setup.py	2011-08-17 15:38:13.206304651 +0200
f11e15
@@ -15,6 +15,16 @@ TOPDIR = os.path.dirname(__file__) or ".
f11e15
 VERSION = re.search('__version__ = "([^"]+)"',
f11e15
                     open(TOPDIR + "/dateutil/__init__.py").read()).group(1)
f11e15
 
f11e15
+# XXX We would like to bind this to something like
f11e15
+# --system-zoneinfo=/path/to/zoneinfo.  Any way of doing this short of
f11e15
+# overriding build and install commands?
f11e15
+if False:
f11e15
+    extra_options = dict(
f11e15
+        package_data={"": ["*.tar.gz"]},
f11e15
+        )
f11e15
+else:
f11e15
+    extra_options = {}
f11e15
+
f11e15
 
f11e15
 setup(name="python-dateutil",
f11e15
       version = VERSION,
f11e15
@@ -29,7 +39,7 @@ The dateutil module provides powerful ex
f11e15
 datetime module, available in Python 2.3+.
f11e15
 """,
f11e15
       packages = ["dateutil", "dateutil.zoneinfo"],
f11e15
-      package_data={"": ["*.tar.gz"]},
f11e15
       include_package_data=True,
f11e15
       zip_safe=False,
f11e15
+      **extra_options
f11e15
       )