| Home | Trees | Indices | Help |
|---|
|
|
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 httplib import InvalidURL 18 import httplib 1921 22 STATE_OPEN = 0 23 STATE_CLOSED = 1 2412226 27 self.server = server 28 self.port = port 29 self.ssl = ssl 30 if not self.port: 31 self.port = httplib.HTTPS_PORT if ssl else httplib.HTTP_PORT 32 self.authorization = None 33 self.connection_state = Session.STATE_CLOSED 34 self.log = log3537 return self.authorization != None3840 return self.authorization41 4547 48 if port is None: 49 i = server.rfind(':') 50 j = server.rfind(']') 51 if i > j: 52 try: 53 port = int(server[i+1:]) 54 except ValueError: 55 raise InvalidURL("nonnumeric port: '%s'" % server[i+1:]) 56 server = server[:i] 57 else: 58 port = httplib.HTTPS_PORT if self.ssl else httplib.HTTP_PORT 59 if server and server[0] == '[' and server[-1] == ']': 60 server = server[1:-1] 61 62 if self.server != server: 63 self.server = server 64 self.port = port 65 66 # Always clear out authorization when host changes 67 self.authorization = None6870 try: 71 72 # First need a connection 73 self.needConnection(); 74 75 # Now do the connection 76 self.doRequest(request); 77 78 # Check the final connection state and close if that's what the server wants 79 if request.getConnectionClose(): 80 self.closeConnection() 81 82 except Exception: 83 84 # log.err(e) 85 self.connection_state = Session.STATE_CLOSED 86 raise87 90 93 96 100102 if not self.isConnectionOpen(): 103 self.openSession() 104 self.connection_state = Session.STATE_OPEN105107 if self.isConnectionOpen(): 108 self.closeSession(); 109 self.connection_state = Session.STATE_CLOSED110 113 116 119
| Home | Trees | Indices | Help |
|---|
| Generated by Epydoc 3.0.1 on Thu Jul 7 15:01:48 2011 | http://epydoc.sourceforge.net |