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