[Zope3-checkins] CVS: Zope3/src/zope/app - datetimeutils.py:1.1.2.3

Fred L. Drake, Jr. fred@zope.com
Tue, 24 Dec 2002 11:54:50 -0500


Update of /cvs-repository/Zope3/src/zope/app
In directory cvs.zope.org:/tmp/cvs-serv8420

Modified Files:
      Tag: NameGeddon-branch
	datetimeutils.py 
Log Message:
- clean up imports
- normalize whitespace


=== Zope3/src/zope/app/datetimeutils.py 1.1.2.2 => 1.1.2.3 ===
--- Zope3/src/zope/app/datetimeutils.py:1.1.2.2	Mon Dec 23 16:16:53 2002
+++ Zope3/src/zope/app/datetimeutils.py	Tue Dec 24 11:54:49 2002
@@ -2,23 +2,35 @@
 #
 # Copyright (c) 2001, 2002 Zope Corporation and Contributors.
 # All Rights Reserved.
-# 
+#
 # This software is subject to the provisions of the Zope Public License,
 # Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
 # FOR A PARTICULAR PURPOSE.
-# 
+#
 ##############################################################################
 """Commonly used utility functions.
 
+Encapsulation of date/time values
+
 $Id$
 """
 
 __version__='$Revision$'[11:-2]
 
-import time
+import math
+import re
+import time as _time # there is a method definition that makes just "time"
+                     # problematic while executing a class definition
+
+from types import StringTypes
+
+try:
+    from time import tzname
+except ImportError:
+    tzname = ('UNKNOWN','UNKNOWN')
 
 # These are needed because the various date formats below must
 # be in english per the RFCs. That means we can't use strftime,
@@ -34,14 +46,16 @@
     # Return an ISO 8601 formatted date string, required
     # for certain DAV properties.
     # '2000-11-10T16:21:09-08:00
-    if ts is None: ts=time.time()
-    return time.strftime('%Y-%m-%dT%H:%M:%SZ', time.gmtime(ts))
+    if ts is None:
+        ts = _time.time()
+    return _time.strftime('%Y-%m-%dT%H:%M:%SZ', _time.gmtime(ts))
 
 def rfc850_date(ts=None):
     # Return an HTTP-date formatted date string.
     # 'Friday, 10-Nov-00 16:21:09 GMT'
