Skip to content

Commit 3657841

Browse files
committed
Merge pull request #61 from jkeyes/python3
Python3 compatibility.
2 parents a220358 + feb78b8 commit 3657841

30 files changed

+517
-363
lines changed

.travis.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
language: python
22
python:
33
- 2.7
4+
- 3.4
45
install:
56
- pip install -r requirements.txt --use-mirrors
67
- pip install -r dev-requirements.txt --use-mirrors
7-
script:
8-
- PYTHONPATH=. describe tests/unit
8+
script:
9+
- nosetests tests/unit

dev-requirements.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#
22
# Development dependencies.
33
#
4-
https://github.com/jeffh/describe/tarball/dev#egg=describe-dev
5-
httpretty==0.8.8
4+
nose==1.3.4
5+
httpretty==0.8.6
66
mock==1.0.1

intercom/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import copy
2323
import random
2424
import re
25+
import six
2526
import time
2627

2728
__version__ = '2.0.alpha'
@@ -47,7 +48,7 @@ class IntercomType(type): # noqa
4748
_endpoints = None
4849
_current_endpoint = None
4950
_target_base_url = None
50-
_endpoint_randomized_at = None
51+
_endpoint_randomized_at = 0
5152

5253
@property
5354
def _auth(self):
@@ -134,9 +135,9 @@ def endpoint(self, value):
134135
self.endpoints = [value]
135136

136137

138+
@six.add_metaclass(IntercomType)
137139
class Intercom(object):
138140
_class_register = {}
139-
__metaclass__ = IntercomType
140141

141142
@classmethod
142143
def get_url(cls, path):

intercom/api_operations/save.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ def create(cls, **params):
1313
return cls(**response)
1414

1515
def from_dict(self, pdict):
16-
for key, value in pdict.items():
16+
for key, value in list(pdict.items()):
1717
setattr(self, key, value)
1818

1919
@property
2020
def to_dict(self):
2121
a_dict = {}
22-
for name in self.__dict__.keys():
22+
for name in list(self.__dict__.keys()):
2323
if name == "changed_attributes":
2424
continue
2525
a_dict[name] = self.__dict__[name] # direct access

intercom/collection_proxy.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
# -*- coding: utf-8 -*-
22

3+
import six
34
from intercom import HttpError
45

56

6-
class CollectionProxy(object):
7+
class CollectionProxy(six.Iterator):
78

89
def __init__(self, cls, collection, finder_url, finder_params={}):
910
# needed to create class instances of the resource
@@ -27,7 +28,7 @@ def __init__(self, cls, collection, finder_url, finder_params={}):
2728
def __iter__(self):
2829
return self
2930

30-
def next(self):
31+
def __next__(self):
3132
if self.resources is None:
3233
# get the first page of results
3334
self.get_first_page()
@@ -36,18 +37,18 @@ def next(self):
3637
# current resource iterator (StopIteration is raised)
3738
# try to get the next page of results first
3839
try:
39-
resource = self.resources.next()
40+
resource = six.next(self.resources)
4041
except StopIteration:
4142
self.get_next_page()
42-
resource = self.resources.next()
43+
resource = six.next(self.resources)
4344

4445
instance = self.collection_cls(**resource)
4546
return instance
4647

4748
def __getitem__(self, index):
4849
for i in range(index):
49-
self.next()
50-
return self.next()
50+
six.next(self)
51+
return six.next(self)
5152

5253
def get_first_page(self):
5354
# get the first page of results

intercom/errors.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ class IntercomError(Exception):
1313

1414
def __init__(self, message=None, context=None):
1515
super(IntercomError, self).__init__(message)
16+
self.message = message
1617
self.context = context
1718

1819

intercom/lib/flat_store.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# -*- coding: utf-8 -*-
22

33
import numbers
4+
import six
45

56

67
class FlatStore(dict):
@@ -11,11 +12,11 @@ def __init__(self, *args, **kwargs):
1112
def __setitem__(self, key, value):
1213
if not (
1314
isinstance(value, numbers.Real) or
14-
isinstance(value, basestring)
15+
isinstance(value, six.string_types)
1516
):
1617
raise ValueError(
1718
"custom data only allows string and real number values")
18-
if not isinstance(key, basestring):
19+
if not isinstance(key, six.string_types):
1920
raise ValueError("custom data only allows string keys")
2021
super(FlatStore, self).__setitem__(key, value)
2122

intercom/request.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def send_request_to_path(cls, method, url, auth, params=None):
4040
@classmethod
4141
def parse_body(cls, resp):
4242
try:
43-
body = json.loads(resp.content)
43+
body = json.loads(resp.content.decode())
4444
except ValueError:
4545
cls.raise_errors_on_failure(resp)
4646
if body.get('type') == 'error.list':

intercom/traits/api_resource.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,15 @@ def from_response(self, response):
6363
return self
6464

6565
def from_dict(self, dict):
66-
for attribute, value in dict.items():
66+
for attribute, value in list(dict.items()):
6767
if type_field(attribute):
6868
continue
6969
setattr(self, attribute, value)
7070

7171
@property
7272
def attributes(self):
7373
res = {}
74-
for name, value in self.__dict__.items():
74+
for name, value in list(self.__dict__.items()):
7575
if self.submittable_attribute(name, value):
7676
res[name] = value
7777
return res

intercom/utils.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# -*- coding: utf-8 -*-
22

33
import inflection
4+
import six
45

56

67
def pluralize(str):
@@ -46,8 +47,9 @@ def __new__(cls, name, bases, attributes):
4647
return super(Meta, cls).__new__(
4748
cls, str(class_name), bases, attributes)
4849

50+
@six.add_metaclass(Meta)
4951
class DynamicClass(Resource, Load):
50-
__metaclass__ = Meta
52+
pass
5153

5254
dyncls = DynamicClass()
5355
CLASS_REGISTRY[class_name] = dyncls

0 commit comments

Comments
 (0)