Package caldavclientlibrary :: Package client :: Module simple
[hide private]
[frames] | no frames]

Source Code for Module caldavclientlibrary.client.simple

 1  ## 
 2  # Copyright (c) 2006-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.client.httpshandler import SmartHTTPConnection 
18  from caldavclientlibrary.protocol.webdav.session import Session 
19  from caldavclientlibrary.protocol.webdav.options import Options 
20   
21 -def run(session, request):
22 23 # Create connection 24 connect = SmartHTTPConnection(session.server, session.port, session.ssl) 25 connect.set_debuglevel(1) 26 27 # Do headers 28 connect.putrequest(request.method, request.url, skip_host=True, skip_accept_encoding=True) 29 hdrs = request.getRequestHeaders() 30 for header, value in hdrs.iteritems(): 31 connect.putheader(header, value) 32 connect.endheaders() 33 34 # Do request body 35 stream = request.getRequestDataStream() 36 if stream: 37 stream.start() 38 more = True 39 while more: 40 data, more = stream.read() 41 if data: 42 connect.send(data) 43 stream.stop() 44 45 # Get response 46 response = connect.getresponse() 47 48 # Get response headers 49 request.setResponseStatus(response.version, response.status, response.reason) 50 request.setResponseHeaders(response.getheaders())
51 52 # Get response body 53 54 if __name__ == '__main__': 55 session = Session("www.mulberrymail.com") 56 request = Options(session, "/") 57 58 run(session, request) 59