From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: <gentoo-commits+bounces-491598-garchives=archives.gentoo.org@lists.gentoo.org> Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id CCD2E13800E for <garchives@archives.gentoo.org>; Thu, 2 Aug 2012 02:26:52 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id CBD3AE079C; Thu, 2 Aug 2012 02:26:44 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by pigeon.gentoo.org (Postfix) with ESMTP id 8E004E079C for <gentoo-commits@lists.gentoo.org>; Thu, 2 Aug 2012 02:26:44 +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 C5B8F1B402E for <gentoo-commits@lists.gentoo.org>; Thu, 2 Aug 2012 02:26:43 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by hornbill.gentoo.org (Postfix) with ESMTP id 42DB1E543C for <gentoo-commits@lists.gentoo.org>; Thu, 2 Aug 2012 02:26:42 +0000 (UTC) From: "Zac Medico" <zmedico@gentoo.org> To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Zac Medico" <zmedico@gentoo.org> Message-ID: <1343874378.2b1ba77eb17629593ca5b8b2ed6c0f3841c43fb6.zmedico@gentoo> Subject: [gentoo-commits] proj/portage:master commit in: pym/portage/util/ X-VCS-Repository: proj/portage X-VCS-Files: pym/portage/util/_urlopen.py X-VCS-Directories: pym/portage/util/ X-VCS-Committer: zmedico X-VCS-Committer-Name: Zac Medico X-VCS-Revision: 2b1ba77eb17629593ca5b8b2ed6c0f3841c43fb6 X-VCS-Branch: master Date: Thu, 2 Aug 2012 02:26:42 +0000 (UTC) Precedence: bulk List-Post: <mailto:gentoo-commits@lists.gentoo.org> List-Help: <mailto:gentoo-commits+help@lists.gentoo.org> List-Unsubscribe: <mailto:gentoo-commits+unsubscribe@lists.gentoo.org> List-Subscribe: <mailto:gentoo-commits+subscribe@lists.gentoo.org> List-Id: Gentoo Linux mail <gentoo-commits.gentoo.org> X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: 39fbbc8c-67c2-4897-a4c8-fbfc533f7cd3 X-Archives-Hash: 9626c01d01a43a2c64ce469897d55732 commit: 2b1ba77eb17629593ca5b8b2ed6c0f3841c43fb6 Author: Zac Medico <zmedico <AT> gentoo <DOT> org> AuthorDate: Thu Aug 2 02:26:18 2012 +0000 Commit: Zac Medico <zmedico <AT> gentoo <DOT> org> CommitDate: Thu Aug 2 02:26:18 2012 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=2b1ba77e _urlopen: fix python3 http password breakage This broke in commit e06cb6d66db37ac7ab77acf65038b1f770c13c96 since CompressedResponseProcessor did not include password auth support. BUG: The if_modified_since parameter appears to be ignored when using http password authentication. --- pym/portage/util/_urlopen.py | 40 +++++++++++----------------------------- 1 files changed, 11 insertions(+), 29 deletions(-) diff --git a/pym/portage/util/_urlopen.py b/pym/portage/util/_urlopen.py index bcd8f7c..768ccb8 100644 --- a/pym/portage/util/_urlopen.py +++ b/pym/portage/util/_urlopen.py @@ -27,14 +27,20 @@ TIMESTAMP_TOLERANCE=5 def urlopen(url, if_modified_since=None): parse_result = urllib_parse.urlparse(url) - try: - if parse_result.scheme not in ("http", "https"): - return _urlopen(url) + if parse_result.scheme not in ("http", "https"): + return _urlopen(url) + else: + netloc = urllib_parse_splituser(parse_result.netloc)[1] + url = urllib_parse.urlunparse((parse_result.scheme, netloc, parse_result.path, parse_result.params, parse_result.query, parse_result.fragment)) + password_manager = urllib_request.HTTPPasswordMgrWithDefaultRealm() request = urllib_request.Request(url) request.add_header('User-Agent', 'Gentoo Portage') if if_modified_since: request.add_header('If-Modified-Since', _timestamp_to_http(if_modified_since)) - opener = urllib_request.build_opener(CompressedResponseProcessor) + if parse_result.username is not None: + password_manager.add_password(None, url, parse_result.username, parse_result.password) + auth_handler = CompressedResponseProcessor(password_manager) + opener = urllib_request.build_opener(auth_handler) hdl = opener.open(request) if hdl.headers.get('last-modified', ''): try: @@ -44,30 +50,6 @@ def urlopen(url, if_modified_since=None): add_header = hdl.headers.addheader add_header('timestamp', _http_to_timestamp(hdl.headers.get('last-modified'))) return hdl - except SystemExit: - raise - except Exception as e: - if hasattr(e, 'code') and e.code == 304: # HTTPError 304: not modified - raise - if sys.hexversion < 0x3000000: - raise - if parse_result.scheme not in ("http", "https") or \ - not parse_result.username: - raise - - return _new_urlopen(url) - -def _new_urlopen(url): - # This is experimental code for bug #413983. - parse_result = urllib_parse.urlparse(url) - netloc = urllib_parse_splituser(parse_result.netloc)[1] - url = urllib_parse.urlunparse((parse_result.scheme, netloc, parse_result.path, parse_result.params, parse_result.query, parse_result.fragment)) - password_manager = urllib_request.HTTPPasswordMgrWithDefaultRealm() - if parse_result.username is not None: - password_manager.add_password(None, url, parse_result.username, parse_result.password) - auth_handler = urllib_request.HTTPBasicAuthHandler(password_manager) - opener = urllib_request.build_opener(auth_handler) - return opener.open(url) def _timestamp_to_http(timestamp): dt = datetime.fromtimestamp(float(long(timestamp)+TIMESTAMP_TOLERANCE)) @@ -79,7 +61,7 @@ def _http_to_timestamp(http_datetime_string): timestamp = mktime(tuple) return str(long(timestamp)) -class CompressedResponseProcessor(urllib_request.BaseHandler): +class CompressedResponseProcessor(urllib_request.HTTPBasicAuthHandler): # Handler for compressed responses. def http_request(self, req):