Skip to content

Commit

Permalink
Merge pull request Scifabric#1909 from Scifabric/migrate-python3
Browse files Browse the repository at this point in the history
Migrate python3
  • Loading branch information
teleyinex authored Dec 28, 2019
2 parents 480be9d + 215a404 commit 3eb0895
Show file tree
Hide file tree
Showing 182 changed files with 2,708 additions and 2,617 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,14 @@ PYBOSSA allows data capture for further analysis made by users in a transparent

# PYBOSSA for python 3

We've finally migrated PYBOSSA to python 3. We're not going to merge into master until we test it in production a bit
more, so please, help us by testing it. All you have to do is basically, check out the python3 branch (migrate-python3) and run
it. Then, any bug, issue you find, you just report it and we will be happy to help you.
PYBOSSA runs in python >= 3.6. While 3.8 has been released recently, it needs testing before officially support it.

If you have a python2.7 server, please, checkout the python2.7 branch and use that one for your server.

## Get professional support

You can hire us to help you with your PYBOSSA project. Go to our website, and [contact us](https://scifabric.com/).
You can hire us to help you with your PYBOSSA project or server (specially for python 2.7). Go to our website, and [contact us](https://scifabric.com/).


### Supporting PYBOSSA

Expand Down
2 changes: 1 addition & 1 deletion circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ jobs:
build:
working_directory: ~/circulate
docker:
- image: scifabric/python2.7-ldap
- image: scifabric/python3.6-ldap
environment:
FLASK_CONFIG: testing
TEST_DATABASE_URL: postgresql://rtester:rtester@localhost/pybossa_test?sslmode=disable
Expand Down
144 changes: 72 additions & 72 deletions cli.py

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pybossa/anonymizer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ def __init__(self, app=None):
self.init_app(app)

def init_app(self, app):
cp = CryptoPAn(app.config.get('CRYPTOPAN_KEY'))
cp = CryptoPAn(str.encode(app.config.get('CRYPTOPAN_KEY')))
self.ip = cp.anonymize
42 changes: 21 additions & 21 deletions pybossa/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,20 @@
from pybossa.cache.projects import n_tasks
import pybossa.sched as sched
from pybossa.error import ErrorStatus
from global_stats import GlobalStatsAPI
from task import TaskAPI
from task_run import TaskRunAPI
from project import ProjectAPI
from announcement import AnnouncementAPI
from blogpost import BlogpostAPI
from category import CategoryAPI
from favorites import FavoritesAPI
from user import UserAPI
from token import TokenAPI
from result import ResultAPI
from project_stats import ProjectStatsAPI
from helpingmaterial import HelpingMaterialAPI
from page import PageAPI
from .global_stats import GlobalStatsAPI
from .task import TaskAPI
from .task_run import TaskRunAPI
from .project import ProjectAPI
from .announcement import AnnouncementAPI
from .blogpost import BlogpostAPI
from .category import CategoryAPI
from .favorites import FavoritesAPI
from .user import UserAPI
from .token import TokenAPI
from .result import ResultAPI
from .project_stats import ProjectStatsAPI
from .helpingmaterial import HelpingMaterialAPI
from .page import PageAPI
from pybossa.core import project_repo, task_repo
from pybossa.contributions_guard import ContributionsGuard
from pybossa.auth import jwt_authorize_project
Expand Down Expand Up @@ -152,7 +152,7 @@ def _retrieve_new_task(project_id):
if project is None:
raise NotFound

if not project.allow_anonymous_contributors and current_user.is_anonymous():
if not project.allow_anonymous_contributors and current_user.is_anonymous:
info = dict(
error="This project does not allow anonymous contributors")
error = [model.task.Task(info=info)]
Expand Down Expand Up @@ -187,9 +187,9 @@ def _retrieve_new_task(project_id):
else:
desc = False

user_id = None if current_user.is_anonymous() else current_user.id
user_id = None if current_user.is_anonymous else current_user.id
user_ip = (anonymizer.ip(request.remote_addr or '127.0.0.1')
if current_user.is_anonymous() else None)
if current_user.is_anonymous else None)
external_uid = request.args.get('external_uid')
task = sched.new_task(project_id, project.info.get('sched'),
user_id,
Expand Down Expand Up @@ -229,7 +229,7 @@ def user_progress(project_id=None, short_name=None):
# For now, keep this version, but wait until redis cache is
# used here for task_runs too
query_attrs = dict(project_id=project.id)
if current_user.is_anonymous():
if current_user.is_anonymous:
query_attrs['user_ip'] = anonymizer.ip(request.remote_addr or
'127.0.0.1')
else:
Expand Down Expand Up @@ -270,7 +270,7 @@ def auth_jwt_project(short_name):
def get_disqus_sso_api():
"""Return remote_auth_s3 and api_key for disqus SSO."""
try:
if current_user.is_authenticated():
if current_user.is_authenticated:
message, timestamp, sig, pub_key = get_disqus_sso_payload(current_user)
else:
message, timestamp, sig, pub_key = get_disqus_sso_payload(None)
Expand All @@ -282,5 +282,5 @@ def get_disqus_sso_api():
else:
raise MethodNotAllowed
except MethodNotAllowed as e:
e.message = "Disqus keys are missing"
return error.format_exception(e, target='DISQUS_SSO', action='GET')
return error.format_exception(e, target='DISQUS_SSO', action='GET',
message="Disqus keys are missing")
6 changes: 3 additions & 3 deletions pybossa/api/announcement.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* announcement
"""
from api_base import APIBase
from .api_base import APIBase
from pybossa.model.announcement import Announcement
from pybossa.core import user_repo, project_repo
from flask_login import current_user
Expand All @@ -38,10 +38,10 @@ class AnnouncementAPI(APIBase):
__class__ = Announcement

def _forbidden_attributes(self, data):
for key in data.keys():
for key in list(data.keys()):
if key in self.reserved_keys:
raise BadRequest("Reserved keys in payload")

def _update_object(self, obj):
if not current_user.is_anonymous():
if not current_user.is_anonymous:
obj.user_id = current_user.id
17 changes: 9 additions & 8 deletions pybossa/api/api_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
* etc.
"""
import six
import json
from flask import request, abort, Response, current_app
from flask_login import current_user
Expand Down Expand Up @@ -111,7 +112,7 @@ def refresh_cache(self, cls_name, oid):

def valid_args(self):
"""Check if the domain object args are valid."""
for k in request.args.keys():
for k in list(request.args.keys()):
if k not in ['api_key']:
getattr(self.__class__, k)

Expand Down Expand Up @@ -150,7 +151,7 @@ def _create_json_response(self, query_result, oid):
for result in query_result:
# This is for n_favs orderby case
if not isinstance(result, DomainObject):
if 'n_favs' in result.keys():
if 'n_favs' in list(result.keys()):
result = result[0]
try:
if (result.__class__ != self.__class__):
Expand Down Expand Up @@ -241,15 +242,15 @@ def _db_query(self, oid):
return results

def api_context(self, all_arg, **filters):
if current_user.is_authenticated():
if current_user.is_authenticated:
filters['owner_id'] = current_user.id
if filters.get('owner_id') and all_arg == '1':
del filters['owner_id']
return filters

def _filter_query(self, repo_info, limit, offset, orderby):
filters = {}
for k in request.args.keys():
for k in list(request.args.keys()):
if k not in ['limit', 'offset', 'api_key', 'last_id', 'all',
'fulltextsearch', 'desc', 'orderby', 'related',
'participated', 'full', 'stats']:
Expand Down Expand Up @@ -500,7 +501,7 @@ def _file_upload(self, data):
if (content_type in request_headers and
cls_name in self.allowed_classes_upload):
tmp = dict()
for key in request.form.keys():
for key in list(request.form.keys()):
tmp[key] = request.form[key]
if isinstance(self, announcement.Announcement):
# don't check project id for announcements
Expand All @@ -518,7 +519,7 @@ def _file_upload(self, data):
if request.files.get('file') is None:
raise AttributeError
_file = request.files['file']
if current_user.is_authenticated():
if current_user.is_authenticated:
if current_user.admin:
container = "user_%s" % project.owner.id
else:
Expand All @@ -535,7 +536,7 @@ def _file_upload(self, data):
tmp['media_url'] = file_url
if tmp.get('info') is None:
tmp['info'] = dict()
elif type(tmp['info']) is unicode:
elif type(tmp['info']) is six.text_type:
tmp['info'] = json.loads(tmp['info'])
tmp['info']['container'] = container
tmp['info']['file_name'] = _file.filename
Expand All @@ -547,7 +548,7 @@ def _file_delete(self, request, obj):
"""Delete file object."""
cls_name = self.__class__.__name__.lower()
if cls_name in self.allowed_classes_upload:
keys = obj.info.keys()
keys = list(obj.info.keys())
if 'file_name' in keys and 'container' in keys:
ensure_authorized_to('delete', obj)
uploader.delete_file(obj.info['file_name'],
Expand Down
6 changes: 3 additions & 3 deletions pybossa/api/blogpost.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* blopost
"""
from api_base import APIBase
from .api_base import APIBase
from pybossa.model.blogpost import Blogpost
from pybossa.core import user_repo, project_repo
from flask_login import current_user
Expand All @@ -38,11 +38,11 @@ class BlogpostAPI(APIBase):
__class__ = Blogpost

def _forbidden_attributes(self, data):
for key in data.keys():
for key in list(data.keys()):
if key in self.reserved_keys:
msg = "Reserved keys in payload: %s" % key
raise BadRequest(msg)

def _update_object(self, obj):
if not current_user.is_anonymous():
if not current_user.is_anonymous:
obj.user_id = current_user.id
4 changes: 2 additions & 2 deletions pybossa/api/category.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"""
from werkzeug.exceptions import BadRequest
from api_base import APIBase
from .api_base import APIBase
from pybossa.model.category import Category


Expand All @@ -36,7 +36,7 @@ class CategoryAPI(APIBase):
__class__ = Category

def _forbidden_attributes(self, data):
for key in data.keys():
for key in list(data.keys()):
if key in self.reserved_keys:
msg = "Reserved keys in payload: %s" % key
raise BadRequest(msg)
16 changes: 8 additions & 8 deletions pybossa/api/favorites.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
"""
import json
from api_base import APIBase
from .api_base import APIBase
from pybossa.core import task_repo
from flask_login import current_user, request
from flask import Response, abort
from flask_login import current_user
from flask import Response, abort, request
from werkzeug.exceptions import MethodNotAllowed, NotFound, Unauthorized
from pybossa.core import ratelimits
from pybossa.util import jsonpify, fuzzyboolean
Expand All @@ -48,12 +48,12 @@ class FavoritesAPI(APIBase):
def get(self, oid):
"""Return all the tasks favorited by current user."""
try:
if current_user.is_anonymous():
if current_user.is_anonymous:
raise abort(401)
uid = current_user.id
limit, offset, orderby = self._set_limit_and_offset()
last_id = request.args.get('last_id')
print last_id
print(last_id)
desc = request.args.get('desc') if request.args.get('desc') else False
desc = fuzzyboolean(desc)

Expand All @@ -78,9 +78,9 @@ def post(self):
try:
self.valid_args()
data = json.loads(request.data)
if (len(data.keys()) != 1) or ('task_id' not in data.keys()):
if (len(list(data.keys())) != 1) or ('task_id' not in list(data.keys())):
raise AttributeError
if current_user.is_anonymous():
if current_user.is_anonymous:
raise Unauthorized
uid = current_user.id
tasks = task_repo.get_task_favorited(uid, data['task_id'])
Expand Down Expand Up @@ -109,7 +109,7 @@ def post(self):
def delete(self, oid):
"""Delete User ID from task as a favorite."""
try:
if current_user.is_anonymous():
if current_user.is_anonymous:
raise abort(401)
uid = current_user.id
tasks = task_repo.get_task_favorited(uid, oid)
Expand Down
2 changes: 1 addition & 1 deletion pybossa/api/global_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"""
import json
from api_base import APIBase
from .api_base import APIBase
from flask import Response
import pybossa.cache.site_stats as stats
import pybossa.cache.projects as cached_projects
Expand Down
6 changes: 3 additions & 3 deletions pybossa/api/helpingmaterial.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* helpingmaterial
"""
from api_base import APIBase
from .api_base import APIBase
from pybossa.model.helpingmaterial import HelpingMaterial
from flask_login import current_user
from werkzeug.exceptions import BadRequest
Expand All @@ -37,10 +37,10 @@ class HelpingMaterialAPI(APIBase):
__class__ = HelpingMaterial

def _forbidden_attributes(self, data):
for key in data.keys():
for key in list(data.keys()):
if key in self.reserved_keys:
raise BadRequest("Reserved keys in payload")

def _update_object(self, obj):
if not current_user.is_anonymous():
if not current_user.is_anonymous:
obj.user_id = current_user.id
4 changes: 2 additions & 2 deletions pybossa/api/page.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* page
"""
from api_base import APIBase
from .api_base import APIBase
from pybossa.model.page import Page
from flask_login import current_user
from werkzeug.exceptions import BadRequest
Expand All @@ -42,5 +42,5 @@ def _forbidden_attributes(self, data):
raise BadRequest("Reserved keys in payload")

def _update_object(self, obj):
if not current_user.is_anonymous():
if not current_user.is_anonymous:
obj.user_id = current_user.id
Loading

0 comments on commit 3eb0895

Please sign in to comment.