From patchwork Mon Jun 29 13:46:06 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Finucane X-Patchwork-Id: 489589 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id CAB141402C4 for ; Tue, 30 Jun 2015 18:52:37 +1000 (AEST) Received: from ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id AEAB61A24BF for ; Tue, 30 Jun 2015 18:52:37 +1000 (AEST) X-Original-To: patchwork@lists.ozlabs.org Delivered-To: patchwork@lists.ozlabs.org Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lists.ozlabs.org (Postfix) with ESMTP id 5688F1A03A4 for ; Mon, 29 Jun 2015 23:46:32 +1000 (AEST) Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga103.fm.intel.com with ESMTP; 29 Jun 2015 06:46:30 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.13,698,1427785200"; d="scan'208";a="719610590" Received: from irvmail001.ir.intel.com ([163.33.26.43]) by orsmga001.jf.intel.com with ESMTP; 29 Jun 2015 06:46:29 -0700 Received: from sivswdev01.ir.intel.com (sivswdev01.ir.intel.com [10.237.217.45]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id t5TDkS6d018092; Mon, 29 Jun 2015 14:46:28 +0100 Received: from sivswdev01.ir.intel.com (localhost [127.0.0.1]) by sivswdev01.ir.intel.com with ESMTP id t5TDkSHe030613; Mon, 29 Jun 2015 14:46:28 +0100 Received: (from sfinucan@localhost) by sivswdev01.ir.intel.com with id t5TDkSkg030605; Mon, 29 Jun 2015 14:46:28 +0100 From: Stephen Finucane To: patchwork@lists.ozlabs.org Subject: [PATCH 06/11] trivial: Remove Python < 2.5 code Date: Mon, 29 Jun 2015 14:46:06 +0100 Message-Id: <1435585571-25252-7-git-send-email-stephen.finucane@intel.com> X-Mailer: git-send-email 2.0.0 In-Reply-To: <1435585571-25252-1-git-send-email-stephen.finucane@intel.com> References: <1435585571-25252-1-git-send-email-stephen.finucane@intel.com> X-Mailman-Approved-At: Tue, 30 Jun 2015 18:51:03 +1000 X-BeenThere: patchwork@lists.ozlabs.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Patchwork development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Stephen Finucane MIME-Version: 1.0 Errors-To: patchwork-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Patchwork" None of the supported versions of Django (currently 1.6 -> 1.8) support Python < 2.6. There is no need to keep code for older versions of Python around. Signed-off-by: Stephen Finucane --- patchwork/bin/parsemail.py | 9 ++------- patchwork/parser.py | 10 ++-------- patchwork/tests/test_patchparser.py | 6 +----- patchwork/tests/utils.py | 9 ++------- patchwork/views/__init__.py | 19 +++++-------------- patchwork/views/xmlrpc.py | 21 +++++++++------------ 6 files changed, 21 insertions(+), 53 deletions(-) diff --git a/patchwork/bin/parsemail.py b/patchwork/bin/parsemail.py index f2b10bd..e66b557 100755 --- a/patchwork/bin/parsemail.py +++ b/patchwork/bin/parsemail.py @@ -26,13 +26,8 @@ import time import operator import codecs from email import message_from_file -try: - from email.header import Header, decode_header - from email.utils import parsedate_tz, mktime_tz -except ImportError: - # Python 2.4 compatibility - from email.Header import Header, decode_header - from email.Utils import parsedate_tz, mktime_tz +from email.header import Header, decode_header +from email.utils import parsedate_tz, mktime_tz from patchwork.parser import parse_patch from patchwork.models import Patch, Project, Person, Comment, State, \ diff --git a/patchwork/parser.py b/patchwork/parser.py index 8afb334..13b4466 100644 --- a/patchwork/parser.py +++ b/patchwork/parser.py @@ -20,16 +20,10 @@ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +import hashlib import re from collections import Counter -try: - import hashlib - sha1_hash = hashlib.sha1 -except ImportError: - import sha - sha1_hash = sha.sha - _hunk_re = re.compile('^\@\@ -\d+(?:,(\d+))? \+\d+(?:,(\d+))? \@\@') _filename_re = re.compile('^(---|\+\+\+) (\S+)') @@ -194,7 +188,7 @@ def hash_patch(str): str = str.strip() + '\n' prefixes = ['-', '+', ' '] - hash = sha1_hash() + hash = hashlib.sha1() for line in str.split('\n'): diff --git a/patchwork/tests/test_patchparser.py b/patchwork/tests/test_patchparser.py index 58689bb..a49bf9b 100644 --- a/patchwork/tests/test_patchparser.py +++ b/patchwork/tests/test_patchparser.py @@ -25,11 +25,7 @@ from patchwork.models import Project, Person, Patch, Comment, State, \ from patchwork.tests.utils import read_patch, read_mail, create_email, \ defaults, create_user -try: - from email.mime.text import MIMEText -except ImportError: - # Python 2.4 compatibility - from email.MIMEText import MIMEText +from email.mime.text import MIMEText class PatchTest(TestCase): fixtures = ['default_states'] diff --git a/patchwork/tests/utils.py b/patchwork/tests/utils.py index 782ed36..9abe2c7 100644 --- a/patchwork/tests/utils.py +++ b/patchwork/tests/utils.py @@ -24,13 +24,8 @@ from django.contrib.auth.models import User from django.forms.fields import EmailField from email import message_from_file -try: - from email.mime.text import MIMEText - from email.mime.multipart import MIMEMultipart -except ImportError: - # Python 2.4 compatibility - from email.MIMEText import MIMEText - from email.MIMEMultipart import MIMEMultipart +from email.mime.text import MIMEText +from email.mime.multipart import MIMEMultipart # helper functions for tests _test_mail_dir = os.path.join(os.path.dirname(__file__), 'mail') diff --git a/patchwork/views/__init__.py b/patchwork/views/__init__.py index b64f604..8df8920 100644 --- a/patchwork/views/__init__.py +++ b/patchwork/views/__init__.py @@ -26,20 +26,11 @@ from patchwork.models import Comment import re import datetime -try: - from email.mime.nonmultipart import MIMENonMultipart - from email.encoders import encode_7or8bit - from email.parser import HeaderParser - from email.header import Header - import email.utils -except ImportError: - # Python 2.4 compatibility - from email.MIMENonMultipart import MIMENonMultipart - from email.Encoders import encode_7or8bit - from email.Parser import HeaderParser - from email.Header import Header - import email.Utils - email.utils = email.Utils +from email.mime.nonmultipart import MIMENonMultipart +from email.encoders import encode_7or8bit +from email.parser import HeaderParser +from email.header import Header +import email.utils def generic_list(request, project, view, view_args = {}, filter_settings = [], patches = None, diff --git a/patchwork/views/xmlrpc.py b/patchwork/views/xmlrpc.py index 84ed408..c025c09 100644 --- a/patchwork/views/xmlrpc.py +++ b/patchwork/views/xmlrpc.py @@ -22,7 +22,7 @@ from SimpleXMLRPCServer import SimpleXMLRPCDispatcher from django.http import HttpResponse, HttpResponseRedirect, \ - HttpResponseServerError + HttpResponseServerError from django.core import urlresolvers from django.contrib.auth import authenticate from patchwork.models import Patch, Project, Person, State @@ -34,18 +34,15 @@ import base64 import xmlrpclib class PatchworkXMLRPCDispatcher(SimpleXMLRPCDispatcher): + def __init__(self): - if sys.version_info[:3] >= (2,5,): - SimpleXMLRPCDispatcher.__init__(self, allow_none=False, - encoding=None) - def _dumps(obj, *args, **kwargs): - kwargs['allow_none'] = self.allow_none - kwargs['encoding'] = self.encoding - return xmlrpclib.dumps(obj, *args, **kwargs) - else: - def _dumps(obj, *args, **kwargs): - return xmlrpclib.dumps(obj, *args, **kwargs) - SimpleXMLRPCDispatcher.__init__(self) + SimpleXMLRPCDispatcher.__init__(self, allow_none=False, + encoding=None) + + def _dumps(obj, *args, **kwargs): + kwargs['allow_none'] = self.allow_none + kwargs['encoding'] = self.encoding + return xmlrpclib.dumps(obj, *args, **kwargs) self.dumps = _dumps