From 2ae9a24a338241a0541628e8fe9d9eee49f9017e Mon Sep 17 00:00:00 2001 From: Paul Tagliamonte Date: Tue, 10 Mar 2015 00:02:59 -0400 Subject: [PATCH 1/2] Start initial work on a Python 3 port This just gets the tests passing, no further work in validating the bindings on Python 3 was done yet. --- inbox/client/client.py | 4 ++-- inbox/client/errors.py | 2 +- inbox/client/restful_models.py | 8 ++++++-- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/inbox/client/client.py b/inbox/client/client.py index 2fdbdc55..729c4af9 100644 --- a/inbox/client/client.py +++ b/inbox/client/client.py @@ -185,7 +185,7 @@ def _get_resources(self, namespace, cls, **filters): response = self._get_http_session(cls.api_root).get(url) results = _validate(response).json() - return map(lambda x: cls.create(self, namespace, **x), results) + return list(map(lambda x: cls.create(self, namespace, **x), results)) @inbox_excepted def _get_resource_raw(self, namespace, cls, id, **filters): @@ -242,7 +242,7 @@ def _create_resources(self, namespace, cls, data): response = session.post(url, data=data, headers=headers) results = _validate(response).json() - return map(lambda x: cls.create(self, namespace, **x), results) + return list(map(lambda x: cls.create(self, namespace, **x), results)) @inbox_excepted def _delete_resource(self, namespace, cls, id): diff --git a/inbox/client/errors.py b/inbox/client/errors.py index 141f6582..895a2d00 100644 --- a/inbox/client/errors.py +++ b/inbox/client/errors.py @@ -4,7 +4,7 @@ class APIClientError(Exception): def __init__(self, **kwargs): self.attrs = kwargs.keys() - for k, v in kwargs.iteritems(): + for k, v in kwargs.items(): setattr(self, k, v) Exception.__init__(self, str(kwargs)) diff --git a/inbox/client/restful_models.py b/inbox/client/restful_models.py index 2b1f9852..8f09ccf0 100644 --- a/inbox/client/restful_models.py +++ b/inbox/client/restful_models.py @@ -1,5 +1,5 @@ from .restful_model_collection import RestfulModelCollection -from cStringIO import StringIO +from six import StringIO import base64 import json @@ -18,10 +18,14 @@ def __init__(self, cls, api, namespace): self.api = api self.namespace = namespace - __getattr__ = dict.__getitem__ __setattr__ = dict.__setitem__ __delattr__ = dict.__delitem__ + def __getattr__(self, what): + if what not in self: + raise AttributeError("no such attribute: '{}'".format(what)) + return self[what] + @classmethod def create(cls, api, namespace_, **kwargs): obj = cls(api, namespace_) From ea090afd214fd12c9323a4366673e50b7c64d7f5 Mon Sep 17 00:00:00 2001 From: Paul Tagliamonte Date: Tue, 10 Mar 2015 20:19:45 -0400 Subject: [PATCH 2/2] Add in a tox config This also includes a new requirements-dev file, for test-time dependencies that we don't need at runtime. --- requirements-dev.txt | 2 ++ tox.ini | 9 +++++++++ 2 files changed, 11 insertions(+) create mode 100644 requirements-dev.txt create mode 100644 tox.ini diff --git a/requirements-dev.txt b/requirements-dev.txt new file mode 100644 index 00000000..208ec64c --- /dev/null +++ b/requirements-dev.txt @@ -0,0 +1,2 @@ +pytest +responses diff --git a/tox.ini b/tox.ini new file mode 100644 index 00000000..ec874cae --- /dev/null +++ b/tox.ini @@ -0,0 +1,9 @@ +[tox] +envlist = py27,pypy,py34 + +[testenv] +commands = + pip install -e . + py.test +deps = + -rrequirements-dev.txt