1 |
commit: 6e6d8e7f522fef3c32a7c71298024167c066a3c5 |
2 |
Author: Frédéric Pierret (fepitre) <frederic.pierret <AT> qubes-os <DOT> org> |
3 |
AuthorDate: Thu Aug 20 09:35:23 2020 +0000 |
4 |
Commit: Zac Medico <zmedico <AT> gentoo <DOT> org> |
5 |
CommitDate: Mon Sep 7 22:23:08 2020 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=6e6d8e7f |
7 |
|
8 |
Use portage proxy settings for fetching BINPKG host |
9 |
|
10 |
Bug: https://bugs.gentoo.org/740898 |
11 |
See: https://github.com/gentoo/portage/pull/607 |
12 |
Signed-off-by: Frédéric Pierret (fepitre) <frederic.pierret <AT> qubes-os.org> |
13 |
Signed-off-by: Zac Medico <zmedico <AT> gentoo.org> |
14 |
|
15 |
lib/portage/dbapi/bintree.py | 9 ++++++++- |
16 |
lib/portage/util/_urlopen.py | 10 +++++++--- |
17 |
2 files changed, 15 insertions(+), 4 deletions(-) |
18 |
|
19 |
diff --git a/lib/portage/dbapi/bintree.py b/lib/portage/dbapi/bintree.py |
20 |
index 620865a79..ee30542a5 100644 |
21 |
--- a/lib/portage/dbapi/bintree.py |
22 |
+++ b/lib/portage/dbapi/bintree.py |
23 |
@@ -964,11 +964,18 @@ class binarytree: |
24 |
download_timestamp + ttl > time.time(): |
25 |
raise UseCachedCopyOfRemoteIndex() |
26 |
|
27 |
+ # Set proxy settings for _urlopen -> urllib_request |
28 |
+ proxies = {} |
29 |
+ for proto in ('http', 'https'): |
30 |
+ value = self.settings.get(proto + '_proxy') |
31 |
+ if value is not None: |
32 |
+ proxies[proto] = value |
33 |
+ |
34 |
# Don't use urlopen for https, unless |
35 |
# PEP 476 is supported (bug #469888). |
36 |
if parsed_url.scheme not in ('https',) or _have_pep_476(): |
37 |
try: |
38 |
- f = _urlopen(url, if_modified_since=local_timestamp) |
39 |
+ f = _urlopen(url, if_modified_since=local_timestamp, proxies=proxies) |
40 |
if hasattr(f, 'headers') and f.headers.get('timestamp', ''): |
41 |
remote_timestamp = f.headers.get('timestamp') |
42 |
except IOError as err: |
43 |
|
44 |
diff --git a/lib/portage/util/_urlopen.py b/lib/portage/util/_urlopen.py |
45 |
index b46d1554c..b67d02739 100644 |
46 |
--- a/lib/portage/util/_urlopen.py |
47 |
+++ b/lib/portage/util/_urlopen.py |
48 |
@@ -26,7 +26,7 @@ def have_pep_476(): |
49 |
return hasattr(__import__('ssl'), '_create_unverified_context') |
50 |
|
51 |
|
52 |
-def urlopen(url, if_modified_since=None): |
53 |
+def urlopen(url, if_modified_since=None, proxies=None): |
54 |
parse_result = urllib_parse.urlparse(url) |
55 |
if parse_result.scheme not in ("http", "https"): |
56 |
return _urlopen(url) |
57 |
@@ -40,8 +40,12 @@ def urlopen(url, if_modified_since=None): |
58 |
request.add_header('If-Modified-Since', _timestamp_to_http(if_modified_since)) |
59 |
if parse_result.username is not None: |
60 |
password_manager.add_password(None, url, parse_result.username, parse_result.password) |
61 |
- auth_handler = CompressedResponseProcessor(password_manager) |
62 |
- opener = urllib_request.build_opener(auth_handler) |
63 |
+ |
64 |
+ handlers = [CompressedResponseProcessor(password_manager)] |
65 |
+ if proxies: |
66 |
+ handlers.append(urllib_request.ProxyHandler(proxies)) |
67 |
+ opener = urllib_request.build_opener(*handlers) |
68 |
+ |
69 |
hdl = opener.open(request) |
70 |
if hdl.headers.get('last-modified', ''): |
71 |
try: |