[Checkins] SVN: DateTime/trunk/ Moved pytz cache from `DateTime._tzinfo` to a module global `_TZINFO`.

Hanno Schlichting hannosch at hannosch.eu
Sun May 8 07:24:01 EDT 2011


Log message for revision 121578:
  Moved pytz cache from `DateTime._tzinfo` to a module global `_TZINFO`.
  

Changed:
  U   DateTime/trunk/CHANGES.txt
  U   DateTime/trunk/src/DateTime/DateTime.py
  U   DateTime/trunk/src/DateTime/pytz.txt

-=-
Modified: DateTime/trunk/CHANGES.txt
===================================================================
--- DateTime/trunk/CHANGES.txt	2011-05-08 11:13:05 UTC (rev 121577)
+++ DateTime/trunk/CHANGES.txt	2011-05-08 11:24:01 UTC (rev 121578)
@@ -4,6 +4,8 @@
 3.0 (unreleased)
 ----------------
 
+- Moved pytz cache from `DateTime._tzinfo` to a module global `_TZINFO`.
+
 - Make DateTime a new-style class and limit its available attributes via a
   slots definition. The pickle size increases to 110 bytes thanks to the
   `ccopy_reg\n_reconstructor` stanza. But the memory size drops from 3kb to

Modified: DateTime/trunk/src/DateTime/DateTime.py
===================================================================
--- DateTime/trunk/src/DateTime/DateTime.py	2011-05-08 11:13:05 UTC (rev 121577)
+++ DateTime/trunk/src/DateTime/DateTime.py	2011-05-08 11:24:01 UTC (rev 121578)
@@ -56,6 +56,8 @@
 EPOCH  =(to_year+to_month+dy+(hr/24.0+mn/1440.0+sc/86400.0))*86400
 jd1901 =2415385L
 
