From patchwork Mon Jul 11 02:26:13 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael-Doyle Hudson X-Patchwork-Id: 2639 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 8A72423F51 for ; Mon, 11 Jul 2011 02:26:16 +0000 (UTC) Received: from mail-qw0-f52.google.com (mail-qw0-f52.google.com [209.85.216.52]) by fiordland.canonical.com (Postfix) with ESMTP id 3BC93A182B4 for ; Mon, 11 Jul 2011 02:26:16 +0000 (UTC) Received: by qwb8 with SMTP id 8so2403924qwb.11 for ; Sun, 10 Jul 2011 19:26:15 -0700 (PDT) Received: by 10.229.68.200 with SMTP id w8mr3485261qci.114.1310351175571; Sun, 10 Jul 2011 19:26:15 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.229.217.78 with SMTP id hl14cs193009qcb; Sun, 10 Jul 2011 19:26:15 -0700 (PDT) Received: by 10.216.236.157 with SMTP id w29mr2852201weq.18.1310351174207; Sun, 10 Jul 2011 19:26:14 -0700 (PDT) Received: from adelie.canonical.com (adelie.canonical.com [91.189.90.139]) by mx.google.com with ESMTP id g21si96557wes.44.2011.07.10.19.26.13; Sun, 10 Jul 2011 19:26:14 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of bounces@canonical.com designates 91.189.90.139 as permitted sender) client-ip=91.189.90.139; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of bounces@canonical.com designates 91.189.90.139 as permitted sender) smtp.mail=bounces@canonical.com Received: from loganberry.canonical.com ([91.189.90.37]) by adelie.canonical.com with esmtp (Exim 4.71 #1 (Debian)) id 1Qg6CL-00008b-38 for ; Mon, 11 Jul 2011 02:26:13 +0000 Received: from loganberry.canonical.com (localhost [127.0.0.1]) by loganberry.canonical.com (Postfix) with ESMTP id 14EF82EA00E for ; Mon, 11 Jul 2011 02:26:13 +0000 (UTC) MIME-Version: 1.0 X-Launchpad-Project: lava-tool X-Launchpad-Branch: ~linaro-validation/lava-tool/trunk X-Launchpad-Message-Rationale: Subscriber X-Launchpad-Branch-Revision-Number: 161 X-Launchpad-Notification-Type: branch-revision To: Linaro Patch Tracker From: noreply@launchpad.net Subject: [Branch ~linaro-validation/lava-tool/trunk] Rev 161: python 2.6 compatibility Message-Id: <20110711022613.1912.2438.launchpad@loganberry.canonical.com> Date: Mon, 11 Jul 2011 02:26:13 -0000 Reply-To: noreply@launchpad.net Sender: bounces@canonical.com Errors-To: bounces@canonical.com Precedence: bulk X-Generated-By: Launchpad (canonical.com); Revision="13376"; Instance="initZopeless config overlay" X-Launchpad-Hash: e29c75589b52cff3c2072b2e29f665277bd29f16 Merge authors: Michael Hudson-Doyle (mwhudson) ------------------------------------------------------------ revno: 161 [merge] committer: Michael-Doyle Hudson branch nick: trunk timestamp: Mon 2011-07-11 13:37:29 +1200 message: python 2.6 compatibility modified: lava_tool/authtoken.py lava_tool/tests/test_authtoken.py --- lp:lava-tool https://code.launchpad.net/~linaro-validation/lava-tool/trunk You are subscribed to branch lp:lava-tool. To unsubscribe from this branch go to https://code.launchpad.net/~linaro-validation/lava-tool/trunk/+edit-subscription === modified file 'lava_tool/authtoken.py' --- lava_tool/authtoken.py 2011-06-17 13:11:50 +0000 +++ lava_tool/authtoken.py 2011-07-10 23:39:36 +0000 @@ -64,12 +64,11 @@ def send_request(self, connection, handler, request_body): xmlrpclib.Transport.send_request( self, connection, handler, request_body) - auth, host = urllib.splituser(self._connection[0]) - if auth is None: + if self._auth is None: return - user, token = urllib.splitpasswd(auth) + user, token = urllib.splitpasswd(self._auth) if token is None: - endpoint_url = '%s://%s%s' % (self._scheme, host, handler) + endpoint_url = '%s://%s%s' % (self._scheme, self._host, handler) token = self.auth_backend.get_token_for_endpoint( user, endpoint_url) if token is None: @@ -79,13 +78,14 @@ connection.putheader("Authorization", "Basic " + auth) def get_host_info(self, host): - # We override to never send any authorization header based soley on - # the host; we do all that in send_request above. + # We override stash the auth part away and never send any + # authorization header based soley on the host; we do all that in + # send_request above. x509 = {} if isinstance(host, tuple): host, x509 = host - auth, host = urllib.splituser(host) - return host, None, x509 + self._auth, self._host = urllib.splituser(host) + return self._host, None, x509 class AuthenticatingTransport( === modified file 'lava_tool/tests/test_authtoken.py' --- lava_tool/tests/test_authtoken.py 2011-06-17 13:26:55 +0000 +++ lava_tool/tests/test_authtoken.py 2011-07-10 23:43:30 +0000 @@ -24,6 +24,7 @@ import StringIO from unittest import TestCase import urlparse +import sys import xmlrpclib from mocker import ARGS, KWARGS, Mocker @@ -34,6 +35,10 @@ ) from lava_tool.interface import LavaCommandError +if sys.version_info[:2] <= (2, 6): + TWO_SIX = True +else: + TWO_SIX = False class TestAuthenticatingServerProxy(TestCase): @@ -46,11 +51,13 @@ url, auth_backend=auth_backend) mocker = Mocker() if url.startswith('https'): - cls_name = 'httplib.HTTPSConnection' - expected_constructor_args = (expected_host, None) + cls_name = 'httplib.HTTPS' + expected_constructor_args = (expected_host, ARGS) else: - cls_name = 'httplib.HTTPConnection' - expected_constructor_args = (expected_host,) + cls_name = 'httplib.HTTP' + expected_constructor_args = (expected_host, ARGS) + if not TWO_SIX: + cls_name += 'Connection' mocked_HTTPConnection = mocker.replace(cls_name, passthrough=False) mocked_connection = mocked_HTTPConnection(*expected_constructor_args) # nospec() is required because of @@ -58,6 +65,8 @@ mocker.nospec() auth_data = [] mocked_connection.putrequest(ARGS, KWARGS) + if TWO_SIX: + mocked_connection.send(ARGS, KWARGS) def match_header(header, *values): if header.lower() == 'authorization': @@ -72,10 +81,19 @@ mocked_connection.endheaders(ARGS, KWARGS) - mocked_connection.getresponse(ARGS, KWARGS) - s = StringIO.StringIO(xmlrpclib.dumps((1,), methodresponse=True)) - s.status = 200 - mocker.result(s) + if TWO_SIX: + mocked_connection.getreply(ARGS, KWARGS) + mocker.result((200, None, None)) + s = StringIO.StringIO(xmlrpclib.dumps((1,), methodresponse=True)) + mocked_connection.getfile() + mocker.result(s) + mocked_connection._conn + mocker.result(None) + else: + mocked_connection.getresponse(ARGS, KWARGS) + s = StringIO.StringIO(xmlrpclib.dumps((1,), methodresponse=True)) + s.status = 200 + mocker.result(s) mocked_connection.close() mocker.count(0, 1)