[CalendarServer-changes] [7415] CalDAVClientLibrary/trunk/src

source_changes at macosforge.org source_changes at macosforge.org
Thu May 5 12:30:13 PDT 2011


Revision: 7415
          http://trac.macosforge.org/projects/calendarserver/changeset/7415
Author:   cdaboo at apple.com
Date:     2011-05-05 12:30:12 -0700 (Thu, 05 May 2011)
Log Message:
-----------
Add an mkadbk command for CardDAV.

Modified Paths:
--------------
    CalDAVClientLibrary/trunk/src/browser/commands/__init__.py
    CalDAVClientLibrary/trunk/src/client/clientsession.py
    CalDAVClientLibrary/trunk/src/protocol/webdav/definitions/davxml.py

Added Paths:
-----------
    CalDAVClientLibrary/trunk/src/browser/commands/mkadbk.py
    CalDAVClientLibrary/trunk/src/protocol/carddav/
    CalDAVClientLibrary/trunk/src/protocol/carddav/__init__.py
    CalDAVClientLibrary/trunk/src/protocol/carddav/definitions/
    CalDAVClientLibrary/trunk/src/protocol/carddav/definitions/__init__.py
    CalDAVClientLibrary/trunk/src/protocol/carddav/definitions/carddavxml.py
    CalDAVClientLibrary/trunk/src/protocol/carddav/makeaddressbook.py

Modified: CalDAVClientLibrary/trunk/src/browser/commands/__init__.py
===================================================================
--- CalDAVClientLibrary/trunk/src/browser/commands/__init__.py	2011-05-05 17:45:32 UTC (rev 7414)
+++ CalDAVClientLibrary/trunk/src/browser/commands/__init__.py	2011-05-05 19:30:12 UTC (rev 7415)
@@ -1,5 +1,5 @@
 ##
-# Copyright (c) 2007-2010 Apple Inc. All rights reserved.
+# Copyright (c) 2007-2011 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.
@@ -22,6 +22,7 @@
     "history",
     "logging",
     "ls",
+    "mkadbk",
     "mkcal",
     "mkdir",
     "mv",

Added: CalDAVClientLibrary/trunk/src/browser/commands/mkadbk.py
===================================================================
--- CalDAVClientLibrary/trunk/src/browser/commands/mkadbk.py	                        (rev 0)
+++ CalDAVClientLibrary/trunk/src/browser/commands/mkadbk.py	2011-05-05 19:30:12 UTC (rev 7415)
@@ -0,0 +1,65 @@
+##
+# Copyright (c) 2007-2010 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 browser.command import Command
+from browser.command import WrongOptions
+from protocol.url import URL
+import getopt
+import os
+import shlex
+
+class Cmd(Command):
+    
+    def __init__(self):
+        super(Command, self).__init__()
+        self.cmds = ("mkadbk",)
+        
+    def execute(self, name, options):
+
+        opts, args = getopt.getopt(shlex.split(options), '')
+
+        for name, _ignore_value in opts:
+            
+            print "Unknown option: %s" % (name,)
+            print self.usage(name)
+            raise WrongOptions
+        
+        if len(args) != 1:
+            print "Wrong number of arguments: %d" % (len(args),)
+            print self.usage(name)
+            raise WrongOptions
+
+        path = args[0]
+        if not path.startswith("/"):
+            path = os.path.join(self.shell.wd, path)
+        if not path.endswith("/"):
+            path += "/"
+
+        resource = URL(url=path)
+        self.shell.account.session.makeAddressBook(resource)
+        return True
+
+    def complete(self, text):
+        return self.shell.wdcomplete(text)
+
+    def usage(self, name):
+        return """Usage: %s PATH
+PATH is a relative or absolute path.
+
+""" % (name,)
+
+    def helpDescription(self):
+        return "Creates an address book collection."

Modified: CalDAVClientLibrary/trunk/src/client/clientsession.py
===================================================================
--- CalDAVClientLibrary/trunk/src/client/clientsession.py	2011-05-05 17:45:32 UTC (rev 7414)
+++ CalDAVClientLibrary/trunk/src/client/clientsession.py	2011-05-05 19:30:12 UTC (rev 7415)
@@ -1,5 +1,5 @@
 ##
