From 1288f694d51c13d12e6d61a1349b758ac8eab893 Mon Sep 17 00:00:00 2001 From: David Stanek Date: Wed, 29 Jan 2014 05:18:49 +0000 Subject: [PATCH] Sync oslo's policy module I made some changes to the policy module in oslo to use six.moves.urllib instead of py3kcompat.urlutils. This change will help us on our way to being more Python3 friendly. Our test_policy tests had to be updated because we are stubbing implementation details in policy. Change-Id: I23377a4c71f0f0cb58518f0cd5ce341a8a9c4243 Implements: bp keystone-py3kcompat --- keystone/openstack/common/policy.py | 11 ++++++----- keystone/tests/test_policy.py | 6 +++--- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/keystone/openstack/common/policy.py b/keystone/openstack/common/policy.py index 16b848d042..7bbf93f21c 100644 --- a/keystone/openstack/common/policy.py +++ b/keystone/openstack/common/policy.py @@ -56,17 +56,18 @@ as it allows particular rules to be explicitly disabled. import abc import re -import urllib -import urllib2 from oslo.config import cfg import six +import six.moves.urllib.parse as urlparse +import six.moves.urllib.request as urlrequest from keystone.openstack.common import fileutils -from keystone.openstack.common.gettextutils import _ # noqa +from keystone.openstack.common.gettextutils import _ from keystone.openstack.common import jsonutils from keystone.openstack.common import log as logging + policy_opts = [ cfg.StrOpt('policy_file', default='policy.json', @@ -824,8 +825,8 @@ class HttpCheck(Check): url = ('http:' + self.match) % target data = {'target': jsonutils.dumps(target), 'credentials': jsonutils.dumps(creds)} - post_data = urllib.urlencode(data) - f = urllib2.urlopen(url, post_data) + post_data = urlparse.urlencode(data) + f = urlrequest.urlopen(url, post_data) return f.read() == "True" diff --git a/keystone/tests/test_policy.py b/keystone/tests/test_policy.py index e0d33c99f9..4878e80760 100644 --- a/keystone/tests/test_policy.py +++ b/keystone/tests/test_policy.py @@ -17,9 +17,9 @@ import json import tempfile -import urllib2 import six +from six.moves.urllib import request as urlrequest from testtools import matchers from keystone import config @@ -110,7 +110,7 @@ class PolicyTestCase(tests.TestCase): def fakeurlopen(url, post_data): return six.StringIO("True") - self.stubs.Set(urllib2, 'urlopen', fakeurlopen) + self.stubs.Set(urlrequest, 'urlopen', fakeurlopen) action = "example:get_http" target = {} result = rules.enforce(self.credentials, action, target) @@ -120,7 +120,7 @@ class PolicyTestCase(tests.TestCase): def fakeurlopen(url, post_data): return six.StringIO("False") - self.stubs.Set(urllib2, 'urlopen', fakeurlopen) + self.stubs.Set(urlrequest, 'urlopen', fakeurlopen) action = "example:get_http" target = {} self.assertRaises(exception.ForbiddenAction, rules.enforce,