Gentoo Archives: gentoo-commits

From: Arfrever Frehtes Taifersar Arahesis <arfrever.fta@×××××.com>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/portage:master commit in: pym/portage/dbapi/, bin/, pym/portage/, pym/portage/util/
Date: Tue, 01 May 2012 19:54:28
Message-Id: 1335901876.0a9cc38a66ded0cf0e5b534cb24b970fc9c21920.arfrever@gentoo
1 commit: 0a9cc38a66ded0cf0e5b534cb24b970fc9c21920
2 Author: Arfrever Frehtes Taifersar Arahesis <Arfrever <AT> Apache <DOT> Org>
3 AuthorDate: Tue May 1 19:51:16 2012 +0000
4 Commit: Arfrever Frehtes Taifersar Arahesis <arfrever.fta <AT> gmail <DOT> com>
5 CommitDate: Tue May 1 19:51:16 2012 +0000
6 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=0a9cc38a
7
8 Bug #413983: Add portage.util.urlopen(), which transparently
9 handles authentication in the way compatible with Python 3.
10
11 ---
12 bin/repoman | 9 ++-------
13 pym/portage/dbapi/bintree.py | 7 +++----
14 pym/portage/glsa.py | 10 +++-------
15 pym/portage/util/__init__.py | 21 ++++++++++++++++++++-
16 4 files changed, 28 insertions(+), 19 deletions(-)
17
18 diff --git a/bin/repoman b/bin/repoman
19 index 1cdfcf6..cfe4b8e 100755
20 --- a/bin/repoman
21 +++ b/bin/repoman
22 @@ -25,11 +25,6 @@ import textwrap
23 import time
24 import platform
25
26 -try:
27 - from urllib.request import urlopen as urllib_request_urlopen
28 -except ImportError:
29 - from urllib import urlopen as urllib_request_urlopen
30 -
31 from itertools import chain
32 from stat import S_ISDIR
33
34 @@ -75,7 +70,7 @@ from portage.process import find_binary, spawn
35 from portage.output import bold, create_color_func, \
36 green, nocolor, red
37 from portage.output import ConsoleStyleFile, StyleWriter
38 -from portage.util import cmp_sort_key, writemsg_level
39 +from portage.util import cmp_sort_key, urlopen, writemsg_level
40 from portage.util._desktop_entry import validate_desktop_entry
41 from portage.package.ebuild.digestgen import digestgen
42 from portage.eapi import eapi_has_iuse_defaults, eapi_has_required_use
43 @@ -1051,7 +1046,7 @@ def fetch_metadata_dtd():
44 "needs to be refetched, doing that now")
45 print()
46 try:
47 - url_f = urllib_request_urlopen(metadata_dtd_uri)
48 + url_f = urlopen(metadata_dtd_uri)
49 msg_info = url_f.info()
50 last_modified = msg_info.get('last-modified')
51 if last_modified is not None:
52
53 diff --git a/pym/portage/dbapi/bintree.py b/pym/portage/dbapi/bintree.py
54 index 2295b9f..810163d 100644
55 --- a/pym/portage/dbapi/bintree.py
56 +++ b/pym/portage/dbapi/bintree.py
57 @@ -1,4 +1,4 @@
58 -# Copyright 1998-2011 Gentoo Foundation
59 +# Copyright 1998-2012 Gentoo Foundation
60 # Distributed under the terms of the GNU General Public License v2
61
62 __all__ = ["bindbapi", "binarytree"]
63 @@ -26,6 +26,7 @@ from portage.dep import Atom, use_reduce, paren_enclose
64 from portage.exception import AlarmSignal, InvalidPackageName, \
65 PermissionDenied, PortageException
66 from portage.localization import _
67 +from portage.util import urlopen
68 from portage import _movefile
69 from portage import os
70 from portage import _encodings
71 @@ -45,10 +46,8 @@ import warnings
72 from itertools import chain
73 try:
74 from urllib.parse import urlparse
75 - from urllib.request import urlopen as urllib_request_urlopen
76 except ImportError:
77 from urlparse import urlparse
78 - from urllib import urlopen as urllib_request_urlopen
79
80 if sys.hexversion >= 0x3000000:
81 basestring = str
82 @@ -843,7 +842,7 @@ class binarytree(object):
83 # slash, so join manually...
84 url = base_url.rstrip("/") + "/Packages"
85 try:
86 - f = urllib_request_urlopen(url)
87 + f = urlopen(url)
88 except IOError:
89 path = parsed_url.path.rstrip("/") + "/Packages"
90
91
92 diff --git a/pym/portage/glsa.py b/pym/portage/glsa.py
93 index 2df7ec3..16f662f 100644
94 --- a/pym/portage/glsa.py
95 +++ b/pym/portage/glsa.py
96 @@ -1,14 +1,10 @@
97 -# Copyright 2003-2011 Gentoo Foundation
98 +# Copyright 2003-2012 Gentoo Foundation
99 # Distributed under the terms of the GNU General Public License v2
100
101 from __future__ import absolute_import
102
103 import io
104 import sys
105 -try:
106 - from urllib.request import urlopen as urllib_request_urlopen
107 -except ImportError:
108 - from urllib import urlopen as urllib_request_urlopen
109 import re
110 import xml.dom.minidom
111
112 @@ -18,7 +14,7 @@ from portage import _encodings
113 from portage import _unicode_decode
114 from portage import _unicode_encode
115 from portage.versions import pkgsplit, catpkgsplit, pkgcmp, best
116 -from portage.util import grabfile
117 +from portage.util import grabfile, urlopen
118 from portage.const import CACHE_PATH
119 from portage.localization import _
120 from portage.dep import _slot_separator
121 @@ -476,7 +472,7 @@ class Glsa:
122 myurl = "file://"+self.nr
123 else:
124 myurl = repository + "glsa-%s.xml" % str(self.nr)
125 - self.parse(urllib_request_urlopen(myurl))
126 + self.parse(urlopen(myurl))
127 return None
128
129 def parse(self, myfile):
130
131 diff --git a/pym/portage/util/__init__.py b/pym/portage/util/__init__.py
132 index d6ac46c..2b50733 100644
133 --- a/pym/portage/util/__init__.py
134 +++ b/pym/portage/util/__init__.py
135 @@ -1,4 +1,4 @@
136 -# Copyright 2004-2011 Gentoo Foundation
137 +# Copyright 2004-2012 Gentoo Foundation
138 # Distributed under the terms of the GNU General Public License v2
139
140 __all__ = ['apply_permissions', 'apply_recursive_permissions',
141 @@ -26,6 +26,14 @@ import string
142 import sys
143 import traceback
144 import glob
145 +try:
146 + import urllib.parse as urllib_parse
147 + import urllib.request as urllib_request
148 + from urllib.parse import splituser as urllib_parse_splituser
149 +except ImportError:
150 + import urlparse as urllib_parse
151 + import urllib2 as urllib_request
152 + from urllib import splituser as urllib_parse_splituser
153
154 import portage
155 portage.proxy.lazyimport.lazyimport(globals(),
156 @@ -1640,3 +1648,14 @@ def getlibpaths(root, env=None):
157 rval.append("/lib")
158
159 return [normalize_path(x) for x in rval if x]
160 +
161 +def urlopen(url):
162 + parse_result = urllib_parse.urlparse(url)
163 + netloc = urllib_parse_splituser(parse_result.netloc)[1]
164 + url = urllib_parse.urlunparse((parse_result.scheme, netloc, parse_result.path, parse_result.params, parse_result.query, parse_result.fragment))
165 + password_manager = urllib_request.HTTPPasswordMgrWithDefaultRealm()
166 + if parse_result.username is not None:
167 + password_manager.add_password(None, url, parse_result.username, parse_result.password)
168 + auth_handler = urllib_request.HTTPBasicAuthHandler(password_manager)
169 + opener = urllib_request.build_opener(auth_handler)
170 + return opener.open(url)