-# Copyright (c) 2006-2010 Apple Inc. All rights reserved.
+# Copyright (c) 2006-2011 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.
@@ -17,6 +17,7 @@
 from client.httpshandler import SmartHTTPConnection
 from protocol.caldav.definitions import headers
 from protocol.caldav.makecalendar import MakeCalendar
+from protocol.carddav.makeaddressbook import MakeAddressBook
 from protocol.http.authentication.basic import Basic
 from protocol.http.authentication.digest import Digest
 try:
@@ -462,6 +463,19 @@
         if request.getStatusCode() not in (statuscodes.OK, statuscodes.Created, statuscodes.NoContent):
             self.handleHTTPError(request)
 
+    def makeAddressBook(self, rurl, displayname=None, description=None):
+        
+        assert(isinstance(rurl, URL))
+
+        # Create WebDAV extended MKCOL
+        request = MakeAddressBook(self, rurl.relativeURL(), displayname, description)
+    
+        # Process it
+        self.runSession(request)
+        
+        if request.getStatusCode() not in (statuscodes.OK, statuscodes.Created, statuscodes.NoContent):
+            self.handleHTTPError(request)
+
     def deleteResource(self, rurl):
         
         assert(isinstance(rurl, URL))

Added: CalDAVClientLibrary/trunk/src/protocol/carddav/__init__.py
===================================================================
--- CalDAVClientLibrary/trunk/src/protocol/carddav/__init__.py	                        (rev 0)
+++ CalDAVClientLibrary/trunk/src/protocol/carddav/__init__.py	2011-05-05 19:30:12 UTC (rev 7415)
@@ -0,0 +1,15 @@
+##
+# Copyright (c) 2007-2011 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.
+##

Added: CalDAVClientLibrary/trunk/src/protocol/carddav/definitions/__init__.py
===================================================================
--- CalDAVClientLibrary/trunk/src/protocol/carddav/definitions/__init__.py	                        (rev 0)
+++ CalDAVClientLibrary/trunk/src/protocol/carddav/definitions/__init__.py	2011-05-05 19:30:12 UTC (rev 7415)
@@ -0,0 +1,15 @@
+##
+# Copyright (c) 2007-2011 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.
+##

Added: CalDAVClientLibrary/trunk/src/protocol/carddav/definitions/carddavxml.py
===================================================================
--- CalDAVClientLibrary/trunk/src/protocol/carddav/definitions/carddavxml.py	                        (rev 0)
+++ CalDAVClientLibrary/trunk/src/protocol/carddav/definitions/carddavxml.py	2011-05-05 19:30:12 UTC (rev 7415)
@@ -0,0 +1,45 @@
+##
+# Copyright (c) 2007-2011 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 xml.etree.ElementTree import QName
+
+CardDAVNamespace = "urn:ietf:params:xml:ns:carddav"
+
+# draft-
+
+addressbook                      = QName(CardDAVNamespace, "addressbook")
+
+addressbook_description          = QName(CardDAVNamespace, "addressbook-description")
+supported_addressbook_data       = QName(CardDAVNamespace, "supported-addressbook-data")
+max_resource_size                = QName(CardDAVNamespace, "max-resource-size")
+
+addressbook_home_set    = QName(CardDAVNamespace, "addressbook-home-set")
+
+supported_collation  = QName(CardDAVNamespace, "supported-collation")
+
+addressbook_query    = QName(CardDAVNamespace, "addressbook-query")
+address_data         = QName(CardDAVNamespace, "address-data")
+comp                 = QName(CardDAVNamespace, "comp")
+allcomp              = QName(CardDAVNamespace, "allcomp")
+prop                 = QName(CardDAVNamespace, "prop")
+filter               = QName(CardDAVNamespace, "filter")
+comp_filter          = QName(CardDAVNamespace, "comp-filter")
+prop_filter          = QName(CardDAVNamespace, "prop-filter")
+param_filter         = QName(CardDAVNamespace, "param-filter")
+is_not_defined       = QName(CardDAVNamespace, "is-not-defined")
+text_match           = QName(CardDAVNamespace, "text-match")
+
+addressbook_multiget = QName(CardDAVNamespace, "addressbook-multiget")

