Package caldavclientlibrary :: Package protocol :: Package caldav :: Module multiget
[hide private]
[frames] | no frames]

Source Code for Module caldavclientlibrary.protocol.caldav.multiget

 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 caldavclientlibrary.protocol.webdav.report import Report 
18  from StringIO import StringIO 
19  from caldavclientlibrary.protocol.http.data.string import RequestDataString 
20  from caldavclientlibrary.protocol.caldav.definitions import caldavxml 
21  from xml.etree.ElementTree import Element 
22  from xml.etree.ElementTree import SubElement 
23  from caldavclientlibrary.protocol.webdav.definitions import davxml 
24  from caldavclientlibrary.protocol.utils.xmlhelpers import BetterElementTree 
25   
26 -class Multiget(Report):
27
28 - def __init__(self, session, url, hrefs, props=()):
29 super(Multiget, self).__init__(session, url) 30 self.props = props 31 self.hrefs = hrefs 32 pass
33
34 - def initRequestData(self):
35 if self.displayname or self.description or self.timezone: 36 # 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")
40
41 - def generateXML(self, os):
42 # Structure of document is: 43 # 44 # <CalDAV:calendar-multiget> 45 # <DAV:prop> 46 # <<names of each property as elements>> 47 # </DAV:prop> 48 # <DAV:href>...</DAV:href> 49 # ... 50 # </CalDAV:calendar-multiget> 51 52 # <CalDAV:calendar-multiget> element 53 multiget = Element(caldavxml.calendar_multiget) 54 55 if self.props: 56 # <DAV:prop> element 57 prop = SubElement(multiget, davxml.prop) 58 59 # Now add each property 60 for propname in self.props: 61 # Add property element taking namespace into account 62 SubElement(prop, propname) 63 64 # Now add each href 65 for href in self.hrefs: 66 # Add href elements 67 SubElement(multiget, davxml.href).text = href 68 69 # Now we have the complete document, so write it out (no indentation) 70 xmldoc = BetterElementTree(multiget) 71 xmldoc.writeUTF8(os)
72