Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Python 3 #26

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
14 changes: 9 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
sudo: false

language: python

python:
- "2.7"
- 2.7
- 3.4

install:
- pip install -r requirements.txt --use-mirrors
- pip install rednose
- pip install nose
- pip install mock
script: nosetests
- pip install -r requirements-dev.txt --use-mirrors

script: python $(which nosetests)

after_success:
- pip install coveralls
- coveralls
18 changes: 11 additions & 7 deletions pbclient/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

import requests
import json
import six


OFFSET_WARNING = """
INFO: you can use keyset pagination to get faster responses from the server.
Expand Down Expand Up @@ -50,7 +52,8 @@ def _pybossa_req(method, domain, id=None, payload=None, params={}):
elif method == 'delete':
r = requests.delete(url, params=params, headers=headers,
data=json.dumps(payload))
if r.status_code / 100 == 2:

if r.status_code // 100 == 2: # PEP 238: Use the // floor division operator
if r.text and r.text != '""':
return json.loads(r.text)
else:
Expand Down Expand Up @@ -152,7 +155,7 @@ def get_projects(limit=100, offset=0, last_id=None):
if last_id is not None:
params = dict(limit=limit, last_id=last_id)
else:
print OFFSET_WARNING
six.print_(OFFSET_WARNING)
params = dict(limit=limit, offset=offset)
try:
res = _pybossa_req('get', 'project',
Expand Down Expand Up @@ -283,7 +286,7 @@ def get_categories(limit=20, offset=0, last_id=None):
params = dict(limit=limit, last_id=last_id)
else:
params = dict(limit=limit, offset=offset)
print OFFSET_WARNING
six.print_(OFFSET_WARNING)
try:
res = _pybossa_req('get', 'category',
params=params)
Expand Down Expand Up @@ -410,7 +413,7 @@ def get_tasks(project_id, limit=100, offset=0, last_id=None):
params = dict(limit=limit, last_id=last_id)
else:
params = dict(limit=limit, offset=offset)
print OFFSET_WARNING
six.print_(OFFSET_WARNING)
params['project_id'] = project_id
try:
res = _pybossa_req('get', 'task',
Expand Down Expand Up @@ -536,7 +539,7 @@ def get_taskruns(project_id, limit=100, offset=0, last_id=None):
params = dict(limit=limit, last_id=last_id)
else:
params = dict(limit=limit, offset=offset)
print OFFSET_WARNING
six.print_(OFFSET_WARNING)
params['project_id'] = project_id
try:
res = _pybossa_req('get', 'taskrun',
Expand Down Expand Up @@ -587,7 +590,8 @@ def delete_taskrun(taskrun_id):

def _forbidden_attributes(obj):
"""Return the object without the forbidden attributes."""
for key in obj.data.keys():
if key in obj.reserved_keys.keys():

for key in list(six.iterkeys(obj.data)):
if key in list(six.iterkeys(obj.reserved_keys)):
obj.data.pop(key)
return obj
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
requests>=0.13.0
six