-    if ts is None: ts=time.time()
-    year, month, day, hh, mm, ss, wd, y, z = time.gmtime(ts)
+    if ts is None:
+        ts = _time.time()
+    year, month, day, hh, mm, ss, wd, y, z = _time.gmtime(ts)
     return "%s, %02d-%3s-%2s %02d:%02d:%02d GMT" % (
             weekday_full[wd],
             day, monthname[month],
@@ -52,26 +66,20 @@
     # Return an RFC 1123 format date string, required for
     # use in HTTP Date headers per the HTTP 1.1 spec.
     # 'Fri, 10 Nov 2000 16:21:09 GMT'
-    if ts is None: ts=time.time()
-    year, month, day, hh, mm, ss, wd, y, z = time.gmtime(ts)
+    if ts is None:
+        ts = _time.time()
+    year, month, day, hh, mm, ss, wd, y, z = _time.gmtime(ts)
     return "%s, %02d %3s %4d %02d:%02d:%02d GMT" % (weekday_abbr[wd],
                                                     day, monthname[month],
                                                     year,
                                                     hh, mm, ss)
-    
-
 
-"""
-
-Revision information: $Id$
-"""
 
 
-_data={
-
+_data = {
 
 'GMT':      ('GMT',      0, 1, [], '', [(0, 0, 0)],      'GMT\000'),
-'GMT+0':    ('GMT+0',    0, 1, [], '', [(0, 0, 0)],      'GMT+0000\000'), 
+'GMT+0':    ('GMT+0',    0, 1, [], '', [(0, 0, 0)],      'GMT+0000\000'),
 'GMT+1':    ('GMT+1',    0, 1, [], '', [(3600, 0, 0)],   'GMT+0100\000'),
 'GMT+2':    ('GMT+2',    0, 1, [], '', [(7200, 0, 0)],   'GMT+0200\000'),
 'GMT+3':    ('GMT+3',    0, 1, [], '', [(10800, 0, 0)],  'GMT+0300\000'),
@@ -82,7 +90,7 @@
 'GMT+8':    ('GMT+8',    0, 1, [], '', [(28800, 0, 0)],  'GMT+0800\000'),
 'GMT+9':    ('GMT+9',    0, 1, [], '', [(32400, 0, 0)],  'GMT+0900\000'),
 'GMT+10':   ('GMT+10',   0, 1, [], '', [(36000, 0, 0)],  'GMT+1000\000'),
-'GMT+11':   ('GMT+11',   0, 1, [], '', [(39600, 0, 0)],  'GMT+1100\000'), 
+'GMT+11':   ('GMT+11',   0, 1, [], '', [(39600, 0, 0)],  'GMT+1100\000'),
 'GMT+12':   ('GMT+12',   0, 1, [], '', [(43200, 0, 0)],  'GMT+1200\000'),
 'GMT+13':   ('GMT+13',   0, 1, [], '', [(46800, 0, 0)],  'GMT+1300\000'),
 
@@ -131,18 +139,6 @@
 }
 
 
-"""Encapsulation of date/time values
-
-$Id$
-"""
-
-import math
-import re
-from types import StringTypes
-from time import \
-     time as _time, gmtime, localtime, daylight, timezone, altzone
-try: from time import tzname
-except ImportError: tzname = ('UNKNOWN','UNKNOWN')
 
 class DateTimeError(Exception): "Date-time error"
 class DateError(DateTimeError): 'Invalid Date Components'
@@ -152,7 +148,7 @@
 # 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]
+yr,mo,dy,hr,mn,sc = _time.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]
@@ -173,12 +169,13 @@
             if self.tinfo[i][1] == 0: return i
         return 0
 
-    def index(self,t=None):
-        t=t or _time()
-        if self.timect==0: idx=(0, 0, 0)
+    def index(self, t=None):
+        t = t or _time.time()
+        if self.timect == 0:
+            idx = (0, 0, 0)
         elif t < self.ttrans[0]:
-            i=self.default_index()
-            idx=(i, ord(self.tindex[0]),i)
+            i = self.default_index()
+            idx = (i, ord(self.tindex[0]),i)
         elif t >= self.ttrans[-1]:
             if self.timect > 1:
                 idx=(ord(self.tindex[-1]),ord(self.tindex[-1]),
@@ -359,13 +356,14 @@
             if numericTimeZoneMatch(k) == None:
                 raise 'DateTimeError','Unrecognized timezone: %s' % k
             return k
-        try: return self._d[n]
+        try:
+            return self._d[n]
         except KeyError:
-            z=self._d[n]=_timezone(self._db[n])
+            z = self._d[n] = _timezone(self._db[n])
             return z
 
 def _findLocalTimeZoneName(isDST):
-    if not daylight:
+    if not _time.daylight:
         # Daylight savings does not occur in this time zone.
         isDST = 0
     try:
@@ -376,9 +374,9 @@
         try:
             # Generate a GMT-offset zone name.
             if isDST:
-                localzone = altzone
+                localzone = _time.altzone
             else:
-                localzone = timezone
+                localzone = _time.timezone
             offset=(-localzone/(60*60))
             majorOffset=int(offset)
             if majorOffset != 0 :
@@ -510,8 +508,7 @@
     except OverflowError:
         raise TimeError('The time %f is beyond the range '
                         'of this Python implementation.' % float(t))
-    rval = gmtime(t_int)
-    return rval
+    return _time.gmtime(t_int)
 
 def safelocaltime(t):
     '''localtime with a safety zone.'''
@@ -520,8 +517,7 @@
     except OverflowError:
         raise TimeError('The time %f is beyond the range '
                         'of this Python implementation.' % float(t))
-    rval = localtime(t_int)
-    return rval
+    return _time.localtime(t_int)
 
 class DateTimeParser:
 
@@ -667,10 +663,10 @@
     _localzone1 = _findLocalTimeZoneName(1)
     _multipleZones = (_localzone0 != _localzone1)
     # For backward compatibility only:
-    _isDST = localtime(_time())[8]
-    _localzone  = _isDST and _localzone1 or _localzone0
+    _isDST = _time.localtime()[8]
+    _localzone = _isDST and _localzone1 or _localzone0
 
-    _tzinfo     = _cache()
+    _tzinfo    = _cache()
 
     def localZone(self, ltm=None):
         '''Returns the time zone on the given date.  The time zone
@@ -678,7 +674,7 @@
         if not self._multipleZones:
             return self._localzone0
         if ltm == None:
-            ltm = localtime(_time())
+            ltm = _time.localtime()
         isDST = ltm[8]
         lz = isDST and self._localzone1 or self._localzone0
         return lz
@@ -855,7 +851,7 @@
 
         if day is None:
             # Use today's date.
-            year,month,day = localtime(_time())[:3]
+            year,month,day = _time.localtime()[:3]
 
         year = _correctYear(year)
         if year < 1000: raise SyntaxError(string)