[Checkins] SVN: DateTime/trunk/src/DateTime/ Some PEP8, avoid module level _cache alias for the PytzCache class
Hanno Schlichting
hannosch at hannosch.eu
Sun May 8 07:30:57 EDT 2011
Log message for revision 121579:
Some PEP8, avoid module level _cache alias for the PytzCache class
Changed:
U DateTime/trunk/src/DateTime/DateTime.py
U DateTime/trunk/src/DateTime/tests/testDateTime.py
-=-
Modified: DateTime/trunk/src/DateTime/DateTime.py
===================================================================
--- DateTime/trunk/src/DateTime/DateTime.py 2011-05-08 11:24:01 UTC (rev 121578)
+++ DateTime/trunk/src/DateTime/DateTime.py 2011-05-08 11:30:57 UTC (rev 121579)
@@ -10,20 +10,28 @@
# FOR A PARTICULAR PURPOSE
#
##############################################################################
-"""Encapsulation of date/time values"""
-
-import re, math
-from time import time, gmtime, localtime
-from time import daylight, timezone, altzone
+import math
+import re
+from time import altzone
+from time import daylight
+from time import gmtime
+from time import localtime
+from time import time
+from time import timezone
from time import tzname
from datetime import datetime
-from interfaces import IDateTime
-from interfaces import DateTimeError, SyntaxError, DateError, TimeError
+
+from pytz_support import PytzCache
from zope.interface import implements
-from pytz_support import PytzCache
-_cache = PytzCache
+from interfaces import IDateTime
+from interfaces import DateTimeError
+from interfaces import SyntaxError
+from interfaces import DateError
+from interfaces import TimeError
+
+
default_datefmt = None
def getDefaultDateFormat():
@@ -33,12 +41,11 @@
from App.config import getConfiguration
default_datefmt = getConfiguration().datetime_format
return default_datefmt
- except:
+ except Exception:
return 'us'
else:
return default_datefmt
-
# To control rounding errors, we round system time to the nearest
# microsecond. Then delicate calculations can rely on that the
# maximum precision that needs to be preserved is known.
@@ -47,14 +54,15 @@
return round(_system_time(), 6)
# Determine machine epoch
-tm=((0, 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334),
- (0, 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335))
-yr,mo,dy,hr,mn,sc=gmtime(0)[:6]
-i=int(yr-1)
-to_year =int(i*365+i/4-i/100+i/400-693960.0)
-to_month=tm[yr%4==0 and (yr%100!=0 or yr%400==0)][mo]
-EPOCH =(to_year+to_month+dy+(hr/24.0+mn/1440.0+sc/86400.0))*86400
-jd1901 =2415385L
+tm= ((0, 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334),
+ (0, 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335))
+yr, mo, dy, hr, mn, sc = gmtime(0)[:6]
+i = int(yr - 1)
+to_year = int(i * 365 + i / 4 - i / 100 + i / 400 - 693960.0)
+to_month = tm[yr % 4 == 0 and (yr % 100 != 0 or yr % 400 == 0)][mo]
+EPOCH = ((to_year + to_month + dy +
+ (hr / 24.0 + mn / 1440.0 + sc / 86400.0)) * 86400)
+jd1901 = 2415385L
_TZINFO = PytzCache()
@@ -112,7 +120,7 @@
try:
# Get the name of the current time zone depending
# on DST.
- _localzone = _cache._zmap[tzname[isDST].lower()]
+ _localzone = PytzCache._zmap[tzname[isDST].lower()]
except:
try:
# Generate a GMT-offset zone name.
@@ -127,7 +135,7 @@
else: minorOffset = 0
m=majorOffset >= 0 and '+' or ''
lz='%s%0.02d%0.02d' % (m, majorOffset, minorOffset)
- _localzone = _cache._zmap[('GMT%s' % lz).lower()]
+ _localzone = PytzCache._zmap[('GMT%s' % lz).lower()]
except:
_localzone = ''
return _localzone
Modified: DateTime/trunk/src/DateTime/tests/testDateTime.py
===================================================================
--- DateTime/trunk/src/DateTime/tests/testDateTime.py 2011-05-08 11:24:01 UTC (rev 121578)
+++ DateTime/trunk/src/DateTime/tests/testDateTime.py 2011-05-08 11:30:57 UTC (rev 121579)
@@ -18,7 +18,7 @@
import time
import unittest
-from DateTime.DateTime import _findLocalTimeZoneName, _cache
+from DateTime.DateTime import _findLocalTimeZoneName
from DateTime import DateTime
from datetime import date, datetime, tzinfo, timedelta
import pytz
@@ -569,19 +569,19 @@
self.assertEqual(dt5, dt6)
self.assertEqual(dt5.asdatetime().tzinfo, tz)
self.assertEqual(dt6.asdatetime().tzinfo, tz)
-
+
def testLegacyTimezones(self):
- cache = _cache()
+ from DateTime.DateTime import _TZINFO
# The year is important here as timezones change over time
t1 = time.mktime(datetime(2002, 1, 1).timetuple())
t2 = time.mktime(datetime(2002, 7, 1).timetuple())
for name in legacy._zlst + legacy._zmap.keys() + legacy._data.keys():
- self.failUnless(name.lower() in cache._zidx, 'legacy timezone %s cannot be looked up' % name)
+ self.failUnless(name.lower() in _TZINFO._zidx, 'legacy timezone %s cannot be looked up' % name)
failures = []
for name, zone in legacy.timezones.iteritems():
- newzone = cache[name]
+ newzone = _TZINFO[name]
# The name of the new zone might change (eg GMT+6 rather than GMT+0600)
if zone.info(t1)[:2] != newzone.info(t1)[:2] or zone.info(t2)[:2] != newzone.info(t2)[:2]:
failures.append(name)
More information about the checkins
mailing list