Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(77874)

Delta Between Two Patch Sets: Lib/http/client.py

Issue 19689: ssl.create_default_context()
Left Patch Set: Created 5 years, 7 months ago
Right Patch Set: Created 5 years, 7 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « Lib/ftplib.py ('k') | Lib/imaplib.py » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 """HTTP/1.1 client library 1 """HTTP/1.1 client library
2 2
3 <intro stuff goes here> 3 <intro stuff goes here>
4 <other stuff, too> 4 <other stuff, too>
5 5
6 HTTPConnection goes through a number of "states", which define when a client 6 HTTPConnection goes through a number of "states", which define when a client
7 may legally make another request or fetch the response for a particular 7 may legally make another request or fetch the response for a particular
8 request. This diagram details these state transitions: 8 request. This diagram details these state transitions:
9 9
10 (null) 10 (null)
(...skipping 1161 matching lines...) Expand 10 before | Expand all | Expand 10 after
1172 1172
1173 def __init__(self, host, port=None, key_file=None, cert_file=None, 1173 def __init__(self, host, port=None, key_file=None, cert_file=None,
1174 timeout=socket._GLOBAL_DEFAULT_TIMEOUT, 1174 timeout=socket._GLOBAL_DEFAULT_TIMEOUT,
1175 source_address=None, *, context=None, 1175 source_address=None, *, context=None,
1176 check_hostname=None): 1176 check_hostname=None):
1177 super(HTTPSConnection, self).__init__(host, port, timeout, 1177 super(HTTPSConnection, self).__init__(host, port, timeout,
1178 source_address) 1178 source_address)
1179 self.key_file = key_file 1179 self.key_file = key_file
1180 self.cert_file = cert_file 1180 self.cert_file = cert_file
1181 if context is None: 1181 if context is None:
1182 context = ssl.create_default_context() 1182 context = ssl.create_default_context(certfile=cert_file,
1183 keyfile=key_file)
1184 elif key_file or cert_file:
1185 context.load_cert_chain(cert_file, key_file)
1183 will_verify = context.verify_mode != ssl.CERT_NONE 1186 will_verify = context.verify_mode != ssl.CERT_NONE
1184 if check_hostname is None: 1187 if check_hostname is None:
1185 check_hostname = will_verify 1188 check_hostname = will_verify
1186 elif check_hostname and not will_verify: 1189 elif check_hostname and not will_verify:
1187 raise ValueError("check_hostname needs a SSL context with " 1190 raise ValueError("check_hostname needs a SSL context with "
1188 "either CERT_OPTIONAL or CERT_REQUIRED") 1191 "either CERT_OPTIONAL or CERT_REQUIRED")
1189 if key_file or cert_file:
1190 context.load_cert_chain(cert_file, key_file)
1191 self._context = context 1192 self._context = context
1192 self._check_hostname = check_hostname 1193 self._check_hostname = check_hostname
1193 1194
1194 def connect(self): 1195 def connect(self):
1195 "Connect to a host on a given (SSL) port." 1196 "Connect to a host on a given (SSL) port."
1196 1197
1197 sock = socket.create_connection((self.host, self.port), 1198 sock = socket.create_connection((self.host, self.port),
1198 self.timeout, self.source_address) 1199 self.timeout, self.source_address)
1199 1200
1200 if self._tunnel_host: 1201 if self._tunnel_host:
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
1269 self.args = line, 1270 self.args = line,
1270 self.line = line 1271 self.line = line
1271 1272
1272 class LineTooLong(HTTPException): 1273 class LineTooLong(HTTPException):
1273 def __init__(self, line_type): 1274 def __init__(self, line_type):
1274 HTTPException.__init__(self, "got more than %d bytes when reading %s" 1275 HTTPException.__init__(self, "got more than %d bytes when reading %s"
1275 % (_MAXLINE, line_type)) 1276 % (_MAXLINE, line_type))
1276 1277
1277 # for backwards compatibility 1278 # for backwards compatibility
1278 error = HTTPException 1279 error = HTTPException
LEFTRIGHT

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+