Skip to content

Commit

Permalink
Merge pull request #355 from aarranz/feature/move-to-python3
Browse files Browse the repository at this point in the history
Remove support for Python 2
  • Loading branch information
aarranz authored Oct 30, 2018
2 parents 1d99d89 + c8ebffe commit 886d367
Show file tree
Hide file tree
Showing 113 changed files with 276 additions and 516 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ env:
- DJANGO_VERSION=1.10
- DJANGO_VERSION=1.11
python:
- "2.7"
- "3.4"
- "3.5"
- "3.6"
Expand Down
2 changes: 0 additions & 2 deletions src/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,6 @@ def read(fname):
'License :: OSI Approved :: GNU Affero General Public License v3 or later (AGPLv3+)',
'Operating System :: OS Independent',
'Programming Language :: Python',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
Expand Down
2 changes: 0 additions & 2 deletions src/wirecloud/catalogue/management/commands/addtocatalogue.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
# You should have received a copy of the GNU Affero General Public License
# along with Wirecloud. If not, see <http://www.gnu.org/licenses/>.

from __future__ import unicode_literals

import locale

from django.contrib.auth.models import User, Group
Expand Down
2 changes: 0 additions & 2 deletions src/wirecloud/catalogue/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models, migrations
from django.conf import settings

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.7 on 2017-01-30 12:24
from __future__ import unicode_literals

from django.db import migrations
import wirecloud.commons.fields

Expand Down
4 changes: 1 addition & 3 deletions src/wirecloud/catalogue/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@
# You should have received a copy of the GNU Affero General Public License
# along with Wirecloud. If not, see <http://www.gnu.org/licenses/>.

from __future__ import unicode_literals

import random
from six.moves.urllib.parse import urlparse, urljoin
from urllib.parse import urlparse, urljoin

from django.contrib.auth.models import User, Group
from django.core.cache import cache
Expand Down
4 changes: 1 addition & 3 deletions src/wirecloud/catalogue/search_indexes.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@
# You should have received a copy of the GNU Affero General Public License
# along with Wirecloud. If not, see <http://www.gnu.org/licenses/>.

from __future__ import unicode_literals

from django.db.models import Q
from six.moves.urllib.parse import urljoin
from urllib.parse import urljoin
from haystack import indexes

from wirecloud.catalogue.models import CatalogueResource, get_template_url
Expand Down
2 changes: 0 additions & 2 deletions src/wirecloud/catalogue/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
# You should have received a copy of the GNU Affero General Public License
# along with Wirecloud. If not, see <http://www.gnu.org/licenses/>.

from __future__ import unicode_literals

import json
import os

Expand Down
17 changes: 7 additions & 10 deletions src/wirecloud/catalogue/tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,10 @@
# You should have received a copy of the GNU Affero General Public License
# along with Wirecloud. If not, see <http://www.gnu.org/licenses/>.

from __future__ import unicode_literals

import errno

from django.test import TestCase
from mock import Mock, patch, DEFAULT
import six

from wirecloud.catalogue.utils import add_packaged_resource, update_resource_catalogue_cache
from wirecloud.commons.utils.template import TemplateParseException
Expand Down Expand Up @@ -250,7 +247,7 @@ def test_add_packaged_resource_invalid_longdescription_encoding(self):
add_packaged_resource(f, user, wgt_file=wgt_file, template=template, deploy_only=True)
self.fail('Expecting InvalidContents exception to be raised')
except InvalidContents as e:
self.assertIn('DESCRIPTION.md', six.text_type(e))
self.assertIn('DESCRIPTION.md', str(e))
wgt_file.read.assert_called_with('DESCRIPTION.md')

def test_add_packaged_resource_missing_longdescription_file(self):
Expand All @@ -261,7 +258,7 @@ def test_add_packaged_resource_missing_longdescription_file(self):
add_packaged_resource(f, user, wgt_file=wgt_file, template=template, deploy_only=True)
self.fail('Expecting InvalidContents exception to be raised')
except InvalidContents as e:
self.assertIn('DESCRIPTION.md', six.text_type(e))
self.assertIn('DESCRIPTION.md', str(e))

def test_add_packaged_resource_invalid_translated_longdescription_encoding(self):
f, user, wgt_file, template, file_mocks = self.build_add_packaged_resouce_mocks(['index.html', 'DESCRIPTION.md', 'doc/index.md', 'DESCRIPTION.es.md', 'CHANGELOG.md'], ['DESCRIPTION.es.md'])
Expand All @@ -271,7 +268,7 @@ def test_add_packaged_resource_invalid_translated_longdescription_encoding(self)
add_packaged_resource(f, user, wgt_file=wgt_file, template=template, deploy_only=True)
self.fail('Expecting InvalidContents exception to be raised')
except InvalidContents as e:
self.assertIn('DESCRIPTION.es.md', six.text_type(e))
self.assertIn('DESCRIPTION.es.md', str(e))

