From c7979f16ecc0568e931edf440b25c437b461fd01 Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Sun, 5 Dec 2004 11:38:18 +0000 Subject: Removed deprecated tzparse module. --- Lib/lib-old/tzparse.py | 98 +++++++++++++++++++++++++++++++++++++++++++++++++ Lib/test/test_sundry.py | 1 - Lib/tzparse.py | 98 ------------------------------------------------- Misc/NEWS | 2 + 4 files changed, 100 insertions(+), 99 deletions(-) create mode 100644 Lib/lib-old/tzparse.py delete mode 100644 Lib/tzparse.py diff --git a/Lib/lib-old/tzparse.py b/Lib/lib-old/tzparse.py new file mode 100644 index 0000000..12468b5 --- /dev/null +++ b/Lib/lib-old/tzparse.py @@ -0,0 +1,98 @@ +"""Parse a timezone specification.""" + +# XXX Unfinished. +# XXX Only the typical form "XXXhhYYY;ddd/hh,ddd/hh" is currently supported. + +import warnings +warnings.warn( + "The tzparse module is obsolete and will disappear in the future", + DeprecationWarning) + +tzpat = ('^([A-Z][A-Z][A-Z])([-+]?[0-9]+)([A-Z][A-Z][A-Z]);' + '([0-9]+)/([0-9]+),([0-9]+)/([0-9]+)$') + +tzprog = None + +def tzparse(tzstr): + """Given a timezone spec, return a tuple of information + (tzname, delta, dstname, daystart, hourstart, dayend, hourend), + where 'tzname' is the name of the timezone, 'delta' is the offset + in hours from GMT, 'dstname' is the name of the daylight-saving + timezone, and 'daystart'/'hourstart' and 'dayend'/'hourend' + specify the starting and ending points for daylight saving time.""" + global tzprog + if tzprog is None: + import re + tzprog = re.compile(tzpat) + match = tzprog.match(tzstr) + if not match: + raise ValueError, 'not the TZ syntax I understand' + subs = [] + for i in range(1, 8): + subs.append(match.group(i)) + for i in (1, 3, 4, 5, 6): + subs[i] = eval(subs[i]) + [tzname, delta, dstname, daystart, hourstart, dayend, hourend] = subs + return (tzname, delta, dstname, daystart, hourstart, dayend, hourend) + +def tzlocaltime(secs, params): + """Given a Unix time in seconds and a tuple of information about + a timezone as returned by tzparse(), return the local time in the + form (year, month, day, hour, min, sec, yday, wday, tzname).""" + import time + (tzname, delta, dstname, daystart, hourstart, dayend, hourend) = params + year, month, days, hours, mins, secs, yday, wday, isdst = \ + time.gmtime(secs - delta*3600) + if (daystart, hourstart) <= (yday+1, hours) < (dayend, hourend): + tzname = dstname + hours = hours + 1 + return year, month, days, hours, mins, secs, yday, wday, tzname + +def tzset(): + """Determine the current timezone from the "TZ" environment variable.""" + global tzparams, timezone, altzone, daylight, tzname + import os + tzstr = os.environ['TZ'] + tzparams = tzparse(tzstr) + timezone = tzparams[1] * 3600 + altzone = timezone - 3600 + daylight = 1 + tzname = tzparams[0], tzparams[2] + +def isdst(secs): + """Return true if daylight-saving time is in effect for the given + Unix time in the current timezone.""" + import time + (tzname, delta, dstname, daystart, hourstart, dayend, hourend) = \ + tzparams + year, month, days, hours, mins, secs, yday, wday, isdst = \ + time.gmtime(secs - delta*3600) + return (daystart, hourstart) <= (yday+1, hours) < (dayend, hourend) + +tzset() + +def localtime(secs): + """Get the local time in the current timezone.""" + return tzlocaltime(secs, tzparams) + +def test(): + from time import asctime, gmtime + import time, sys + now = time.time() + x = localtime(now) + tm = x[:-1] + (0,) + print 'now =', now, '=', asctime(tm), x[-1] + now = now - now % (24*3600) + if sys.argv[1:]: now = now + eval(sys.argv[1]) + x = gmtime(now) + tm = x[:-1] + (0,) + print 'gmtime =', now, '=', asctime(tm), 'yday =', x[-2] + jan1 = now - x[-2]*24*3600 + x = localtime(jan1) + tm = x[:-1] + (0,) + print 'jan1 =', jan1, '=', asctime(tm), x[-1] + for d in range(85, 95) + range(265, 275): + t = jan1 + d*24*3600 + x = localtime(t) + tm = x[:-1] + (0,) + print 'd =', d, 't =', t, '=', asctime(tm), x[-1] diff --git a/Lib/test/test_sundry.py b/Lib/test/test_sundry.py index ef28700..be1a1e7 100644 --- a/Lib/test/test_sundry.py +++ b/Lib/test/test_sundry.py @@ -87,7 +87,6 @@ import tabnanny import telnetlib import test import toaiff -#import tzparse import urllib2 # Can't test the "user" module -- if the user has a ~/.pythonrc.py, it # can screw up all sorts of things (esp. if it prints!). diff --git a/Lib/tzparse.py b/Lib/tzparse.py deleted file mode 100644 index 12468b5..0000000 --- a/Lib/tzparse.py +++ /dev/null @@ -1,98 +0,0 @@ -"""Parse a timezone specification.""" - -# XXX Unfinished. -# XXX Only the typical form "XXXhhYYY;ddd/hh,ddd/hh" is currently supported. - -import warnings -warnings.warn( - "The tzparse module is obsolete and will disappear in the future", - DeprecationWarning) - -tzpat = ('^([A-Z][A-Z][A-Z])([-+]?[0-9]+)([A-Z][A-Z][A-Z]);' - '([0-9]+)/([0-9]+),([0-9]+)/([0-9]+)$') - -tzprog = None - -def tzparse(tzstr): - """Given a timezone spec, return a tuple of information - (tzname, delta, dstname, daystart, hourstart, dayend, hourend), - where 'tzname' is the name of the timezone, 'delta' is the offset - in hours from GMT, 'dstname' is the name of the daylight-saving - timezone, and 'daystart'/'hourstart' and 'dayend'/'hourend' - specify the starting and ending points for daylight saving time.""" - global tzprog - if tzprog is None: - import re - tzprog = re.compile(tzpat) - match = tzprog.match(tzstr) - if not match: - raise ValueError, 'not the TZ syntax I understand' - subs = [] - for i in range(1, 8): - subs.append(match.group(i)) - for i in (1, 3, 4, 5, 6): - subs[i] = eval(subs[i]) - [tzname, delta, dstname, daystart, hourstart, dayend, hourend] = subs - return (tzname, delta, dstname, daystart, hourstart, dayend, hourend) - -def tzlocaltime(secs, params): - """Given a Unix time in seconds and a tuple of information about - a timezone as returned by tzparse(), return the local time in the - form (year, month, day, hour, min, sec, yday, wday, tzname).""" - import time - (tzname, delta, dstname, daystart, hourstart, dayend, hourend) = params - year, month, days, hours, mins, secs, yday, wday, isdst = \ - time.gmtime(secs - delta*3600) - if (daystart, hourstart) <= (yday+1, hours) < (dayend, hourend): - tzname = dstname - hours = hours + 1 - return year, month, days, hours, mins, secs, yday, wday, tzname - -def tzset(): - """Determine the current timezone from the "TZ" environment variable.""" - global tzparams, timezone, altzone, daylight, tzname - import os - tzstr = os.environ['TZ'] - tzparams = tzparse(tzstr) - timezone = tzparams[1] * 3600 - altzone = timezone - 3600 - daylight = 1 - tzname = tzparams[0], tzparams[2] - -def isdst(secs): - """Return true if daylight-saving time is in effect for the given - Unix time in the current timezone.""" - import time - (tzname, delta, dstname, daystart, hourstart, dayend, hourend) = \ - tzparams - year, month, days, hours, mins, secs, yday, wday, isdst = \ - time.gmtime(secs - delta*3600) - return (daystart, hourstart) <= (yday+1, hours) < (dayend, hourend) - -tzset() - -def localtime(secs): - """Get the local time in the current timezone.""" - return tzlocaltime(secs, tzparams) - -def test(): - from time import asctime, gmtime - import time, sys - now = time.time() - x = localtime(now) - tm = x[:-1] + (0,) - print 'now =', now, '=', asctime(tm), x[-1] - now = now - now % (24*3600) - if sys.argv[1:]: now = now + eval(sys.argv[1]) - x = gmtime(now) - tm = x[:-1] + (0,) - print 'gmtime =', now, '=', asctime(tm), 'yday =', x[-2] - jan1 = now - x[-2]*24*3600 - x = localtime(jan1) - tm = x[:-1] + (0,) - print 'jan1 =', jan1, '=', asctime(tm), x[-1] - for d in range(85, 95) + range(265, 275): - t = jan1 + d*24*3600 - x = localtime(t) - tm = x[:-1] + (0,) - print 'd =', d, 't =', t, '=', asctime(tm), x[-1] diff --git a/Misc/NEWS b/Misc/NEWS index 95b9d2c..784e782 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -25,6 +25,8 @@ Extension Modules Library ------- +- the deprecated tzparse module was removed. + - the pickle module no longer uses the deprecated bin parameter. - the depecated statcache module was removed. -- cgit v0.12