Commit 6878320f authored by Arkadiusz Hiler's avatar Arkadiusz Hiler
Browse files

Get rid of six usage



We have already removed Python 2 support, let's remove the leftovers
too.
Signed-off-by: default avatarArkadiusz Hiler <arkadiusz.hiler@intel.com>
parent 7870c067
...@@ -21,15 +21,11 @@ ...@@ -21,15 +21,11 @@
from __future__ import absolute_import from __future__ import absolute_import
import six
import argparse import argparse
import codecs import codecs
import datetime import datetime
if six.PY3: from email import message_from_binary_file
from email import message_from_binary_file
else:
from email import message_from_file
from email.header import Header, decode_header from email.header import Header, decode_header
from email.parser import HeaderParser from email.parser import HeaderParser
...@@ -53,8 +49,6 @@ from django.core.exceptions import MultipleObjectsReturned ...@@ -53,8 +49,6 @@ from django.core.exceptions import MultipleObjectsReturned
from django.db.models import Q from django.db.models import Q
from django.db import IntegrityError from django.db import IntegrityError
from django.utils.log import AdminEmailHandler from django.utils.log import AdminEmailHandler
from django.utils import six
from django.utils.six.moves import map
from patchwork import lock as lockmod from patchwork import lock as lockmod
from patchwork.lock import release from patchwork.lock import release
...@@ -89,7 +83,7 @@ def clean_header(header): ...@@ -89,7 +83,7 @@ def clean_header(header):
(frag_str, frag_encoding) = fragment (frag_str, frag_encoding) = fragment
if frag_encoding: if frag_encoding:
return frag_str.decode(frag_encoding) return frag_str.decode(frag_encoding)
elif isinstance(frag_str, six.binary_type): # python 2 elif isinstance(frag_str, bytes):
return frag_str.decode() return frag_str.decode()
return frag_str return frag_str
...@@ -215,8 +209,7 @@ def mail_date(mail): ...@@ -215,8 +209,7 @@ def mail_date(mail):
def __format_header(header_name, value): def __format_header(header_name, value):
if six.PY3: value = value.encode()
value = value.encode()
header_instance = Header(value, continuation_ws=' ') header_instance = Header(value, continuation_ws=' ')
return '%s: %s\n' % (header_name, header_instance.encode()) return '%s: %s\n' % (header_name, header_instance.encode())
...@@ -246,7 +239,7 @@ def find_pull_request(content): ...@@ -246,7 +239,7 @@ def find_pull_request(content):
def try_decode(payload, charset): def try_decode(payload, charset):
try: try:
payload = six.text_type(payload, charset) payload = str(payload, charset)
except UnicodeDecodeError: except UnicodeDecodeError:
return None return None
return payload return payload
...@@ -378,7 +371,7 @@ def find_content(project, mail, force_comment=False): ...@@ -378,7 +371,7 @@ def find_content(project, mail, force_comment=False):
payload = part.get_payload(decode=True) payload = part.get_payload(decode=True)
subtype = part.get_content_subtype() subtype = part.get_content_subtype()
if not isinstance(payload, six.text_type): if not isinstance(payload, str):
charset = part.get_content_charset() charset = part.get_content_charset()
# Check that we have a charset that we understand. Otherwise, # Check that we have a charset that we understand. Otherwise,
...@@ -932,10 +925,8 @@ def main(args): ...@@ -932,10 +925,8 @@ def main(args):
logging.basicConfig(level=VERBOSITY_LEVELS[args['verbosity']]) logging.basicConfig(level=VERBOSITY_LEVELS[args['verbosity']])
if six.PY3: mail = message_from_binary_file(sys.stdin.buffer)
mail = message_from_binary_file(sys.stdin.buffer)
else:
mail = message_from_file(sys.stdin)
try: try:
parse_lock = lock() parse_lock = lock()
return parse_mail(mail) return parse_mail(mail)
......
...@@ -23,7 +23,6 @@ from __future__ import absolute_import ...@@ -23,7 +23,6 @@ from __future__ import absolute_import
import hashlib import hashlib
from django.db import models from django.db import models
from django.utils import six
class HashField(models.CharField): class HashField(models.CharField):
...@@ -35,7 +34,7 @@ class HashField(models.CharField): ...@@ -35,7 +34,7 @@ class HashField(models.CharField):
super(HashField, self).__init__(*args, **kwargs) super(HashField, self).__init__(*args, **kwargs)
def construct(self, value): def construct(self, value):
if isinstance(value, six.text_type): if isinstance(value, str):
value = value.encode('utf-8') value = value.encode('utf-8')
return hashlib.sha1(value) return hashlib.sha1(value)
......
...@@ -23,8 +23,7 @@ from django.core.exceptions import ObjectDoesNotExist ...@@ -23,8 +23,7 @@ from django.core.exceptions import ObjectDoesNotExist
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.utils.html import escape from django.utils.html import escape
from django.utils.safestring import mark_safe from django.utils.safestring import mark_safe
from django.utils import six from urllib.parse import quote
from django.utils.six.moves.urllib.parse import quote
from patchwork.models import Person, State from patchwork.models import Person, State
...@@ -460,8 +459,8 @@ class Filters: ...@@ -460,8 +459,8 @@ class Filters:
del params[remove.param] del params[remove.param]
def sanitise(s): def sanitise(s):
if not isinstance(s, six.string_types): if not isinstance(s, str):
s = six.text_type(s) s = str(s)
return quote(s.encode('utf-8')) return quote(s.encode('utf-8'))
return '?' + '&'.join(['%s=%s' % (sanitise(k), sanitise(v)) return '?' + '&'.join(['%s=%s' % (sanitise(k), sanitise(v))
......
...@@ -35,7 +35,6 @@ from django.db.models import Q ...@@ -35,7 +35,6 @@ from django.db.models import Q
import django.dispatch import django.dispatch
from django.utils.encoding import python_2_unicode_compatible from django.utils.encoding import python_2_unicode_compatible
from django.utils.functional import cached_property from django.utils.functional import cached_property
from django.utils.six.moves import filter
from patchwork.fields import HashField from patchwork.fields import HashField
from patchwork.parser import hash_patch, extract_tags from patchwork.parser import hash_patch, extract_tags
......
...@@ -21,7 +21,6 @@ from __future__ import absolute_import ...@@ -21,7 +21,6 @@ from __future__ import absolute_import
from django.conf import settings from django.conf import settings
from django.core import paginator from django.core import paginator
from django.utils.six.moves import range
DEFAULT_PATCHES_PER_PAGE = 100 DEFAULT_PATCHES_PER_PAGE = 100
......
...@@ -26,8 +26,6 @@ from collections import Counter ...@@ -26,8 +26,6 @@ from collections import Counter
import hashlib import hashlib
import re import re
from django.utils.six.moves import map
_hunk_re = re.compile(r'^\@\@ -\d+(?:,(\d+))? \+\d+(?:,(\d+))? \@\@') _hunk_re = re.compile(r'^\@\@ -\d+(?:,(\d+))? \+\d+(?:,(\d+))? \@\@')
_filename_re = re.compile(r'^(---|\+\+\+) (\S+)') _filename_re = re.compile(r'^(---|\+\+\+) (\S+)')
......
...@@ -24,7 +24,6 @@ import re ...@@ -24,7 +24,6 @@ import re
from django import template from django import template
from django.utils.html import escape from django.utils.html import escape
from django.utils.safestring import mark_safe from django.utils.safestring import mark_safe
from django.utils.six.moves import map
register = template.Library() register = template.Library()
......
...@@ -28,7 +28,6 @@ from django.utils.http import urlencode ...@@ -28,7 +28,6 @@ from django.utils.http import urlencode
from patchwork.models import Patch, Bundle, BundlePatch, Person from patchwork.models import Patch, Bundle, BundlePatch, Person
from patchwork.tests.utils import defaults, create_user, find_in_context from patchwork.tests.utils import defaults, create_user, find_in_context
from django.utils.six.moves import range, zip
def bundle_url(bundle): def bundle_url(bundle):
......
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
# SOFTWARE. # SOFTWARE.
import sys import sys
from django.utils.six import StringIO from io import StringIO
from contextlib import contextmanager from contextlib import contextmanager
from django.core import management from django.core import management
......
...@@ -24,7 +24,6 @@ import re ...@@ -24,7 +24,6 @@ import re
from django.urls import reverse from django.urls import reverse
from django.test import TestCase from django.test import TestCase
from django.utils.six.moves import zip
from patchwork.models import Person, Patch from patchwork.models import Person, Patch
from patchwork.tests.utils import defaults from patchwork.tests.utils import defaults
......
...@@ -17,7 +17,6 @@ ...@@ -17,7 +17,6 @@
# along with Patchwork; if not, write to the Free Software # along with Patchwork; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
import six
from email import message_from_string from email import message_from_string
from email.mime.text import MIMEText from email.mime.text import MIMEText
from email.utils import make_msgid from email.utils import make_msgid
...@@ -755,12 +754,8 @@ class NonAsciiHeaders(MBoxPatchTest): ...@@ -755,12 +754,8 @@ class NonAsciiHeaders(MBoxPatchTest):
self.assertTrue("Content-Type" in headers) self.assertTrue("Content-Type" in headers)
self.assertTrue("Content-Transfer-Encoding" in headers) self.assertTrue("Content-Transfer-Encoding" in headers)
if six.PY3: # offending header, should be re-encoded
# offending header, should be re-encoded self.assertTrue("Received" in headers)
self.assertTrue("Received" in headers)
else:
# offending header, should be discarded
self.assertFalse("Received" in headers)
class DelegateRequestTest(TestCase): class DelegateRequestTest(TestCase):
......
...@@ -21,7 +21,6 @@ from __future__ import absolute_import ...@@ -21,7 +21,6 @@ from __future__ import absolute_import
import json import json
from django.test import TestCase from django.test import TestCase
from django.utils.six.moves import map, range
from patchwork.models import Person from patchwork.models import Person
......
...@@ -29,7 +29,6 @@ import os ...@@ -29,7 +29,6 @@ import os
import dateutil.parser as dateparse import dateutil.parser as dateparse
from django.core import mail from django.core import mail
from django.test.utils import override_settings from django.test.utils import override_settings
from django.utils import six
import patchwork.tests.test_series as test_series import patchwork.tests.test_series as test_series
from patchwork.tests.test_user import TestUser from patchwork.tests.test_user import TestUser
...@@ -251,27 +250,16 @@ class APITest(APITestBase): ...@@ -251,27 +250,16 @@ class APITest(APITestBase):
def testSeriesMbox(self): def testSeriesMbox(self):
# XXX: since Python 3 email module wrap header lines differently # XXX: since Python 3 email module wrap header lines differently
if six.PY3: self.check_mbox("/series/%s/revisions/1/mbox/" % self.series.pk,
self.check_mbox("/series/%s/revisions/1/mbox/" % self.series.pk, 'for_each_-intel_-crtc-v2.mbox',
'for_each_-intel_-crtc-v2.mbox', '6d59b59dbf751064408249e18401275f')
'6d59b59dbf751064408249e18401275f')
else:
self.check_mbox("/series/%s/revisions/1/mbox/" % self.series.pk,
'for_each_-intel_-crtc-v2.mbox',
'42e2b2c9eeccf912c998be41683f50d7')
def testMboxWithCoverLetter(self): def testMboxWithCoverLetter(self):
# XXX: since Python 3 email module wrap header lines differently # XXX: since Python 3 email module wrap header lines differently
if six.PY3: self.check_mbox("/series/%s/revisions/1/mbox_with_cover/" %
self.check_mbox("/series/%s/revisions/1/mbox_with_cover/" % self.series.pk,
self.series.pk, 'for_each_-intel_-crtc-v2.mbox',
'for_each_-intel_-crtc-v2.mbox', '826f03a224083df013a2b373459527a3')
'826f03a224083df013a2b373459527a3')
else:
self.check_mbox("/series/%s/revisions/1/mbox_with_cover/" %
self.series.pk,
'for_each_-intel_-crtc-v2.mbox',
'3921b55a5ac3fb28eea0c4e198406cca')
def testCoverLetterMbox(self): def testCoverLetterMbox(self):
self.check_mbox("/series/%s/revisions/1/cover/" % self.check_mbox("/series/%s/revisions/1/cover/" %
......
...@@ -20,12 +20,13 @@ ...@@ -20,12 +20,13 @@
import datetime import datetime
from email.utils import make_msgid from email.utils import make_msgid
import unittest import unittest
from django.utils.six.moves.urllib.parse import urlparse from urllib.parse import urlparse
from django.conf import settings from django.conf import settings
from django.urls import reverse from django.urls import reverse
from django.test import LiveServerTestCase from django.test import LiveServerTestCase
from django.utils.six.moves import xmlrpc_client
import xmlrpc.client
from patchwork.models import Patch, State, EventLog from patchwork.models import Patch, State, EventLog
from patchwork.tests.test_user import TestUser from patchwork.tests.test_user import TestUser
...@@ -67,7 +68,7 @@ class XMLRPCTest(LiveServerTestCase): ...@@ -67,7 +68,7 @@ class XMLRPCTest(LiveServerTestCase):
self.url = (p.scheme + '://' + self.maintainer.username + ':' + self.url = (p.scheme + '://' + self.maintainer.username + ':' +
self.maintainer.password + '@' + p.netloc + p.path + self.maintainer.password + '@' + p.netloc + p.path +
reverse('xmlrpc')) reverse('xmlrpc'))
self.rpc = xmlrpc_client.Server(self.url) self.rpc = xmlrpc.client.Server(self.url)
def testGetRedirect(self): def testGetRedirect(self):
response = self.client.patch(self.url) response = self.client.patch(self.url)
......
...@@ -18,12 +18,8 @@ ...@@ -18,12 +18,8 @@
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
import codecs import codecs
import six
if six.PY3: from email import message_from_binary_file
from email import message_from_binary_file
else:
from email import message_from_file
from email.mime.multipart import MIMEMultipart from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText from email.mime.text import MIMEText
from email.utils import make_msgid from email.utils import make_msgid
...@@ -148,16 +144,17 @@ def read_patch(filename, encoding=None): ...@@ -148,16 +144,17 @@ def read_patch(filename, encoding=None):
else: else:
f = open(file_path) f = open(file_path)
return f.read() content = f.read()
f.close()
return content
def read_mail(filename, project=None): def read_mail(filename, project=None):
file_path = os.path.join(_test_mail_dir, filename) file_path = os.path.join(_test_mail_dir, filename)
if six.PY3: with open(file_path, "rb") as f:
mail = message_from_binary_file(open(file_path, "rb")) mail = message_from_binary_file(f)
else:
mail = message_from_file(open(file_path))
if 'Message-Id' not in mail: if 'Message-Id' not in mail:
mail['Message-Id'] = make_msgid() mail['Message-Id'] = make_msgid()
......
...@@ -21,7 +21,6 @@ from __future__ import absolute_import ...@@ -21,7 +21,6 @@ from __future__ import absolute_import
import datetime import datetime
import itertools import itertools
import six
from django.conf import settings from django.conf import settings
from django.contrib.auth.models import User from django.contrib.auth.models import User
...@@ -115,7 +114,7 @@ class Order(object): ...@@ -115,7 +114,7 @@ class Order(object):
q = self.order_map[self.order] q = self.order_map[self.order]
if self.reversed: if self.reversed:
if isinstance(q, six.string_types): if isinstance(q, str):
q = '-' + q q = '-' + q
else: else:
q = q.desc() q = q.desc()
......
...@@ -21,7 +21,6 @@ from __future__ import absolute_import ...@@ -21,7 +21,6 @@ from __future__ import absolute_import
from django.http import HttpResponse, HttpResponseForbidden, Http404 from django.http import HttpResponse, HttpResponseForbidden, Http404
from django.shortcuts import get_object_or_404, redirect, render from django.shortcuts import get_object_or_404, redirect, render
from django.utils import six
from patchwork.utils import group from patchwork.utils import group
from patchwork.forms import PatchForm, CreateBundleForm from patchwork.forms import PatchForm, CreateBundleForm
...@@ -149,10 +148,7 @@ def mbox(request, patch_id): ...@@ -149,10 +148,7 @@ def mbox(request, patch_id):
} }
response = HttpResponse(content_type="text/plain") response = HttpResponse(content_type="text/plain")
# NOTE(stephenfin) http://stackoverflow.com/a/28584090/613428 # NOTE(stephenfin) http://stackoverflow.com/a/28584090/613428
if six.PY3: response.write(patch_to_mbox(patch, options).as_bytes(True).decode())
response.write(patch_to_mbox(patch, options).as_bytes(True).decode())
else:
response.write(patch_to_mbox(patch, options).as_string(True))
response['Content-Disposition'] = 'attachment; filename=' + \ response['Content-Disposition'] = 'attachment; filename=' + \
patch.filename().replace(';', '').replace('\n', '') patch.filename().replace(';', '').replace('\n', '')
return response return response
......
...@@ -23,23 +23,17 @@ ...@@ -23,23 +23,17 @@
from __future__ import absolute_import from __future__ import absolute_import
import base64 import base64
# NOTE(stephenfin) six does not seem to support this
try:
from DocXMLRPCServer import XMLRPCDocGenerator
except ImportError:
from xmlrpc.server import XMLRPCDocGenerator
import sys import sys
import patchwork.threadlocalrequest import patchwork.threadlocalrequest
import xmlrpc.client as xmlrpc_client
from django.urls import reverse from django.urls import reverse
from django.contrib.auth import authenticate from django.contrib.auth import authenticate
from django.http import ( from django.http import (
HttpResponse, HttpResponseRedirect, HttpResponseServerError) HttpResponse, HttpResponseRedirect, HttpResponseServerError)
from django.views.decorators.csrf import csrf_exempt from django.views.decorators.csrf import csrf_exempt
from django.utils import six from xmlrpc.server import SimpleXMLRPCDispatcher, XMLRPCDocGenerator
from django.utils.six.moves import map, xmlrpc_client
from django.utils.six.moves.xmlrpc_server import SimpleXMLRPCDispatcher
from patchwork.models import Patch, Project, Person, State from patchwork.models import Patch, Project, Person, State
from patchwork.views import patch_to_mbox from patchwork.views import patch_to_mbox
...@@ -117,18 +111,18 @@ class PatchworkXMLRPCDispatcher(SimpleXMLRPCDispatcher, ...@@ -117,18 +111,18 @@ class PatchworkXMLRPCDispatcher(SimpleXMLRPCDispatcher,
def _marshaled_dispatch(self, request): def _marshaled_dispatch(self, request):
try: try:
params, method = six.moves.xmlrpc_client.loads(request.body) params, method = xmlrpc_client.loads(request.body)
response = self._dispatch(request, method, params) response = self._dispatch(request, method, params)
# wrap response in a singleton tuple # wrap response in a singleton tuple
response = (response,) response = (response,)
response = self.dumps(response, methodresponse=1) response = self.dumps(response, methodresponse=1)
except six.moves.xmlrpc_client.Fault as fault: except xmlrpc_client.Fault as fault:
response = self.dumps(fault) response = self.dumps(fault)
except Exception: except Exception:
# report exception back to server # report exception back to server
response = self.dumps( response = self.dumps(
six.moves.xmlrpc_client.Fault(1, xmlrpc_client.Fault(1,
'%s:%s' % (sys.exc_info()[0], sys.exc_info()[1])), '%s:%s' % (sys.exc_info()[0], sys.exc_info()[1])),
) )
...@@ -238,7 +232,7 @@ def person_to_dict(obj): ...@@ -238,7 +232,7 @@ def person_to_dict(obj):
'id': obj.id, 'id': obj.id,
'email': obj.email, 'email': obj.email,
'name': name, 'name': name,
'user': six.text_type(obj.user).encode('utf-8'), 'user': str(obj.user).encode('utf-8'),
} }
...@@ -274,18 +268,18 @@ def patch_to_dict(obj): ...@@ -274,18 +268,18 @@ def patch_to_dict(obj):
""" """
return { return {
'id': obj.id, 'id': obj.id,
'date': six.text_type(obj.date).encode('utf-8'), 'date': str(obj.date).encode('utf-8'),
'filename': obj.filename(), 'filename': obj.filename(),
'msgid': obj.msgid, 'msgid': obj.msgid,
'name': obj.name, 'name': obj.name,
'project': six.text_type(obj.project).encode('utf-8'), 'project': str(obj.project).encode('utf-8'),