def test_add_packaged_resource_missing_userguide_file(self):
f, user, wgt_file, template, file_mocks = self.build_add_packaged_resouce_mocks(['index.html', 'DESCRIPTION.md', 'CHANGELOG.md'], [])
Expand All @@ -281,7 +278,7 @@ def test_add_packaged_resource_missing_userguide_file(self):
add_packaged_resource(f, user, wgt_file=wgt_file, template=template, deploy_only=True)
self.fail('Expecting InvalidContents exception to be raised')
except InvalidContents as e:
self.assertIn('doc/index.md', six.text_type(e))
self.assertIn('doc/index.md', str(e))

def test_add_packaged_resource_invalid_translated_userguide_encoding(self):
f, user, wgt_file, template, file_mocks = self.build_add_packaged_resouce_mocks(['index.html', 'DESCRIPTION.md', 'doc/index.md', 'doc/index.es.md', 'CHANGELOG.md'], ['doc/index.es.md'])
Expand All @@ -291,7 +288,7 @@ def test_add_packaged_resource_invalid_translated_userguide_encoding(self):
add_packaged_resource(f, user, wgt_file=wgt_file, template=template, deploy_only=True)
self.fail('Expecting InvalidContents exception to be raised')
except InvalidContents as e:
self.assertIn('doc/index.es.md', six.text_type(e))
self.assertIn('doc/index.es.md', str(e))

def test_add_packaged_resource_missing_changelog_file(self):
f, user, wgt_file, template, file_mocks = self.build_add_packaged_resouce_mocks(['index.html', 'doc/index.md', 'DESCRIPTION.md'], [])
Expand All @@ -301,7 +298,7 @@ def test_add_packaged_resource_missing_changelog_file(self):
add_packaged_resource(f, user, wgt_file=wgt_file, template=template, deploy_only=True)
self.fail('Expecting InvalidContents exception to be raised')
except InvalidContents as e:
self.assertIn('CHANGELOG.md', six.text_type(e))
self.assertIn('CHANGELOG.md', str(e))

def test_add_packaged_resource_invalid_translated_changelog_encoding(self):
f, user, wgt_file, template, file_mocks = self.build_add_packaged_resouce_mocks(['index.html', 'DESCRIPTION.md', 'doc/index.md', 'CHANGELOG.es.md', 'CHANGELOG.md'], ['CHANGELOG.es.md'])
Expand All @@ -311,4 +308,4 @@ def test_add_packaged_resource_invalid_translated_changelog_encoding(self):
add_packaged_resource(f, user, wgt_file=wgt_file, template=template, deploy_only=True)
self.fail('Expecting InvalidContents exception to be raised')
except InvalidContents as e:
self.assertIn('CHANGELOG.es.md', six.text_type(e))
self.assertIn('CHANGELOG.es.md', str(e))
4 changes: 2 additions & 2 deletions src/wirecloud/catalogue/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
import json
import os
import re
from six.moves.urllib.parse import urljoin
from six.moves.urllib.request import pathname2url, url2pathname
from urllib.parse import urljoin
from urllib.request import pathname2url, url2pathname
import time

from django.conf import settings
Expand Down
6 changes: 2 additions & 4 deletions src/wirecloud/catalogue/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,11 @@
# You should have received a copy of the GNU Affero General Public License
# along with Wirecloud. If not, see <http://www.gnu.org/licenses/>.

from __future__ import unicode_literals

from io import BytesIO
import os
import json
from six.moves.urllib.parse import urljoin
from six.moves.urllib.request import pathname2url, url2pathname
from urllib.parse import urljoin
from urllib.request import pathname2url, url2pathname

from django.contrib.auth.decorators import login_required
from django.core.exceptions import PermissionDenied
Expand Down
2 changes: 0 additions & 2 deletions src/wirecloud/commons/commands/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
# You should have received a copy of the GNU Affero General Public License
# along with Wirecloud. If not, see <http://www.gnu.org/licenses/>.

from __future__ import unicode_literals

from optparse import make_option
import os

Expand Down
2 changes: 0 additions & 2 deletions src/wirecloud/commons/compressor_precompilers.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
# You should have received a copy of the GNU Affero General Public License
# along with Wirecloud. If not, see <http://www.gnu.org/licenses/>.

from __future__ import unicode_literals

import fnmatch
from itertools import product
from pathlib import Path
Expand Down
15 changes: 7 additions & 8 deletions src/wirecloud/commons/fields.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import copy
import json
import six

from django.core.exceptions import ValidationError
from django.db import connection, models
Expand Down Expand Up @@ -40,32 +39,32 @@ def to_python(self, value):
if self.blank and not value:
return {}
value = value or '{}'
if isinstance(value, six.binary_type):
value = six.text_type(value, 'utf-8')
if isinstance(value, six.string_types):
if isinstance(value, bytes):
value = str(value, 'utf-8')
if isinstance(value, str):
try:
return json.loads(value)
except Exception as err:
raise ValidationError(six.text_type(err))
raise ValidationError(str(err))
else:
return value

