msmith - in flumotion/trunk: . flumotion/component/producers/playlist

flumotion-commit at lists.fluendo.com flumotion-commit at lists.fluendo.com
Fri May 18 12:11:09 CEST 2007


Author: msmith
Date: Fri May 18 12:11:00 2007
New Revision: 4981

Modified:
   flumotion/trunk/ChangeLog
   flumotion/trunk/flumotion/component/producers/playlist/playlistparser.py
Log:
        * flumotion/component/producers/playlist/playlistparser.py:
          Parse timestamps correctly in the format we defined.
          Specifically: require and parse the fractional seconds part (it is
          discarded, however; we only schedule on whole second boundaries),
          and parse as UTC, not local time.



Modified: flumotion/trunk/ChangeLog
==============================================================================
--- flumotion/trunk/ChangeLog	(original)
+++ flumotion/trunk/ChangeLog	Fri May 18 12:11:00 2007
@@ -1,3 +1,11 @@
+2007-05-18  Michael Smith <msmith at fluendo.com>
+
+	* flumotion/component/producers/playlist/playlistparser.py:
+	  Parse timestamps correctly in the format we defined.
+	  Specifically: require and parse the fractional seconds part (it is
+	  discarded, however; we only schedule on whole second boundaries),
+	  and parse as UTC, not local time.
+
 2007-05-17  Michael Smith <msmith at fluendo.com>
 
 	* flumotion/component/producers/playlist/playlistparser.py:

Modified: flumotion/trunk/flumotion/component/producers/playlist/playlistparser.py
==============================================================================
--- flumotion/trunk/flumotion/component/producers/playlist/playlistparser.py	(original)
+++ flumotion/trunk/flumotion/component/producers/playlist/playlistparser.py	Fri May 18 12:11:00 2007
@@ -23,6 +23,7 @@
 from gst.extend import discoverer
 
 import time
+import calendar
 from StringIO import StringIO
 
 from xml.dom import Node
@@ -288,14 +289,20 @@
         self.addItemToPlaylist(filename, timestamp, duration, offset, id)
 
     def _parseTimestamp(self, ts):
-        # Take TS in YYYY-MM-DDThh:mm:ssZ format, return timestamp in 
+        # Take TS in YYYY-MM-DDThh:mm:ss.ssZ format, return timestamp in 
         # nanoseconds since the epoch
-        format = "%Y-%m-%dT%H:%M:%SZ"
 
-        try:
-            timestruct = time.strptime(ts, format)
+        # time.strptime() doesn't handle the fractional seconds part. We ignore
+        # it entirely, after verifying that it has the right format.
+        tsmain, trailing = ts[:-4], ts[-4:]
+        if trailing[0] != '.' or trailing[3] != 'Z' or \
+                not trailing[1].isdigit() or not trailing[2].isdigit():
+            raise fxml.ParserError("Invalid timestamp %s", ts)
+        format = "%Y-%m-%dT%H:%M:%S"
 
-            return int(time.mktime(timestruct) * gst.SECOND)
+        try:
+            timestruct = time.strptime(tsmain, format)
+            return int(calendar.timegm(timestruct) * gst.SECOND)
         except ValueError:
             raise fxml.ParserError("Invalid timestamp %s", ts)
 


More information about the flumotion-commit mailing list