[PATCH v2 06/16] trivial: Remove Python < 2.5 code
Stephen Finucane
stephen.finucane at intel.com
Sat Aug 22 00:32:10 AEST 2015
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 <stephen.finucane at intel.com>
---
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
--
2.0.0
More information about the Patchwork
mailing list