[Zope-Checkins] CVS: Packages/DateTime - DateTime.py:1.85.12.6

Evan Simpson cvs-admin at zope.org
Thu Nov 20 12:12:50 EST 2003


Update of /cvs-repository/Packages/DateTime
In directory cvs.zope.org:/tmp/cvs-serv10146/lib/python/DateTime

Modified Files:
      Tag: Zope-2_7-branch
	DateTime.py 
Log Message:
Mostly fixed Collector #1129.  Badly formed ISO8601 dates are rejected,
except that 'Z' is still allowed in front of a '+/-HH:MM' timezone.  I
left that in since it was used elsewhere in the code, and was probably
harmless, whereas the other parse problems caused dates like "2003-2-5"
to be accepted as valid and silently converted into "2003-01-01".

Also re-exposed the DateTime-specific exceptions as attributes of the
DateTime class.  During their recent converted from strings to classes,
they were removed.



=== Packages/DateTime/DateTime.py 1.85.12.5 => 1.85.12.6 ===
--- Packages/DateTime/DateTime.py:1.85.12.5	Mon Nov 17 17:34:05 2003
+++ Packages/DateTime/DateTime.py	Thu Nov 20 12:12:19 2003
@@ -479,6 +479,12 @@
     __roles__=None
     __allow_access_to_unprotected_subobjects__=1
 
+    # Make class-specific exceptions available as attributes.
+    DateError = DateError
+    TimeError = TimeError
+    DateTimeError = DateTimeError
+    SyntaxError = SyntaxError
+
     def __init__(self,*args, **kw):
         """Return a new date-time object
 
@@ -1647,7 +1653,8 @@
         try:
             return self.__parse_iso8601(s)
         except IndexError:
-            raise DateError,'Not an ISO 8601 compliant date string: "%s"' %  s
+            raise SyntaxError, (
+                'Not an ISO 8601 compliant date string: "%s"' % s)
 
 
     def __parse_iso8601(self,s):
@@ -1657,7 +1664,8 @@
         hour=minute=seconds=hour_off=min_off=0
 
         datereg = re.compile('([0-9]{4})(-([0-9][0-9]))?(-([0-9][0-9]))?')
-        timereg = re.compile('([0-9]{2})(:([0-9][0-9]))?(:([0-9][0-9]))?(\.[0-9]{1,20})?')
+        timereg = re.compile('T([0-9]{2})(:([0-9][0-9]))?(:([0-9][0-9]))?(\.[0-9]{1,20})?')
+        zonereg = re.compile('([+-][0-9][0-9])(:([0-9][0-9]))')
 
         # Date part
 
@@ -1666,21 +1674,33 @@
         if fields[1]:   year  = int(fields[1])
         if fields[3]:   month = int(fields[3])
         if fields[5]:   day   = int(fields[5])
+        t = fields[6]
+        if t:
+            if not fields[5]:
+                # Specifying time requires specifying a day.
+                raise IndexError
 
-        if s.find('T')>-1:
-            fields = timereg.split(s[s.find('T')+1:])
+            fields = timereg.split(t)
 
             if fields[1]:   hour     = int(fields[1])
             if fields[3]:   minute   = int(fields[3])
             if fields[5]:   seconds  = int(fields[5])
             if fields[6]:   seconds  = seconds+float(fields[6])
-
-        if s.find('Z')>-1:
-            pass
-
-        if s[-3]==':' and s[-6] in ['+','-']:
-            hour_off = int(s[-6:-3])
-            min_off  = int(s[-2:])
+            z = fields[7]
+            
+	    if z and z.startswith('Z'):
+                # Waaaa! This is wrong, since 'Z' and '+HH:MM'
+                # are supposed to be mutually exclusive.
+                # It's only here to prevent breaking 2.7 beta.
+                z = z[1:]
+
+            if z:
+                fields = zonereg.split(z)
+                hour_off = int(fields[1])
+                min_off  = int(fields[3])
+                if fields[4]:
+                    # Garbage after time zone
+                    raise IndexError
 
         return year,month,day,hour,minute,seconds,'GMT%+03d%02d' % (hour_off,min_off)
 




More information about the Zope-Checkins mailing list