def validate(self, value, model_instance):
"""Check value is a valid JSON string, raise ValidationError on
error."""
if isinstance(value, six.string_types):
if isinstance(value, str):
super(JSONField, self).validate(value, model_instance)
try:
json.loads(value)
except Exception as err:
raise ValidationError(six.text_type(err))
raise ValidationError(str(err))

def get_prep_value(self, value):
"""Convert value to JSON string before save"""
try:
return json.dumps(value)
except Exception as err:
raise ValidationError(six.text_type(err))
raise ValidationError(str(err))

def value_to_string(self, obj):
"""Return value from object converted to string properly"""
Expand Down
2 changes: 0 additions & 2 deletions src/wirecloud/commons/haystack_queryparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
# You should have received a copy of the GNU Affero General Public License
# along with Wirecloud. If not, see <http://www.gnu.org/licenses/>.

from __future__ import unicode_literals

import re
import operator

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with Wirecloud. If not, see <http://www.gnu.org/licenses/>.

from __future__ import unicode_literals

import locale
import six

from django.core.management.base import CommandError, BaseCommand
from django.utils.translation import override, ugettext_lazy as _
Expand Down
2 changes: 0 additions & 2 deletions src/wirecloud/commons/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
# You should have received a copy of the GNU Affero General Public License
# along with Wirecloud. If not, see <http://www.gnu.org/licenses/>.

from __future__ import unicode_literals

from importlib import import_module

from django.contrib.auth.middleware import get_user
Expand Down
2 changes: 0 additions & 2 deletions src/wirecloud/commons/search_indexes.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
# You should have received a copy of the GNU Affero General Public License
# along with Wirecloud. If not, see <http://www.gnu.org/licenses/>.

from __future__ import unicode_literals

from django.contrib.auth.models import Group, User
from haystack import indexes
from haystack.query import SearchQuerySet as HaystackSearchQuerySet
Expand Down
2 changes: 0 additions & 2 deletions src/wirecloud/commons/tests/admin_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
# You should have received a copy of the GNU Affero General Public License
# along with Wirecloud. If not, see <http://www.gnu.org/licenses/>.

from __future__ import unicode_literals

import io
import os
import shutil
Expand Down
2 changes: 0 additions & 2 deletions src/wirecloud/commons/tests/basic_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
# You should have received a copy of the GNU Affero General Public License
# along with Wirecloud. If not, see <http://www.gnu.org/licenses/>.

from __future__ import unicode_literals

import json

from django.core.urlresolvers import reverse
Expand Down
2 changes: 0 additions & 2 deletions src/wirecloud/commons/tests/basic_views_urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
# You should have received a copy of the GNU Affero General Public License
# along with Wirecloud. If not, see <http://www.gnu.org/licenses/>.

from __future__ import unicode_literals

from django.conf.urls import include, url
from django.contrib import admin
from django.contrib.auth import views as auth_views
Expand Down
2 changes: 0 additions & 2 deletions src/wirecloud/commons/tests/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
# You should have received a copy of the GNU Affero General Public License
# along with Wirecloud. If not, see <http://www.gnu.org/licenses/>.

from __future__ import unicode_literals

import io
import os
import sys
Expand Down
2 changes: 0 additions & 2 deletions src/wirecloud/commons/tests/search_indexes.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
# You should have received a copy of the GNU Affero General Public License
# along with Wirecloud. If not, see <http://www.gnu.org/licenses/>.

from __future__ import unicode_literals

import json

from django.contrib.auth.models import Group, User
Expand Down
2 changes: 0 additions & 2 deletions src/wirecloud/commons/tests/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
# You should have received a copy of the GNU Affero General Public License
# along with Wirecloud. If not, see <http://www.gnu.org/licenses/>.

from __future__ import unicode_literals

import copy
import json
import os
Expand Down
2 changes: 0 additions & 2 deletions src/wirecloud/commons/tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
# You should have received a copy of the GNU Affero General Public License
# along with Wirecloud. If not, see <http://www.gnu.org/licenses/>.

from __future__ import unicode_literals

from io import BytesIO
import os
import zipfile
Expand Down
4 changes: 1 addition & 3 deletions src/wirecloud/commons/utils/downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,11 @@
# You should have received a copy of the GNU Affero General Public License
# along with Wirecloud. If not, see <http://www.gnu.org/licenses/>.

from __future__ import unicode_literals

import codecs
from django.utils.translation import ugettext as _
import platform
import requests
from six.moves.urllib.parse import urlparse
from urllib.parse import urlparse

import wirecloud.platform

Expand Down
4 changes: 1 addition & 3 deletions src/wirecloud/commons/utils/html.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,11 @@
# You should have received a copy of the GNU Affero General Public License
# along with Wirecloud. If not, see <http://www.gnu.org/licenses/>.

from __future__ import unicode_literals

import re

from lxml import etree
from lxml.html import fragment_fromstring, XHTMLParser
from six.moves.urllib.parse import urljoin, urlparse
from urllib.parse import urljoin, urlparse

from wirecloud.commons.utils.version import Version

Expand Down
Loading

0 comments on commit 886d367

Please sign in to comment.