| Home | Trees | Indices | Help |
|---|
|
|
1 ## 2 # Copyright (c) 2007-2016 Apple Inc. All rights reserved. 3 # 4 # Licensed under the Apache License, Version 2.0 (the "License"); 5 # you may not use this file except in compliance with the License. 6 # You may obtain a copy of the License at 7 # 8 # http://www.apache.org/licenses/LICENSE-2.0 9 # 10 # Unless required by applicable law or agreed to in writing, software 11 # distributed under the License is distributed on an "AS IS" BASIS, 12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 # See the License for the specific language governing permissions and 14 # limitations under the License. 15 ## 16 17 from StringIO import StringIO 18 from caldavclientlibrary.protocol.carddav.definitions import carddavxml 19 from caldavclientlibrary.protocol.http.data.string import RequestDataString 20 from caldavclientlibrary.protocol.utils.xmlhelpers import BetterElementTree 21 from caldavclientlibrary.protocol.webdav.definitions import davxml, methods 22 from caldavclientlibrary.protocol.webdav.requestresponse import RequestResponse 23 from xml.etree.ElementTree import Element 24 from xml.etree.ElementTree import SubElement 25278029 super(MakeAddressBook, self).__init__(session, methods.MKCOL, url) 30 self.displayname = displayname 31 self.description = description 32 33 self.initRequestData()3436 # Write XML info to a string 37 os = StringIO() 38 self.generateXML(os) 39 self.request_data = RequestDataString(os.getvalue(), "text/xml charset=utf-8")4042 # Structure of document is: 43 # 44 # <WEBDAV:mkcol> 45 # <DAV:set> 46 # <DAV:prop> 47 # <DAV:resourcetype><DAV:collection/><CARDDAV:addressbook/></DAV:resourcetype> 48 # <<each property as elements>> 49 # </DAV:prop> 50 # </DAV:set> 51 # </WEBDAV:mkcol> 52 53 # <CALDAV:mkcalendar> element 54 mkcol = Element(davxml.mkcol) 55 56 # <DAV:set> element 57 set = SubElement(mkcol, davxml.set) 58 59 # <DAV:prop> element 60 prop = SubElement(set, davxml.prop) 61 62 # <WebDAV:resourcetype> element 63 resourcetype = SubElement(prop, davxml.resourcetype) 64 SubElement(resourcetype, davxml.collection) 65 SubElement(resourcetype, carddavxml.addressbook) 66 67 # <DAV:displayname> element 68 if self.displayname: 69 displayname = SubElement(prop, davxml.displayname) 70 displayname.text = self.displayname 71 72 # <CardDAV:addressbook-description> element 73 if self.description: 74 description = SubElement(prop, carddavxml.addressbook_description) 75 description.text = self.description 76 77 # Now we have the complete document, so write it out (no indentation) 78 xmldoc = BetterElementTree(mkcol) 79 xmldoc.writeUTF8(os)
| Home | Trees | Indices | Help |
|---|
| Generated by Epydoc 3.0.1 on Thu Jul 7 15:01:48 2011 | http://epydoc.sourceforge.net |