+_TZINFO = PytzCache()
+
 numericTimeZoneMatch = re.compile(r'[+-][0-9][0-9][0-9][0-9]').match
 iso8601Match = re.compile(r'''
   (?P<year>\d\d\d\d)                # four digits year
@@ -229,7 +231,7 @@
     the time zone, i.e. GMT+2 has a 7200 second offset. This is the opposite
     sign of time.timezone which (confusingly) is -7200 for GMT+2."""
     try:
-        return DateTime._tzinfo[tz].info(t)[0]
+        return _TZINFO[tz].info(t)[0]
     except:
         if numericTimeZoneMatch(tz) is not None:
             return int(tz[0:3])*3600+int(tz[0]+tz[3:5])*60
@@ -643,10 +645,10 @@
 
                 if tz:
                     try:
-                        zone = self._tzinfo[tz]
+                        zone = _TZINFO[tz]
                     except DateTimeError:
                         try:
-                            zone = self._tzinfo[numerictz]
+                            zone = _TZINFO[numerictz]
                         except DateTimeError:
                             raise DateTimeError, \
                                   'Unknown time zone in date: %s' % arg
@@ -655,9 +657,9 @@
                     tz = self._calcTimezoneName(x, ms)
                 s,d,t,microsecs = _calcIndependentSecondEtc(tz, x, ms)
 
-            elif isinstance(arg, (unicode, str)) and arg.lower() in self._tzinfo._zidx:
+            elif isinstance(arg, (unicode, str)) and arg.lower() in _TZINFO._zidx:
                 # Current time, to be displayed in specified timezone
-                t,tz=time(),self._tzinfo._zmap[arg.lower()]
+                t,tz=time(), _TZINFO._zmap[arg.lower()]
                 ms=(t-math.floor(t))
                 # Use integer arithmetic as much as possible.
                 s,d = _calcSD(t)
@@ -684,7 +686,8 @@
                 x = _calcDependentSecond2(yr,mo,dy,hr,mn,sc)
 
                 if tz:
-                    try: tz=self._tzinfo._zmap[tz.lower()]
+                    try:
+                        tz= _TZINFO._zmap[tz.lower()]
                     except KeyError:
                         if numericTimeZoneMatch(tz) is None:
                             raise DateTimeError, \
@@ -708,7 +711,7 @@
                 # Seconds from epoch (gmt) and timezone
                 t,tz=args
                 ms = (t - math.floor(t))
-                tz=self._tzinfo._zmap[tz.lower()]
+                tz = _TZINFO._zmap[tz.lower()]
                 # Use integer arithmetic as much as possible.
                 s,d = _calcSD(t)
                 x = _calcDependentSecond(tz, t)
@@ -751,7 +754,8 @@
             x = _calcDependentSecond2(yr,mo,dy,hr,mn,sc)
             ms = sc - math.floor(sc)
             if tz:
-                try: tz=self._tzinfo._zmap[tz.lower()]
+                try:
+                    tz = _TZINFO._zmap[tz.lower()]
                 except KeyError:
                     if numericTimeZoneMatch(tz) is None:
                         raise DateTimeError, \
@@ -791,7 +795,6 @@
         # self._micros is the time since the epoch
         # in long integer microseconds.
 
-
     int_pattern  =re.compile(r'([0-9]+)') #AJ
     flt_pattern  =re.compile(r':([0-9]+\.[0-9]+)') #AJ
     name_pattern =re.compile(r'([a-zA-Z]+)', re.I) #AJ
@@ -888,7 +891,7 @@
         delimiters    =self.delimiters
         MonthNumbers  =self._monthmap
         DayOfWeekNames=self._daymap
-        ValidZones    =self._tzinfo._zidx
+        ValidZones = _TZINFO._zidx
         TimeModifiers =['am','pm']
 
         # Find timezone first, since it should always be the last
@@ -1095,7 +1098,7 @@
         """Return a DateTime with the value as the current
         object, represented in the indicated timezone.
         """
-        t,tz=self._t,self._tzinfo._zmap[z.lower()]
+        t, tz = self._t, _TZINFO._zmap[z.lower()]
         micros = self.micros()
         tznaive = False # you're performing a timzone change, can't be naive
 
@@ -1619,7 +1622,7 @@
         if tznaive:
             tzinfo = None
         else:
-            tzinfo = self._tzinfo[self._tz].tzinfo
+            tzinfo = _TZINFO[self._tz].tzinfo
         second = int(self._second)
         microsec = self.micros() % 1000000
         dt = datetime(self._year, self._month, self._day, self._hour,

Modified: DateTime/trunk/src/DateTime/pytz.txt
===================================================================
--- DateTime/trunk/src/DateTime/pytz.txt	2011-05-08 11:13:05 UTC (rev 121577)
+++ DateTime/trunk/src/DateTime/pytz.txt	2011-05-08 11:24:01 UTC (rev 121578)
@@ -99,25 +99,25 @@
     >>> t.remove('US/Eastern')
     >>> d = DateTime('US/Eastern')
 
-Python Versions
----------------
-Both pytz and DateTime should work under Python 2.3 as well as Python 2.4.
 
 Internal Components
 -------------------
+
 The following are tests of internal components.
 
 Cache
 ~~~~~
+
 The DateTime class uses a new time zone cache.
 
-    >>> DateTime._tzinfo #doctest: +ELLIPSIS
+    >>> from DateTime.DateTime import _TZINFO
+    >>> _TZINFO #doctest: +ELLIPSIS
     <DateTime.pytz_support.PytzCache instance at ...>
 
 The cache maps time zone names to time zone instances.
 
-    >>> cache = DateTime._tzinfo
-    >>> tz = cache['GMT+730']   
+    >>> cache = _TZINFO
+    >>> tz = cache['GMT+730']
     >>> tz = cache['US/Mountain']
 
 The cache also must provide a few attributes for use by the DateTime



More information about the checkins mailing list