| OLD | NEW |
| 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 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 if host == "": | 153 if host == "": |
| 154 host = request.get_header("Host", "") | 154 host = request.get_header("Host", "") |
| 155 | 155 |
| 156 # remove port, if present | 156 # remove port, if present |
| 157 host = _cut_port_re.sub("", host, 1) | 157 host = _cut_port_re.sub("", host, 1) |
| 158 return host.lower() | 158 return host.lower() |
| 159 | 159 |
| 160 class Request: | 160 class Request: |
| 161 | 161 |
| 162 def __init__(self, url, data=None, headers={}, | 162 def __init__(self, url, data=None, headers={}, |
| 163 origin_req_host=None, unverifiable=False): | 163 origin_req_host=None, unverifiable=False, method=None): |
| 164 # unwrap('<URL:type://host/path>') --> 'type://host/path' | 164 # unwrap('<URL:type://host/path>') --> 'type://host/path' |
| 165 self.full_url = unwrap(url) | 165 self.full_url = unwrap(url) |
| 166 self.full_url, fragment = splittag(self.full_url) | 166 self.full_url, fragment = splittag(self.full_url) |
| 167 self.data = data | 167 self.data = data |
| 168 self.headers = {} | 168 self.headers = {} |
| 169 self._tunnel_host = None | 169 self._tunnel_host = None |
| 170 for key, value in headers.items(): | 170 for key, value in headers.items(): |
| 171 self.add_header(key, value) | 171 self.add_header(key, value) |
| 172 self.unredirected_hdrs = {} | 172 self.unredirected_hdrs = {} |
| 173 if origin_req_host is None: | 173 if origin_req_host is None: |
| 174 origin_req_host = request_host(self) | 174 origin_req_host = request_host(self) |
| 175 self.origin_req_host = origin_req_host | 175 self.origin_req_host = origin_req_host |
| 176 self.unverifiable = unverifiable | 176 self.unverifiable = unverifiable |
| 177 self.method = method |
| 177 self._parse() | 178 self._parse() |
| 178 | 179 |
| 179 def _parse(self): | 180 def _parse(self): |
| 180 self.type, rest = splittype(self.full_url) | 181 self.type, rest = splittype(self.full_url) |
| 181 if self.type is None: | 182 if self.type is None: |
| 182 raise ValueError("unknown url type: %s" % self.full_url) | 183 raise ValueError("unknown url type: %s" % self.full_url) |
| 183 self.host, self.selector = splithost(rest) | 184 self.host, self.selector = splithost(rest) |
| 184 if self.host: | 185 if self.host: |
| 185 self.host = unquote(self.host) | 186 self.host = unquote(self.host) |
| 186 | 187 |
| 187 def get_method(self): | 188 def get_method(self): |
| 189 if self.method is not None: |
| 190 return self.method |
| 191 |
| 188 if self.data is not None: | 192 if self.data is not None: |
| 189 return "POST" | 193 return "POST" |
| 190 else: | 194 else: |
| 191 return "GET" | 195 return "GET" |
| 192 | 196 |
| 193 # Begin deprecated methods | 197 # Begin deprecated methods |
| 194 | 198 |
| 195 def add_data(self, data): | 199 def add_data(self, data): |
| 196 self.data = data | 200 self.data = data |
| 197 | 201 |
| (...skipping 2176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2374 """ | 2378 """ |
| 2375 if getproxies_environment(): | 2379 if getproxies_environment(): |
| 2376 return proxy_bypass_environment(host) | 2380 return proxy_bypass_environment(host) |
| 2377 else: | 2381 else: |
| 2378 return proxy_bypass_registry(host) | 2382 return proxy_bypass_registry(host) |
| 2379 | 2383 |
| 2380 else: | 2384 else: |
| 2381 # By default use environment variables | 2385 # By default use environment variables |
| 2382 getproxies = getproxies_environment | 2386 getproxies = getproxies_environment |
| 2383 proxy_bypass = proxy_bypass_environment | 2387 proxy_bypass = proxy_bypass_environment |
| OLD | NEW |