[CalendarServer-changes] [4215] CalendarServer/trunk/twext/web2
source_changes at macosforge.org
source_changes at macosforge.org
Fri May 8 15:30:44 PDT 2009
Revision: 4215
http://trac.macosforge.org/projects/calendarserver/changeset/4215
Author: wsanchez at apple.com
Date: 2009-05-08 15:30:43 -0700 (Fri, 08 May 2009)
Log Message:
-----------
Add twext.web2.dav.davxml
Added Paths:
-----------
CalendarServer/trunk/twext/web2/dav/
CalendarServer/trunk/twext/web2/dav/__init__.py
CalendarServer/trunk/twext/web2/dav/davxml.py
CalendarServer/trunk/twext/web2/dav/test/
CalendarServer/trunk/twext/web2/dav/test/__init__.py
CalendarServer/trunk/twext/web2/dav/test/test_davxml.py
Added: CalendarServer/trunk/twext/web2/dav/__init__.py
===================================================================
--- CalendarServer/trunk/twext/web2/dav/__init__.py (rev 0)
+++ CalendarServer/trunk/twext/web2/dav/__init__.py 2009-05-08 22:30:43 UTC (rev 4215)
@@ -0,0 +1,19 @@
+##
+# Copyright (c) 2009 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.
+##
+
+"""
+Extentions to twisted.web2.dav
+"""
Added: CalendarServer/trunk/twext/web2/dav/davxml.py
===================================================================
--- CalendarServer/trunk/twext/web2/dav/davxml.py (rev 0)
+++ CalendarServer/trunk/twext/web2/dav/davxml.py 2009-05-08 22:30:43 UTC (rev 4215)
@@ -0,0 +1,62 @@
+##
+# Copyright (c) 2005-2009 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.
+##
+
+"""
+Extensions to twisted.web2.dav.davxml
+"""
+
+__all__ = [
+ "sname2qname",
+ "qname2sname",
+]
+
+def sname2qname(sname):
+ """
+ Convert an sname into a qname.
+
+ That is, parse a property name string (eg: C{"{DAV:}displayname"})
+ into a tuple (eg: C{("DAV:", "displayname")}).
+
+ @raise ValueError is input is not valid. Note, however, that this
+ function does not attempt to fully validate C{sname}.
+ """
+ def raiseIf(condition):
+ if condition:
+ raise ValueError("Invalid sname: %s" % (sname,))
+
+ raiseIf(not sname.startswith("{"))
+
+ try:
+ i = sname.index("}")
+ except ValueError:
+ raiseIf(True)
+
+ namespace = sname[1:i]
+ name = sname [i+1:]
+
+ raiseIf("{" in namespace)
+ raiseIf(not name)
+
+ return namespace, name
+
+def qname2sname(qname):
+ """
+ Convert a qname into an sname.
+ """
+ try:
+ return "{%s}%s" % qname
+ except TypeError:
+ raise ValueError("Invalid qname: %r" % (qname,))
Added: CalendarServer/trunk/twext/web2/dav/test/__init__.py
===================================================================
--- CalendarServer/trunk/twext/web2/dav/test/__init__.py (rev 0)
+++ CalendarServer/trunk/twext/web2/dav/test/__init__.py 2009-05-08 22:30:43 UTC (rev 4215)
@@ -0,0 +1,19 @@
+##
+# Copyright (c) 2009 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.
+##
+
+"""
+Extentions to twisted.web2.dav.test
+"""
Added: CalendarServer/trunk/twext/web2/dav/test/test_davxml.py
===================================================================
--- CalendarServer/trunk/twext/web2/dav/test/test_davxml.py (rev 0)
+++ CalendarServer/trunk/twext/web2/dav/test/test_davxml.py 2009-05-08 22:30:43 UTC (rev 4215)
@@ -0,0 +1,46 @@
+##
+# Copyright (c) 2005-2007 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.
+##
+
+from twext.web2.dav.davxml import *
+
+from twistedcaldav.test.util import TestCase
+
+class XML(TestCase):
+ def test_sname2qname(self):
+ # Empty name
+ self.assertRaises(ValueError, sname2qname, "")
+ self.assertRaises(ValueError, sname2qname, "{}")
+ self.assertRaises(ValueError, sname2qname, "{x}")
+
+ # Weird bracket cases
+ self.assertRaises(ValueError, sname2qname, "{")
+ self.assertRaises(ValueError, sname2qname, "x{")
+ self.assertRaises(ValueError, sname2qname, "{x")
+ self.assertRaises(ValueError, sname2qname, "}")
+ self.assertRaises(ValueError, sname2qname, "x}")
+ self.assertRaises(ValueError, sname2qname, "}x")
+ self.assertRaises(ValueError, sname2qname, "{{}")
+ self.assertRaises(ValueError, sname2qname, "{{}}")
+ self.assertRaises(ValueError, sname2qname, "x{}")
+
+ # Empty namespace is OK
+ self.assertEquals(sname2qname("{}x"), ("", "x"))
+
+ # Normal case
+ self.assertEquals(sname2qname("{namespace}name"), ("namespace", "name"))
+
+ def test_qname2sname(self):
+ self.assertEquals(qname2sname(("namespace", "name")), "{namespace}name")
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20090508/00e8d48f/attachment.html>
More information about the calendarserver-changes
mailing list