Package caldavclientlibrary :: Package protocol :: Package webdav :: Module principalmatch
[hide private]
[frames] | no frames]

Source Code for Module caldavclientlibrary.protocol.webdav.principalmatch

 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.propfindbase import PropFindBase 
18  from caldavclientlibrary.protocol.webdav.definitions import headers 
19  from caldavclientlibrary.protocol.webdav.definitions import methods 
20  from StringIO import StringIO 
21  from caldavclientlibrary.protocol.http.data.string import RequestDataString 
22  from caldavclientlibrary.protocol.webdav.definitions import davxml 
23  from xml.etree.ElementTree import Element 
24  from xml.etree.ElementTree import SubElement 
25  from caldavclientlibrary.protocol.utils.xmlhelpers import BetterElementTree 
26   
27 -class PrincipalMatch(PropFindBase):
28
29 - def __init__(self, session, url, props):
35
36 - def initRequestData(self):
37 # Write XML info to a string 38 os = StringIO() 39 self.generateXML(os) 40 self.request_data = RequestDataString(os.getvalue(), "text/xml charset=utf-8")
41
42 - def generateXML(self, os):
43 # Structure of document is: 44 # 45 # <DAV:principal-match> 46 # <DAV:self/> 47 # <DAV:prop> 48 # <<names of each property as elements>> 49 # </DAV:prop> 50 # </DAV:principal-match> 51 52 # <DAV:principal-match> element 53 principalmatch = Element(davxml.principal_match) 54 55 # <DAV:self> element 56 SubElement(principalmatch, davxml.self) 57 58 if self.props: 59 60 # <DAV:prop> element 61 prop = SubElement(principalmatch, davxml.prop) 62 63 # Now add each property 64 for item in self.props: 65 66 # Add property element taking namespace into account 67 68 # Look for DAV namespace and reuse that one 69 SubElement(prop, item) 70 71 # Now we have the complete document, so write it out (no indentation) 72 xmldoc = BetterElementTree(principalmatch) 73 xmldoc.writeUTF8(os)
74