summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Kehrer <paul.l.kehrer@gmail.com>2014-03-20 10:33:10 -0400
committerPaul Kehrer <paul.l.kehrer@gmail.com>2014-03-20 10:33:10 -0400
commitbc637ec80926e854fd9c6cfb31e74aa84772a977 (patch)
treed92bf9b226ae921f53582ad8366781e36db1eefd
parentcc78b2a2a8c08322a64fa56ce17d06628b18485a (diff)
downloadpython-barbicanclient-bc637ec80926e854fd9c6cfb31e74aa84772a977.tar.gz
python 3 support
Change-Id: If4bc02d103ed0daa54ba411199cdb0bac6ba3712
-rw-r--r--barbicanclient/barbican.py22
-rw-r--r--barbicanclient/base.py3
-rw-r--r--barbicanclient/common/auth.py1
-rw-r--r--barbicanclient/secrets.py5
-rw-r--r--barbicanclient/test/common/test_auth.py10
-rw-r--r--barbicanclient/test/test_barbican.py5
-rw-r--r--barbicanclient/test/test_client.py2
-rw-r--r--barbicanclient/test/test_client_orders.py2
-rw-r--r--barbicanclient/test/test_client_secrets.py2
-rw-r--r--barbicanclient/test/test_client_verifications.py2
-rw-r--r--requirements.txt1
11 files changed, 32 insertions, 23 deletions
diff --git a/barbicanclient/barbican.py b/barbicanclient/barbican.py
index 04cf733..ea2297f 100644
--- a/barbicanclient/barbican.py
+++ b/barbicanclient/barbican.py
@@ -233,7 +233,7 @@ class Barbican:
args.bit_length,
args.mode,
args.expiration)
- print secret
+ print(secret)
else:
self.parser.exit(status=1, message='ERROR: store is only supported'
' for secrets\n')
@@ -246,7 +246,7 @@ class Barbican:
args.bit_length,
args.mode,
args.expiration)
- print order
+ print(order)
else:
self.parser.exit(status=1, message='ERROR: create is only '
'supported for orders\n')
@@ -266,14 +266,14 @@ class Barbican:
def get(self, args):
if args.command == 'secret':
if args.decrypt:
- print self.client.secrets.decrypt(args.URI,
- args.payload_content_type)
+ print(self.client.secrets.decrypt(args.URI,
+ args.payload_content_type))
else:
- print self.client.secrets.get(args.URI)
+ print(self.client.secrets.get(args.URI))
elif args.command == 'verification':
- print self.client.verifications.get(args.URI)
+ print(self.client.verifications.get(args.URI))
elif args.command == 'order':
- print self.client.orders.get(args.URI)
+ print(self.client.orders.get(args.URI))
else:
self.parser.exit(status=1, message='ERROR: get is only '
'supported for secrets, '
@@ -296,9 +296,9 @@ class Barbican:
'supported for secrets, '
'orders or verifications\n')
for obj in ls:
- print obj
- print '{0}s displayed: {1} - offset: {2}'.format(args.command, len(ls),
- args.offset)
+ print(obj)
+ print('{0}s displayed: {1} - offset: {2}'.format(args.command, len(ls),
+ args.offset))
def verify(self, args):
if args.command == 'verification':
@@ -307,7 +307,7 @@ class Barbican:
resource_ref=args.ref,
resource_action=args.action,
impersonation_allowed=args.impersonation)
- print verify
+ print(verify)
else:
self.parser.exit(status=1, message='ERROR: verify is only '
'supported for verifications\n')
diff --git a/barbicanclient/base.py b/barbicanclient/base.py
index 5e63f88..802a878 100644
--- a/barbicanclient/base.py
+++ b/barbicanclient/base.py
@@ -23,7 +23,8 @@ class BaseEntityManager(object):
self.entity = entity
def _remove_empty_keys(self, dictionary):
- for k in dictionary.keys():
+ copied_dict = dictionary.copy()
+ for k in copied_dict.keys():
if dictionary[k] is None:
dictionary.pop(k)
diff --git a/barbicanclient/common/auth.py b/barbicanclient/common/auth.py
index 9711ac2..aeefd4d 100644
--- a/barbicanclient/common/auth.py
+++ b/barbicanclient/common/auth.py
@@ -126,7 +126,6 @@ class RackspaceAuthV2(AuthPluginBase):
payload = self._authenticate_with_password()
r = requests.post(auth_url, data=json.dumps(payload), headers=headers)
-
try:
r.raise_for_status()
except requests.HTTPError:
diff --git a/barbicanclient/secrets.py b/barbicanclient/secrets.py
index e8d2040..0ef9fc6 100644
--- a/barbicanclient/secrets.py
+++ b/barbicanclient/secrets.py
@@ -13,9 +13,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import logging
-import urlparse
import re
+import six
+
from barbicanclient import base
from barbicanclient.openstack.common.timeutils import parse_isotime
@@ -129,7 +130,7 @@ class SecretManager(base.BaseEntityManager):
if not secret_ref:
raise ValueError('secret_ref is required.')
try:
- url = urlparse.urlparse(secret_ref)
+ url = six.moves.urllib.parse.urlparse(secret_ref)
parts = url.path.rstrip('/').split('/')
reuuid = re.compile(r'[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-'
'[0-9a-f]{4}-[0-9a-f]{12}', re.I)
diff --git a/barbicanclient/test/common/test_auth.py b/barbicanclient/test/common/test_auth.py
index 52db65c..d728aef 100644
--- a/barbicanclient/test/common/test_auth.py
+++ b/barbicanclient/test/common/test_auth.py
@@ -79,7 +79,7 @@ class WhenTestingRackspaceAuthentication(testtools.TestCase):
}
}
}
- })
+ }).encode("ascii")
patcher = mock.patch('barbicanclient.common.auth.requests.post')
self._mock_post = patcher.start()
@@ -99,6 +99,7 @@ class WhenTestingRackspaceAuthentication(testtools.TestCase):
api_key=self._api_key)
def test_tokens_is_appended_to_auth_url(self):
+ self._response.status_code = 200
identity = auth.RackspaceAuthV2(self._auth_url,
self._username,
api_key=self._api_key)
@@ -108,6 +109,7 @@ class WhenTestingRackspaceAuthentication(testtools.TestCase):
headers=mock.ANY)
def test_authenticate_with_api_key(self):
+ self._response.status_code = 200
with mock.patch(
'barbicanclient.common.auth.RackspaceAuthV2.'
'_authenticate_with_api_key'
@@ -119,6 +121,7 @@ class WhenTestingRackspaceAuthentication(testtools.TestCase):
mock_authenticate.assert_called_once_with()
def test_authenticate_with_password(self):
+ self._response.status_code = 200
with mock.patch(
'barbicanclient.common.auth.RackspaceAuthV2.'
'_authenticate_with_password'
@@ -137,19 +140,22 @@ class WhenTestingRackspaceAuthentication(testtools.TestCase):
api_key=self._api_key)
def test_error_raised_for_bad_response_from_server(self):
- self._response._content = 'Not JSON'
+ self._response._content = b'Not JSON'
+ self._response.status_code = 200
with testtools.ExpectedException(auth.AuthException):
auth.RackspaceAuthV2(self._auth_url,
self._username,
api_key=self._api_key)
def test_auth_token_is_set(self):
+ self._response.status_code = 200
identity = auth.RackspaceAuthV2(self._auth_url,
self._username,
api_key=self._api_key)
self.assertEqual(identity.auth_token, self._auth_token)
def test_tenant_id_is_set(self):
+ self._response.status_code = 200
identity = auth.RackspaceAuthV2(self._auth_url,
self._username,
api_key=self._api_key)
diff --git a/barbicanclient/test/test_barbican.py b/barbicanclient/test/test_barbican.py
index 2c9f512..cdf2bc8 100644
--- a/barbicanclient/test/test_barbican.py
+++ b/barbicanclient/test/test_barbican.py
@@ -13,9 +13,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-import cStringIO
import os
import sys
+
+import six
import testtools
import barbicanclient.barbican
@@ -28,7 +29,7 @@ class TestBarbican(testtools.TestCase):
clean_env = {}
_old_env, os.environ = os.environ, clean_env.copy()
try:
- sys.stdout = cStringIO.StringIO()
+ sys.stdout = six.StringIO()
_barbican = barbicanclient.barbican.Barbican()
_barbican.execute(argv=argstr.split())
except SystemExit:
diff --git a/barbicanclient/test/test_client.py b/barbicanclient/test/test_client.py
index f69fb3e..5e33633 100644
--- a/barbicanclient/test/test_client.py
+++ b/barbicanclient/test/test_client.py
@@ -64,7 +64,7 @@ class WhenTestingClientInit(testtools.TestCase):
def _mock_response(self, content=None, status_code=200):
resp = requests.Response()
- resp._content = content or '{"title": {"generic mocked response"}}'
+ resp._content = content or b'{"title": "generic mocked response"}'
resp.status_code = status_code
return resp
diff --git a/barbicanclient/test/test_client_orders.py b/barbicanclient/test/test_client_orders.py
index a554862..d7d8c53 100644
--- a/barbicanclient/test/test_client_orders.py
+++ b/barbicanclient/test/test_client_orders.py
@@ -105,7 +105,7 @@ class WhenTestingOrders(test_client.BaseEntityResource):
def test_should_get_list(self):
order_resp = self.order.get_dict(self.entity_href)
self.api.get.return_value = {"orders":
- [order_resp for v in xrange(3)]}
+ [order_resp for v in range(3)]}
orders_list = self.manager.list(limit=10, offset=5)
self.assertTrue(len(orders_list) == 3)
diff --git a/barbicanclient/test/test_client_secrets.py b/barbicanclient/test/test_client_secrets.py
index f93df26..ce04eae 100644
--- a/barbicanclient/test/test_client_secrets.py
+++ b/barbicanclient/test/test_client_secrets.py
@@ -145,7 +145,7 @@ class WhenTestingSecrets(test_client.BaseEntityResource):
def test_should_get_list(self):
secret_resp = self.secret.get_dict(self.entity_href)
self.api.get.return_value = {"secrets":
- [secret_resp for v in xrange(3)]}
+ [secret_resp for v in range(3)]}
secrets_list = self.manager.list(limit=10, offset=5)
self.assertTrue(len(secrets_list) == 3)
diff --git a/barbicanclient/test/test_client_verifications.py b/barbicanclient/test/test_client_verifications.py
index d887ac3..0c13f2a 100644
--- a/barbicanclient/test/test_client_verifications.py
+++ b/barbicanclient/test/test_client_verifications.py
@@ -109,7 +109,7 @@ class WhenTestingVerifications(test_client.BaseEntityResource):
def test_should_get_list(self):
verify_resp = self.verify.get_dict(self.entity_href)
self.api.get.return_value = {"verifications":
- [verify_resp for v in xrange(3)]}
+ [verify_resp for v in range(3)]}
verifies = self.manager.list(limit=10, offset=5)
self.assertTrue(len(verifies) == 3)
diff --git a/requirements.txt b/requirements.txt
index 633e333..86ce461 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -2,4 +2,5 @@ pbr>=0.5.21,<1.0
argparse
requests>=1.2.3
+six>=1.5.2
python-keystoneclient>=0.3.2