[CalendarServer-changes] [12721] PyCalendar/branches/CalendarServer-5.2
source_changes at macosforge.org
source_changes at macosforge.org
Wed Mar 12 11:20:50 PDT 2014
Revision: 12721
http://trac.calendarserver.org//changeset/12721
Author: cdaboo at apple.com
Date: 2014-02-19 11:56:40 -0800 (Wed, 19 Feb 2014)
Log Message:
-----------
Be tolerant of leading spaces instead of zeros in date values.
Modified Paths:
--------------
PyCalendar/branches/CalendarServer-5.2/.pydevproject
PyCalendar/branches/CalendarServer-5.2/src/pycalendar/datetime.py
PyCalendar/branches/CalendarServer-5.2/src/pycalendar/parser.py
PyCalendar/branches/CalendarServer-5.2/src/pycalendar/tests/test_datetime.py
Modified: PyCalendar/branches/CalendarServer-5.2/.pydevproject
===================================================================
--- PyCalendar/branches/CalendarServer-5.2/.pydevproject 2014-02-19 18:57:38 UTC (rev 12720)
+++ PyCalendar/branches/CalendarServer-5.2/.pydevproject 2014-02-19 19:56:40 UTC (rev 12721)
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?eclipse-pydev version="1.0"?><pydev_project>
-<pydev_property name="org.python.pydev.PYTHON_PROJECT_VERSION">python 2.5</pydev_property>
+<pydev_property name="org.python.pydev.PYTHON_PROJECT_VERSION">python 2.7</pydev_property>
<pydev_pathproperty name="org.python.pydev.PROJECT_SOURCE_PATH">
<path>/${PROJECT_DIR_NAME}/src</path>
</pydev_pathproperty>
Modified: PyCalendar/branches/CalendarServer-5.2/src/pycalendar/datetime.py
===================================================================
--- PyCalendar/branches/CalendarServer-5.2/src/pycalendar/datetime.py 2014-02-19 18:57:38 UTC (rev 12720)
+++ PyCalendar/branches/CalendarServer-5.2/src/pycalendar/datetime.py 2014-02-19 19:56:40 UTC (rev 12721)
@@ -19,6 +19,7 @@
from pycalendar import utils
from pycalendar import xmldefs
from pycalendar.duration import PyCalendarDuration
+from pycalendar.parser import ParserContext
from pycalendar.timezone import PyCalendarTimezone
from pycalendar.valueutils import ValueMixin
import cStringIO as StringIO
@@ -960,7 +961,7 @@
self.mDay = int(data[index:index + 2])
index += 2
- if ' ' in data[:index]:
+ if ' ' in data[:index] and ParserContext.INVALID_DATETIME_LEADINGSPACE == ParserContext.PARSER_RAISE:
raise ValueError
if self.mYear < 0 or self.mMonth < 0 or self.mDay < 0:
raise ValueError
Modified: PyCalendar/branches/CalendarServer-5.2/src/pycalendar/parser.py
===================================================================
--- PyCalendar/branches/CalendarServer-5.2/src/pycalendar/parser.py 2014-02-19 18:57:38 UTC (rev 12720)
+++ PyCalendar/branches/CalendarServer-5.2/src/pycalendar/parser.py 2014-02-19 19:56:40 UTC (rev 12721)
@@ -46,6 +46,9 @@
# Allow DATE values when DATETIME specified (and vice versa)
INVALID_DATETIME_VALUE = PARSER_FIX
+ # Allow leading space instead of leading zeros for year in DATE or DATE-TIME values
+ INVALID_DATETIME_LEADINGSPACE = PARSER_ALLOW
+
# Allow slightly invalid DURATION values
INVALID_DURATION_VALUE = PARSER_FIX
Modified: PyCalendar/branches/CalendarServer-5.2/src/pycalendar/tests/test_datetime.py
===================================================================
--- PyCalendar/branches/CalendarServer-5.2/src/pycalendar/tests/test_datetime.py 2014-02-19 18:57:38 UTC (rev 12720)
+++ PyCalendar/branches/CalendarServer-5.2/src/pycalendar/tests/test_datetime.py 2014-02-19 19:56:40 UTC (rev 12721)
@@ -16,11 +16,20 @@
from pycalendar.calendar import PyCalendar
from pycalendar.datetime import PyCalendarDateTime
+from pycalendar.parser import ParserContext
from pycalendar.timezone import PyCalendarTimezone
import unittest
class TestDateTime(unittest.TestCase):
+ def _patch(self, obj, attr, value):
+ oldvalue = getattr(obj, attr)
+ setattr(obj, attr, value)
+ def _restore():
+ setattr(obj, attr, oldvalue)
+ self.addCleanup(_restore)
+
+
def testDuplicateASUTC(self):
items = (
@@ -95,6 +104,8 @@
def testBadParse(self):
+ self._patch(ParserContext, "INVALID_DATETIME_LEADINGSPACE", ParserContext.PARSER_RAISE)
+
data1 = (
"2011",
"201101023",
@@ -128,6 +139,24 @@
self.assertRaises(ValueError, PyCalendarDateTime.parseText, item, False)
+ def testBadParseFixed(self):
+
+ self._patch(ParserContext, "INVALID_DATETIME_LEADINGSPACE", ParserContext.PARSER_ALLOW)
+
+ data = (
+ (" 10102", "00010102"),
+ ("2001 102", "20010102"),
+ ("200101 2", "20010102"),
+ (" 10102T010101", "00010102T010101"),
+ ("2001 102T010101", "20010102T010101"),
+ ("200101 2T010101", "20010102T010101"),
+ )
+
+ for item, result in data:
+ dt = PyCalendarDateTime.parseText(item)
+ self.assertEqual(str(dt), result)
+
+
def testCachePreserveOnAdjustment(self):
# UTC first
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20140312/8580fa02/attachment.html>
More information about the calendarserver-changes
mailing list