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

Source Code for Module caldavclientlibrary.client.httpshandler

 1  ## 
 2  # Copyright (c) 2010-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  import httplib 
18  import socket 
19  import ssl as sslmodule 
20   
21 -class HTTPSConnection_SSLv3(httplib.HTTPSConnection):
22 "This class allows communication via SSL." 23
24 - def connect(self):
25 "Connect to a host on a given (SSL) port." 26 27 sock = socket.create_connection((self.host, self.port), self.timeout) 28 self.sock = sslmodule.wrap_socket(sock, self.key_file, self.cert_file, ssl_version=sslmodule.PROTOCOL_SSLv3)
29 30 https_v23_connects = set() 31 https_v3_connects = set() 32
33 -def SmartHTTPConnection(host, port, ssl):
34 35 def trySSL(cls, ): 36 connect = cls(host, port) 37 connect.connect() 38 return connect
39 40 if ssl: 41 if (host, port) in https_v3_connects: 42 try: 43 return trySSL(HTTPSConnection_SSLv3) 44 except: 45 https_v3_connects.remove((host, port)) 46 elif (host, port) in https_v23_connects: 47 try: 48 return trySSL(httplib.HTTPSConnection) 49 except: 50 https_v23_connects.remove((host, port)) 51 52 try: 53 https_v3_connects.add((host, port)) 54 return trySSL(HTTPSConnection_SSLv3) 55 except: 56 https_v3_connects.remove((host, port)) 57 58 try: 59 https_v23_connects.add((host, port)) 60 return trySSL(httplib.HTTPSConnection) 61 except: 62 https_v23_connects.remove((host, port)) 63 64 raise RuntimeError("Cannot connect via with SSLv23 or SSLv3") 65 else: 66 connect = httplib.HTTPConnection(host, port) 67 connect.connect() 68 return connect 69