Added: CalDAVClientLibrary/trunk/src/protocol/carddav/makeaddressbook.py
===================================================================
--- CalDAVClientLibrary/trunk/src/protocol/carddav/makeaddressbook.py	                        (rev 0)
+++ CalDAVClientLibrary/trunk/src/protocol/carddav/makeaddressbook.py	2011-05-05 19:30:12 UTC (rev 7415)
@@ -0,0 +1,79 @@
+##
+# Copyright (c) 2007-2011 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 StringIO import StringIO
+from protocol.carddav.definitions import carddavxml
+from protocol.http.data.string import RequestDataString
+from protocol.utils.xmlhelpers import BetterElementTree
+from protocol.webdav.definitions import davxml, methods
+from protocol.webdav.requestresponse import RequestResponse
+from xml.etree.ElementTree import Element
+from xml.etree.ElementTree import SubElement
+
+class MakeAddressBook(RequestResponse):
+
+    def __init__(self, session, url, displayname=None, description=None):
+        super(MakeAddressBook, self).__init__(session, methods.MKCOL, url)
+        self.displayname = displayname
+        self.description = description
+        
+        self.initRequestData()
+
+    def initRequestData(self):
+        # Write XML info to a string
+        os = StringIO()
+        self.generateXML(os)
+        self.request_data = RequestDataString(os.getvalue(), "text/xml charset=utf-8")
+    
+    def generateXML(self, os):
+        # Structure of document is:
+        #
+        # <WEBDAV:mkcol>
+        #   <DAV:set>
+        #     <DAV:prop>
+        #       <DAV:resourcetype><DAV:collection/><CARDDAV:addressbook/></DAV:resourcetype>
+        #       <<each property as elements>>
+        #     </DAV:prop>
+        #   </DAV:set>
+        # </WEBDAV:mkcol>
+
+        # <CALDAV:mkcalendar> element
+        mkcol = Element(davxml.mkcol)
+
+        # <DAV:set> element
+        set = SubElement(mkcol, davxml.set)
+        
+        # <DAV:prop> element
+        prop = SubElement(set, davxml.prop)
+        
+        # <WebDAV:resourcetype> element
+        resourcetype = SubElement(prop, davxml.resourcetype)
+        SubElement(resourcetype, davxml.collection)
+        SubElement(resourcetype, carddavxml.addressbook)
+        
+        # <DAV:displayname> element
+        if self.displayname:
+            displayname = SubElement(prop, davxml.displayname)
+            displayname.text = self.displayname
+        
+        # <CardDAV:addressbook-description> element
+        if self.description:
+            description = SubElement(prop, carddavxml.addressbook_description)
+            description.text = self.description
+        
+        # Now we have the complete document, so write it out (no indentation)
+        xmldoc = BetterElementTree(mkcol)
+        xmldoc.writeUTF8(os)

Modified: CalDAVClientLibrary/trunk/src/protocol/webdav/definitions/davxml.py
===================================================================
--- CalDAVClientLibrary/trunk/src/protocol/webdav/definitions/davxml.py	2011-05-05 17:45:32 UTC (rev 7414)
+++ CalDAVClientLibrary/trunk/src/protocol/webdav/definitions/davxml.py	2011-05-05 19:30:12 UTC (rev 7415)
@@ -1,5 +1,5 @@
 ##
-# Copyright (c) 2007-2009 Apple Inc. All rights reserved.
+# Copyright (c) 2007-2011 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.
@@ -91,3 +91,6 @@
 quota_used_bytes      = QName(DAVNamespace, "quota-used-bytes")
 
 current_user_principal = QName(DAVNamespace, "current-user-principal")
+
+mkcol          = QName(DAVNamespace, "mkcol")
+mkcol_response = QName(DAVNamespace, "mkcol-response")
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20110505/b7a784e5/attachment-0001.html>


More information about the calendarserver-changes mailing list