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

Side by Side Diff: Lib/urllib/request.py

Issue 19689: ssl.create_default_context()
Patch Set: Created 5 years, 11 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/test/test_ssl.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 """An extensible library for opening URLs using a variety of protocols 1 """An extensible library for opening URLs using a variety of protocols
2 2
3 The simplest way to use this module is to call the urlopen function, 3 The simplest way to use this module is to call the urlopen function,
4 which accepts a string containing a URL or a Request object (described 4 which accepts a string containing a URL or a Request object (described
5 below). It opens the URL and returns the results as file-like 5 below). It opens the URL and returns the results as file-like
6 object; the returned object has some extra methods described below. 6 object; the returned object has some extra methods described below.
7 7
8 The OpenerDirector manages a collection of Handler objects that do 8 The OpenerDirector manages a collection of Handler objects that do
9 all the actual work. Each Handler implements a particular protocol or 9 all the actual work. Each Handler implements a particular protocol or
10 option. The OpenerDirector is a composite object that invokes the 10 option. The OpenerDirector is a composite object that invokes the
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 # used in User-Agent header sent 134 # used in User-Agent header sent
135 __version__ = sys.version[:3] 135 __version__ = sys.version[:3]
136 136
137 _opener = None 137 _opener = None
138 def urlopen(url, data=None, timeout=socket._GLOBAL_DEFAULT_TIMEOUT, 138 def urlopen(url, data=None, timeout=socket._GLOBAL_DEFAULT_TIMEOUT,
139 *, cafile=None, capath=None, cadefault=False): 139 *, cafile=None, capath=None, cadefault=False):
140 global _opener 140 global _opener
141 if cafile or capath or cadefault: 141 if cafile or capath or cadefault:
142 if not _have_ssl: 142 if not _have_ssl:
143 raise ValueError('SSL support not available') 143 raise ValueError('SSL support not available')
144 context = ssl.SSLContext(ssl.PROTOCOL_SSLv23) 144 context = ssl.create_default_context(verify_mode=ssl.CERT_REQUIRED)
145 context.options |= ssl.OP_NO_SSLv2
146 context.verify_mode = ssl.CERT_REQUIRED
147 if cafile or capath: 145 if cafile or capath:
148 context.load_verify_locations(cafile, capath) 146 context.load_verify_locations(cafile, capath)
149 else: 147 else:
150 context.set_default_verify_paths() 148 context.set_default_verify_paths()
151 https_handler = HTTPSHandler(context=context, check_hostname=True) 149 https_handler = HTTPSHandler(context=context, check_hostname=True)
152 opener = build_opener(https_handler) 150 opener = build_opener(https_handler)
153 elif _opener is None: 151 elif _opener is None:
154 _opener = opener = build_opener() 152 _opener = opener = build_opener()
155 else: 153 else:
156 opener = _opener 154 opener = _opener
(...skipping 2456 matching lines...) Expand 10 before | Expand all | Expand 10 after
2613 """ 2611 """
2614 if getproxies_environment(): 2612 if getproxies_environment():
2615 return proxy_bypass_environment(host) 2613 return proxy_bypass_environment(host)
2616 else: 2614 else:
2617 return proxy_bypass_registry(host) 2615 return proxy_bypass_registry(host)
2618 2616
2619 else: 2617 else:
2620 # By default use environment variables 2618 # By default use environment variables
2621 getproxies = getproxies_environment 2619 getproxies = getproxies_environment
2622 proxy_bypass = proxy_bypass_environment 2620 proxy_bypass = proxy_bypass_environment
OLDNEW
« no previous file with comments | « Lib/test/test_ssl.py ('k') | no next file » | no next file with comments »

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