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

Side by Side Diff: Lib/http/client.py

Issue 19689: ssl.create_default_context()
Patch Set: Created 5 years, 8 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:
View unified diff | Download patch
« no previous file with comments | « Lib/ftplib.py ('k') | Lib/imaplib.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 # Some reasonable defaults 1182 context = ssl.create_default_context()
1183 context = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
1184 context.options |= ssl.OP_NO_SSLv2
1185 will_verify = context.verify_mode != ssl.CERT_NONE 1183 will_verify = context.verify_mode != ssl.CERT_NONE
1186 if check_hostname is None: 1184 if check_hostname is None:
1187 check_hostname = will_verify 1185 check_hostname = will_verify
1188 elif check_hostname and not will_verify: 1186 elif check_hostname and not will_verify:
1189 raise ValueError("check_hostname needs a SSL context with " 1187 raise ValueError("check_hostname needs a SSL context with "
1190 "either CERT_OPTIONAL or CERT_REQUIRED") 1188 "either CERT_OPTIONAL or CERT_REQUIRED")
1191 if key_file or cert_file: 1189 if key_file or cert_file:
1192 context.load_cert_chain(cert_file, key_file) 1190 context.load_cert_chain(cert_file, key_file)
1193 self._context = context 1191 self._context = context
1194 self._check_hostname = check_hostname 1192 self._check_hostname = check_hostname
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
1271 self.args = line, 1269 self.args = line,
1272 self.line = line 1270 self.line = line
1273 1271
1274 class LineTooLong(HTTPException): 1272 class LineTooLong(HTTPException):
1275 def __init__(self, line_type): 1273 def __init__(self, line_type):
1276 HTTPException.__init__(self, "got more than %d bytes when reading %s" 1274 HTTPException.__init__(self, "got more than %d bytes when reading %s"
1277 % (_MAXLINE, line_type)) 1275 % (_MAXLINE, line_type))
1278 1276
1279 # for backwards compatibility 1277 # for backwards compatibility
1280 error = HTTPException 1278 error = HTTPException
OLDNEW
« no previous file with comments | « Lib/ftplib.py ('k') | Lib/imaplib.py » ('j') | no next file with comments »

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