[CalendarServer-changes] [14224] PyCalendar/trunk/src/pycalendar
source_changes at macosforge.org
source_changes at macosforge.org
Thu Dec 11 13:15:58 PST 2014
Revision: 14224
http://trac.calendarserver.org//changeset/14224
Author: cdaboo at apple.com
Date: 2014-12-11 13:15:58 -0800 (Thu, 11 Dec 2014)
Log Message:
-----------
Automatically fix broken GEO property values.
Modified Paths:
--------------
PyCalendar/trunk/src/pycalendar/geovalue.py
PyCalendar/trunk/src/pycalendar/parser.py
Added Paths:
-----------
PyCalendar/trunk/src/pycalendar/tests/test_geovalue.py
Modified: PyCalendar/trunk/src/pycalendar/geovalue.py
===================================================================
--- PyCalendar/trunk/src/pycalendar/geovalue.py 2014-12-11 19:54:56 UTC (rev 14223)
+++ PyCalendar/trunk/src/pycalendar/geovalue.py 2014-12-11 21:15:58 UTC (rev 14224)
@@ -52,7 +52,13 @@
try:
self.mValue = [float(splits[0]), float(splits[1])]
except ValueError:
- raise InvalidData("GEO value incorrect", data)
+ if splits[0][-1] == '\\':
+ try:
+ self.mValue = [float(splits[0][:-1]), float(splits[1])]
+ except ValueError:
+ raise InvalidData("GEO value incorrect", data)
+ else:
+ raise InvalidData("GEO value incorrect", data)
# os - StringIO object
Modified: PyCalendar/trunk/src/pycalendar/parser.py
===================================================================
--- PyCalendar/trunk/src/pycalendar/parser.py 2014-12-11 19:54:56 UTC (rev 14223)
+++ PyCalendar/trunk/src/pycalendar/parser.py 2014-12-11 21:15:58 UTC (rev 14224)
@@ -61,6 +61,9 @@
# Remove \-escaping in URI values when parsing - only PARSER_FIX or PARSER_ALLOW
BACKSLASH_IN_URI_VALUE = PARSER_FIX
+ # Remove \-escaping in GEO values when parsing - only PARSER_FIX
+ BACKSLASH_IN_GEO_VALUE = PARSER_FIX
+
@staticmethod
def allRaise():
"""
@@ -75,4 +78,5 @@
ParserContext.INVALID_ADR_N_VALUES = ParserContext.PARSER_RAISE
ParserContext.INVALID_REQUEST_STATUS_VALUE = ParserContext.PARSER_RAISE
ParserContext.BACKSLASH_IN_URI_VALUE = ParserContext.PARSER_RAISE
+ ParserContext.BACKSLASH_IN_GEO_VALUE = ParserContext.PARSER_RAISE
ParserContext.INVALID_REQUEST_STATUS = ParserContext.PARSER_RAISE
Added: PyCalendar/trunk/src/pycalendar/tests/test_geovalue.py
===================================================================
--- PyCalendar/trunk/src/pycalendar/tests/test_geovalue.py (rev 0)
+++ PyCalendar/trunk/src/pycalendar/tests/test_geovalue.py 2014-12-11 21:15:58 UTC (rev 14224)
@@ -0,0 +1,47 @@
+##
+# Copyright (c) 2012-2013 Cyrus Daboo. 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.
+##
+
+from pycalendar.geovalue import GeoValue
+from pycalendar.icalendar.property import Property
+import unittest
+
+class TestURIValue(unittest.TestCase):
+
+ def testParseValue(self):
+
+ items = (
+ ("-12.345;67.890", "-12.345;67.89"),
+ ("-12.345\\;67.890", "-12.345;67.89"),
+ )
+
+ for item, result in items:
+ req = GeoValue()
+ req.parse(item, "icalendar")
+ test = req.getText()
+ self.assertEqual(test, result, "Failed to parse and re-generate '%s'" % (item,))
+
+
+ def testParseProperty(self):
+
+ items = (
+ ("GEO:-12.345;67.890", "GEO:-12.345;67.89"),
+ ("GEO:-12.345\\;67.890", "GEO:-12.345;67.89"),
+ )
+
+ for item, result in items:
+ prop = Property.parseText(item)
+ test = prop.getText()
+ self.assertEqual(test, result + "\r\n", "Failed to parse and re-generate '%s'" % (item,))
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20141211/0fee3688/attachment.html>
More information about the calendarserver-changes
mailing list