Skip to content
This repository was archived by the owner on Aug 29, 2019. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ language: python
python:
- "2.6"
- "2.7"
- "3.6"

install: "pip install . --use-mirrors"
install: "pip install ."

script: python setup.py nosetests

Expand Down
7 changes: 5 additions & 2 deletions aweber_api/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from urlparse import parse_qs

from aweber_api.base import (
ACCESS_TOKEN_URL,
APIException,
Expand All @@ -13,6 +11,11 @@
from aweber_api.oauth import OAuthAdapter
from aweber_api.response import AWeberResponse

try:
from urlparse import parse_qs
except ImportError:
from urllib.parse import parse_qs


class AWeberAPI(AWeberBase):
"""Base class for connecting to the AWeberAPI.
Expand Down
14 changes: 11 additions & 3 deletions aweber_api/collection.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
from math import floor
from urlparse import parse_qs
from urllib import urlencode

from aweber_api.base import API_BASE
from aweber_api.entry import AWeberEntry
from aweber_api.response import AWeberResponse

try:
from urlparse import parse_qs
from urllib import urlencode
except ImportError:
from urllib.parse import parse_qs, urlencode


class AWeberCollection(AWeberResponse):
"""Represents a collection of similar objects.
Expand Down Expand Up @@ -122,14 +126,18 @@ def __len__(self):
def __iter__(self):
return self

def next(self):
def __next__(self):
"""Get the next entry in the collection."""
if self._current < self.total_size:
self._current += 1
return self[self._current - 1]
self._current = 0
raise StopIteration

def next(self):
"""Added for python2 compatibility"""
return self.__next__()

def __getitem__(self, offset):
if offset < 0 or offset >= self._data['total_size']:
raise ValueError('Offset {0} does not exist'.format(offset))
Expand Down
7 changes: 5 additions & 2 deletions aweber_api/entry.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
from urllib import urlencode

import aweber_api
from aweber_api.data_dict import DataDict
from aweber_api.response import AWeberResponse

try:
from urllib import urlencode
except ImportError:
from urllib.parse import urlencode


class AWeberEntry(AWeberResponse):
"""Represents a single entry in the AWeber API data heirarchy.
Expand Down
11 changes: 9 additions & 2 deletions aweber_api/oauth.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
from urllib import urlencode
import json
import os

import oauth2 as oauth
import six

from aweber_api.base import APIException

try:
from urllib import urlencode
except ImportError:
from urllib.parse import urlencode


class OAuthAdapter(object):

Expand Down Expand Up @@ -61,7 +66,9 @@ def request(self, method, url, data={}, response='body'):
raise APIException(
'{0}: {1}'.format(error_type, error_msg))

if response == 'body' and isinstance(content, str):
if isinstance(content, six.binary_type):
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! Looks good aside from needing to pull in six as a requirement. Can you check this without it?

An example from http://python3porting.com/noconv.html#more-bytes-strings-and-unicode:

>>> from __future__ import unicode_literals
>>> import sys
>>> if sys.version_info < (3,):
...     text_type = unicode
...     binary_type = str
... else:
...     text_type = str
...     binary_type = bytes
>>> isinstance('U\xf1ic\xf6de', text_type)
True

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. I'll update this

content = content.decode('utf-8')
if response == 'body' and isinstance(content, six.string_types):
return self._parse(content)
if response == 'status':
return resp['status']
Expand Down
Empty file added tests/__init__.py
Empty file.
11 changes: 7 additions & 4 deletions tests/mock_adapter.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import json
import os
from urlparse import urlparse, parse_qs
from urllib import quote

import mock

from aweber_api import AWeberUser
from aweber_api import OAuthAdapter
from aweber_api import AWeberUser, OAuthAdapter

try:
from urllib import quote
from urlparse import urlparse, parse_qs
except ImportError:
from urllib.parse import urlparse, parse_qs, quote

__all__ = ['MockAdapter']

Expand Down
2 changes: 1 addition & 1 deletion tests/test_aweber_api.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from unittest import TestCase
from mock_adapter import MockAdapter
from tests.mock_adapter import MockAdapter
from mock import Mock
from aweber_api import (AWeberAPI, AWeberUser, ACCESS_TOKEN_URL, AUTHORIZE_URL,
REQUEST_TOKEN_URL, AWeberEntry)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_aweber_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from aweber_api import AWeberAPI, AWeberCollection, AWeberEntry
from aweber_api.base import API_BASE, APIException
from mock_adapter import MockAdapter
from tests.mock_adapter import MockAdapter


class TestAWeberCollection(TestCase):
Expand Down
8 changes: 6 additions & 2 deletions tests/test_aweber_entry.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import re
from unittest import TestCase
from urllib import urlencode

from aweber_api import AWeberAPI, AWeberCollection, AWeberEntry
from aweber_api.base import APIException
from mock_adapter import MockAdapter
from tests.mock_adapter import MockAdapter

try:
from urllib import urlencode
except ImportError:
from urllib.parse import urlencode


class TestAWeberEntry(TestCase):
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# When making changes, make sure to also edit the .travis.yml file.

[tox]
envlist = py26, py27
envlist = py26, py27, py36

[testenv]
commands = python setup.py nosetests []
Expand Down