From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from pigeon.gentoo.org ([208.92.234.80] helo=lists.gentoo.org) by finch.gentoo.org with esmtp (Exim 4.60) (envelope-from ) id 1SPJ9X-0006EI-Ur for garchives@archives.gentoo.org; Tue, 01 May 2012 19:54:28 +0000 Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 785FDE0A97; Tue, 1 May 2012 19:54:15 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by pigeon.gentoo.org (Postfix) with ESMTP id 32E3AE0A97 for ; Tue, 1 May 2012 19:54:14 +0000 (UTC) Received: from hornbill.gentoo.org (hornbill.gentoo.org [94.100.119.163]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 3C6B71B4027 for ; Tue, 1 May 2012 19:54:14 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by hornbill.gentoo.org (Postfix) with ESMTP id F2406E5403 for ; Tue, 1 May 2012 19:54:12 +0000 (UTC) From: "Arfrever Frehtes Taifersar Arahesis" To: gentoo-commits@lists.gentoo.org Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Arfrever Frehtes Taifersar Arahesis" Message-ID: <1335901876.0a9cc38a66ded0cf0e5b534cb24b970fc9c21920.arfrever@gentoo> Subject: [gentoo-commits] proj/portage:master commit in: pym/portage/dbapi/, bin/, pym/portage/, pym/portage/util/ X-VCS-Repository: proj/portage X-VCS-Files: bin/repoman pym/portage/dbapi/bintree.py pym/portage/glsa.py pym/portage/util/__init__.py X-VCS-Directories: pym/portage/dbapi/ bin/ pym/portage/ pym/portage/util/ X-VCS-Committer: arfrever X-VCS-Committer-Name: Arfrever Frehtes Taifersar Arahesis X-VCS-Revision: 0a9cc38a66ded0cf0e5b534cb24b970fc9c21920 X-VCS-Branch: master Date: Tue, 1 May 2012 19:54:12 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: quoted-printable X-Archives-Salt: 8624f1eb-e631-42a5-9367-822bb90f90e1 X-Archives-Hash: 43765f78853d7ea82e786f50c4bf7f73 commit: 0a9cc38a66ded0cf0e5b534cb24b970fc9c21920 Author: Arfrever Frehtes Taifersar Arahesis Apache Org> AuthorDate: Tue May 1 19:51:16 2012 +0000 Commit: Arfrever Frehtes Taifersar Arahesis gmail = com> CommitDate: Tue May 1 19:51:16 2012 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=3Dproj/portage.git;a= =3Dcommit;h=3D0a9cc38a Bug #413983: Add portage.util.urlopen(), which transparently handles authentication in the way compatible with Python 3. --- bin/repoman | 9 ++------- pym/portage/dbapi/bintree.py | 7 +++---- pym/portage/glsa.py | 10 +++------- pym/portage/util/__init__.py | 21 ++++++++++++++++++++- 4 files changed, 28 insertions(+), 19 deletions(-) diff --git a/bin/repoman b/bin/repoman index 1cdfcf6..cfe4b8e 100755 --- a/bin/repoman +++ b/bin/repoman @@ -25,11 +25,6 @@ import textwrap import time import platform =20 -try: - from urllib.request import urlopen as urllib_request_urlopen -except ImportError: - from urllib import urlopen as urllib_request_urlopen - from itertools import chain from stat import S_ISDIR =20 @@ -75,7 +70,7 @@ from portage.process import find_binary, spawn from portage.output import bold, create_color_func, \ green, nocolor, red from portage.output import ConsoleStyleFile, StyleWriter -from portage.util import cmp_sort_key, writemsg_level +from portage.util import cmp_sort_key, urlopen, writemsg_level from portage.util._desktop_entry import validate_desktop_entry from portage.package.ebuild.digestgen import digestgen from portage.eapi import eapi_has_iuse_defaults, eapi_has_required_use @@ -1051,7 +1046,7 @@ def fetch_metadata_dtd(): "needs to be refetched, doing that now") print() try: - url_f =3D urllib_request_urlopen(metadata_dtd_uri) + url_f =3D urlopen(metadata_dtd_uri) msg_info =3D url_f.info() last_modified =3D msg_info.get('last-modified') if last_modified is not None: diff --git a/pym/portage/dbapi/bintree.py b/pym/portage/dbapi/bintree.py index 2295b9f..810163d 100644 --- a/pym/portage/dbapi/bintree.py +++ b/pym/portage/dbapi/bintree.py @@ -1,4 +1,4 @@ -# Copyright 1998-2011 Gentoo Foundation +# Copyright 1998-2012 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 =20 __all__ =3D ["bindbapi", "binarytree"] @@ -26,6 +26,7 @@ from portage.dep import Atom, use_reduce, paren_enclose from portage.exception import AlarmSignal, InvalidPackageName, \ PermissionDenied, PortageException from portage.localization import _ +from portage.util import urlopen from portage import _movefile from portage import os from portage import _encodings @@ -45,10 +46,8 @@ import warnings from itertools import chain try: from urllib.parse import urlparse - from urllib.request import urlopen as urllib_request_urlopen except ImportError: from urlparse import urlparse - from urllib import urlopen as urllib_request_urlopen =20 if sys.hexversion >=3D 0x3000000: basestring =3D str @@ -843,7 +842,7 @@ class binarytree(object): # slash, so join manually... url =3D base_url.rstrip("/") + "/Packages" try: - f =3D urllib_request_urlopen(url) + f =3D urlopen(url) except IOError: path =3D parsed_url.path.rstrip("/") + "/Packages" =20 diff --git a/pym/portage/glsa.py b/pym/portage/glsa.py index 2df7ec3..16f662f 100644 --- a/pym/portage/glsa.py +++ b/pym/portage/glsa.py @@ -1,14 +1,10 @@ -# Copyright 2003-2011 Gentoo Foundation +# Copyright 2003-2012 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 =20 from __future__ import absolute_import =20 import io import sys -try: - from urllib.request import urlopen as urllib_request_urlopen -except ImportError: - from urllib import urlopen as urllib_request_urlopen import re import xml.dom.minidom =20 @@ -18,7 +14,7 @@ from portage import _encodings from portage import _unicode_decode from portage import _unicode_encode from portage.versions import pkgsplit, catpkgsplit, pkgcmp, best -from portage.util import grabfile +from portage.util import grabfile, urlopen from portage.const import CACHE_PATH from portage.localization import _ from portage.dep import _slot_separator @@ -476,7 +472,7 @@ class Glsa: myurl =3D "file://"+self.nr else: myurl =3D repository + "glsa-%s.xml" % str(self.nr) - self.parse(urllib_request_urlopen(myurl)) + self.parse(urlopen(myurl)) return None =20 def parse(self, myfile): diff --git a/pym/portage/util/__init__.py b/pym/portage/util/__init__.py index d6ac46c..2b50733 100644 --- a/pym/portage/util/__init__.py +++ b/pym/portage/util/__init__.py @@ -1,4 +1,4 @@ -# Copyright 2004-2011 Gentoo Foundation +# Copyright 2004-2012 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 =20 __all__ =3D ['apply_permissions', 'apply_recursive_permissions', @@ -26,6 +26,14 @@ import string import sys import traceback import glob +try: + import urllib.parse as urllib_parse + import urllib.request as urllib_request + from urllib.parse import splituser as urllib_parse_splituser +except ImportError: + import urlparse as urllib_parse + import urllib2 as urllib_request + from urllib import splituser as urllib_parse_splituser =20 import portage portage.proxy.lazyimport.lazyimport(globals(), @@ -1640,3 +1648,14 @@ def getlibpaths(root, env=3DNone): rval.append("/lib") =20 return [normalize_path(x) for x in rval if x] + +def urlopen(url):=09 + parse_result =3D urllib_parse.urlparse(url) + netloc =3D urllib_parse_splituser(parse_result.netloc)[1] + url =3D urllib_parse.urlunparse((parse_result.scheme, netloc, parse_res= ult.path, parse_result.params, parse_result.query, parse_result.fragment)= ) + password_manager =3D urllib_request.HTTPPasswordMgrWithDefaultRealm() + if parse_result.username is not None: + password_manager.add_password(None, url, parse_result.username, parse_= result.password) + auth_handler =3D urllib_request.HTTPBasicAuthHandler(password_manager) + opener =3D urllib_request.build_opener(auth_handler) + return opener.open(url)