[CalendarServer-changes] [10265] CalendarServer/branches/users/glyph/queue-locking-and-timing
source_changes at macosforge.org
source_changes at macosforge.org
Fri Jan 4 16:39:30 PST 2013
Revision: 10265
http://trac.calendarserver.org//changeset/10265
Author: glyph at apple.com
Date: 2013-01-04 16:39:30 -0800 (Fri, 04 Jan 2013)
Log Message:
-----------
Un-invert SQL date parsing dependency.
Modified Paths:
--------------
CalendarServer/branches/users/glyph/queue-locking-and-timing/twext/enterprise/util.py
CalendarServer/branches/users/glyph/queue-locking-and-timing/twistedcaldav/dateops.py
CalendarServer/branches/users/glyph/queue-locking-and-timing/twistedcaldav/test/test_dateops.py
CalendarServer/branches/users/glyph/queue-locking-and-timing/txdav/caldav/datastore/sql.py
CalendarServer/branches/users/glyph/queue-locking-and-timing/txdav/common/datastore/sql.py
Added Paths:
-----------
CalendarServer/branches/users/glyph/queue-locking-and-timing/twext/enterprise/test/test_util.py
Property Changed:
----------------
CalendarServer/branches/users/glyph/queue-locking-and-timing/
Added: CalendarServer/branches/users/glyph/queue-locking-and-timing/twext/enterprise/test/test_util.py
===================================================================
--- CalendarServer/branches/users/glyph/queue-locking-and-timing/twext/enterprise/test/test_util.py (rev 0)
+++ CalendarServer/branches/users/glyph/queue-locking-and-timing/twext/enterprise/test/test_util.py 2013-01-05 00:39:30 UTC (rev 10265)
@@ -0,0 +1,38 @@
+##
+# Copyright (c) 2012 Apple Inc. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+##
+
+import datetime
+
+from twisted.python.unittest import TestCase
+
+from twext.enterprise.util import parseSQLTimestamp
+
+class TimestampTests(TestCase):
+ """
+ Tests for date-related functions.
+ """
+
+ def test_parseSQLTimestamp(self):
+ """
+ L{parseSQLTimestamp} parses the traditional SQL timestamp.
+ """
+ tests = (
+ ("2012-04-04 12:34:56", datetime.datetime(2012, 4, 4, 12, 34, 56)),
+ ("2012-12-31 01:01:01", datetime.datetime(2012, 12, 31, 1, 1, 1)),
+ )
+
+ for sqlStr, result in tests:
+ self.assertEqual(parseSQLTimestamp(sqlStr), result)
Modified: CalendarServer/branches/users/glyph/queue-locking-and-timing/twext/enterprise/util.py
===================================================================
--- CalendarServer/branches/users/glyph/queue-locking-and-timing/twext/enterprise/util.py 2013-01-05 00:39:27 UTC (rev 10264)
+++ CalendarServer/branches/users/glyph/queue-locking-and-timing/twext/enterprise/util.py 2013-01-05 00:39:30 UTC (rev 10265)
@@ -1,4 +1,4 @@
-
+# -*- test-case-name: twext.enterprise.test.test_util -*-
##
# Copyright (c) 2010-2012 Apple Inc. All rights reserved.
#
@@ -20,8 +20,22 @@
"""
from datetime import datetime
-from twistedcaldav.dateops import SQL_TIMESTAMP_FORMAT
+SQL_TIMESTAMP_FORMAT = "%Y-%m-%d %H:%M:%S.%f"
+
+
+
+def parseSQLTimestamp(ts):
+ """
+ Parse an SQL timestamp string.
+ """
+ # Handle case where fraction seconds may not be present
+ if len(ts) < len(SQL_TIMESTAMP_FORMAT):
+ ts += ".0"
+ return datetime.datetime.strptime(ts, SQL_TIMESTAMP_FORMAT)
+
+
+
def mapOracleOutputType(column):
"""
Map a single output value from cx_Oracle based on some rules and
Modified: CalendarServer/branches/users/glyph/queue-locking-and-timing/twistedcaldav/dateops.py
===================================================================
--- CalendarServer/branches/users/glyph/queue-locking-and-timing/twistedcaldav/dateops.py 2013-01-05 00:39:27 UTC (rev 10264)
+++ CalendarServer/branches/users/glyph/queue-locking-and-timing/twistedcaldav/dateops.py 2013-01-05 00:39:30 UTC (rev 10265)
@@ -13,11 +13,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
##
-from pycalendar.datetime import PyCalendarDateTime
-from pycalendar.timezone import PyCalendarTimezone
-from pycalendar.period import PyCalendarPeriod
-import datetime
-import dateutil.tz
"""
Date/time Utilities
@@ -33,6 +28,13 @@
"clipPeriod"
]
+from pycalendar.datetime import PyCalendarDateTime
+from pycalendar.timezone import PyCalendarTimezone
+from pycalendar.period import PyCalendarPeriod
+
+import datetime
+import dateutil.tz
+
import calendar
def normalizeForIndex(dt):
@@ -259,14 +261,6 @@
tzinfo=dateutil.tz.tzutc()
)
-SQL_TIMESTAMP_FORMAT = "%Y-%m-%d %H:%M:%S.%f"
-
-def parseSQLTimestamp(ts):
- # Handle case where fraction seconds may not be present
- if len(ts) < 20:
- ts += ".0"
- return datetime.datetime.strptime(ts, SQL_TIMESTAMP_FORMAT)
-
def parseSQLTimestampToPyCalendar(ts):
"""
Parse an SQL formated timestamp into a PyCalendarDateTime
Modified: CalendarServer/branches/users/glyph/queue-locking-and-timing/twistedcaldav/test/test_dateops.py
===================================================================
--- CalendarServer/branches/users/glyph/queue-locking-and-timing/twistedcaldav/test/test_dateops.py 2013-01-05 00:39:27 UTC (rev 10264)
+++ CalendarServer/branches/users/glyph/queue-locking-and-timing/twistedcaldav/test/test_dateops.py 2013-01-05 00:39:30 UTC (rev 10265)
@@ -17,9 +17,11 @@
import twistedcaldav.test.util
from twisted.trial.unittest import SkipTest
from pycalendar.datetime import PyCalendarDateTime
+
from twistedcaldav.dateops import parseSQLTimestampToPyCalendar,\
- parseSQLDateToPyCalendar, parseSQLTimestamp, pyCalendarTodatetime,\
+ parseSQLDateToPyCalendar, pyCalendarTodatetime,\
normalizeForExpand, normalizeForIndex, normalizeToUTC, timeRangesOverlap
+
import datetime
import dateutil
from pycalendar.timezone import PyCalendarTimezone
@@ -241,11 +243,11 @@
def test_clipPeriod(self):
raise SkipTest("test unimplemented")
+
def test_pyCalendarTodatetime(self):
"""
dateops.pyCalendarTodatetime
"""
-
tests = (
(PyCalendarDateTime(2012, 4, 4, 12, 34, 56), datetime.datetime(2012, 4, 4, 12, 34, 56, tzinfo=dateutil.tz.tzutc())),
(PyCalendarDateTime(2012, 12, 31), datetime.date(2012, 12, 31)),
@@ -254,24 +256,11 @@
for pycal, result in tests:
self.assertEqual(pyCalendarTodatetime(pycal), result)
- def test_parseSQLTimestamp(self):
- """
- dateops.parseSQLTimestamp
- """
-
- tests = (
- ("2012-04-04 12:34:56", datetime.datetime(2012, 4, 4, 12, 34, 56)),
- ("2012-12-31 01:01:01", datetime.datetime(2012, 12, 31, 1, 1, 1)),
- )
- for sqlStr, result in tests:
- self.assertEqual(parseSQLTimestamp(sqlStr), result)
-
def test_parseSQLTimestampToPyCalendar(self):
"""
dateops.parseSQLTimestampToPyCalendar
"""
-
tests = (
("2012-04-04 12:34:56", PyCalendarDateTime(2012, 4, 4, 12, 34, 56)),
("2012-12-31 01:01:01", PyCalendarDateTime(2012, 12, 31, 1, 1, 1)),
Modified: CalendarServer/branches/users/glyph/queue-locking-and-timing/txdav/caldav/datastore/sql.py
===================================================================
--- CalendarServer/branches/users/glyph/queue-locking-and-timing/txdav/caldav/datastore/sql.py 2013-01-05 00:39:27 UTC (rev 10264)
+++ CalendarServer/branches/users/glyph/queue-locking-and-timing/txdav/caldav/datastore/sql.py 2013-01-05 00:39:30 UTC (rev 10265)
@@ -32,6 +32,9 @@
from twext.enterprise.dal.syntax import Select, Count, ColumnSyntax
from twext.enterprise.dal.syntax import Update
from twext.enterprise.dal.syntax import utcNowSQL
+
+from twext.enterprise.util import parseSQLTimestamp
+
from twext.python.clsprop import classproperty
from twext.python.filepath import CachingFilePath
from twext.python.vcomponent import VComponent
@@ -45,7 +48,7 @@
from twistedcaldav.caldavxml import ScheduleCalendarTransp, Opaque
from twistedcaldav.config import config
from twistedcaldav.dateops import normalizeForIndex, datetimeMktime, \
- parseSQLTimestamp, pyCalendarTodatetime, parseSQLDateToPyCalendar
+ pyCalendarTodatetime, parseSQLDateToPyCalendar
from twistedcaldav.ical import Component, InvalidICalendarDataError, Property
from twistedcaldav.instance import InvalidOverriddenInstanceError
from twistedcaldav.memcacher import Memcacher
Modified: CalendarServer/branches/users/glyph/queue-locking-and-timing/txdav/common/datastore/sql.py
===================================================================
--- CalendarServer/branches/users/glyph/queue-locking-and-timing/txdav/common/datastore/sql.py 2013-01-05 00:39:27 UTC (rev 10264)
+++ CalendarServer/branches/users/glyph/queue-locking-and-timing/txdav/common/datastore/sql.py 2013-01-05 00:39:30 UTC (rev 10265)
@@ -84,11 +84,11 @@
from txdav.common.icommondatastore import ConcurrentModification
from twistedcaldav.customxml import NotificationType
-from twistedcaldav.dateops import datetimeMktime, parseSQLTimestamp, \
- pyCalendarTodatetime
+from twistedcaldav.dateops import datetimeMktime, pyCalendarTodatetime
from txdav.base.datastore.util import normalizeUUIDOrNot
from twext.enterprise.queue import NullQueuer
+from twext.enterprise.util import parseSQLTimestamp
from pycalendar.datetime import PyCalendarDateTime
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20130104/0c62971f/attachment-0001.html>
More information about the calendarserver-changes
mailing list