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

Delta Between Two Patch Sets: Lib/urllib/request.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/test/test_ssl.py ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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.create_default_context(verify_mode=ssl.CERT_REQUIRED) 144 context = ssl.create_default_context(cert_reqs=ssl.CERT_REQUIRED,
145 if cafile or capath: 145 cafile=cafile,
146 context.load_verify_locations(cafile, capath) 146 capath=capath)
147 else:
148 context.set_default_verify_paths()
149 https_handler = HTTPSHandler(context=context, check_hostname=True) 147 https_handler = HTTPSHandler(context=context, check_hostname=True)
150 opener = build_opener(https_handler) 148 opener = build_opener(https_handler)
151 elif _opener is None: 149 elif _opener is None:
152 _opener = opener = build_opener() 150 _opener = opener = build_opener()
153 else: 151 else:
154 opener = _opener 152 opener = _opener
155 return opener.open(url, data, timeout) 153 return opener.open(url, data, timeout)
156 154
157 def install_opener(opener): 155 def install_opener(opener):
158 global _opener 156 global _opener
(...skipping 2452 matching lines...) Expand 10 before | Expand all | Expand 10 after
2611 """ 2609 """
2612 if getproxies_environment(): 2610 if getproxies_environment():
2613 return proxy_bypass_environment(host) 2611 return proxy_bypass_environment(host)
2614 else: 2612 else:
2615 return proxy_bypass_registry(host) 2613 return proxy_bypass_registry(host)
2616 2614
2617 else: 2615 else:
2618 # By default use environment variables 2616 # By default use environment variables
2619 getproxies = getproxies_environment 2617 getproxies = getproxies_environment
2620 proxy_bypass = proxy_bypass_environment 2618 proxy_bypass = proxy_bypass_environment
LEFTRIGHT

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