From 4fe87c370dc7c282212c63c0502de13f411da79a Mon Sep 17 00:00:00 2001 From: Aymeric Augustin Date: Fri, 30 Mar 2012 09:20:04 +0000 Subject: [PATCH] Removed some Python < 2.6 compatibility code. Refs #17965. git-svn-id: http://code.djangoproject.com/svn/django/trunk@17830 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/contrib/admin/tests.py | 4 ---- django/core/validators.py | 6 +----- django/test/testcases.py | 6 +----- django/utils/http.py | 23 ++++++--------------- tests/regressiontests/file_storage/tests.py | 8 +------ 5 files changed, 9 insertions(+), 38 deletions(-) diff --git a/django/contrib/admin/tests.py b/django/contrib/admin/tests.py index 2491fc65b1..2cc8b2a92d 100644 --- a/django/contrib/admin/tests.py +++ b/django/contrib/admin/tests.py @@ -1,5 +1,3 @@ -import sys - from django.test import LiveServerTestCase from django.utils.importlib import import_module from django.utils.unittest import SkipTest @@ -10,8 +8,6 @@ class AdminSeleniumWebDriverTestCase(LiveServerTestCase): @classmethod def setUpClass(cls): - if sys.version_info < (2, 6): - raise SkipTest('Selenium Webdriver does not support Python < 2.6.') try: # Import and start the WebDriver class. module, attr = cls.webdriver_class.rsplit('.', 1) diff --git a/django/core/validators.py b/django/core/validators.py index 95224e9de9..9f42476ab0 100644 --- a/django/core/validators.py +++ b/django/core/validators.py @@ -1,4 +1,3 @@ -import platform import re import urllib import urllib2 @@ -123,10 +122,7 @@ class URLValidator(RegexValidator): else: handlers.append(urllib2.HTTPSHandler()) map(opener.add_handler, handlers) - if platform.python_version_tuple() >= (2, 6): - opener.open(req, timeout=10) - else: - opener.open(req) + opener.open(req, timeout=10) except ValueError: raise ValidationError(_(u'Enter a valid URL.'), code='invalid') except: # urllib2.URLError, httplib.InvalidURL, etc. diff --git a/django/test/testcases.py b/django/test/testcases.py index c57099fc92..d9048be98b 100644 --- a/django/test/testcases.py +++ b/django/test/testcases.py @@ -1035,12 +1035,8 @@ class LiveServerThread(threading.Thread): self.httpd = StoppableWSGIServer( (self.host, port), QuietWSGIRequestHandler) except WSGIServerException, e: - if sys.version_info < (2, 6): - error_code = e.args[0].args[0] - else: - error_code = e.args[0].errno if (index + 1 < len(self.possible_ports) and - error_code == errno.EADDRINUSE): + e.args[0].errno == errno.EADDRINUSE): # This port is already in use, so we go on and try with # the next one in the list. continue diff --git a/django/utils/http.py b/django/utils/http.py index d343a375c0..dbd18d8ff0 100644 --- a/django/utils/http.py +++ b/django/utils/http.py @@ -207,20 +207,9 @@ def quote_etag(etag): """ return '"%s"' % etag.replace('\\', '\\\\').replace('"', '\\"') -if sys.version_info >= (2, 6): - def same_origin(url1, url2): - """ - Checks if two URLs are 'same-origin' - """ - p1, p2 = urlparse.urlparse(url1), urlparse.urlparse(url2) - return (p1.scheme, p1.hostname, p1.port) == (p2.scheme, p2.hostname, p2.port) -else: - # Python 2.5 compatibility. This actually works for Python 2.6 and above, - # but the above definition is much more obviously correct and so is - # preferred going forward. - def same_origin(url1, url2): - """ - Checks if two URLs are 'same-origin' - """ - p1, p2 = urlparse.urlparse(url1), urlparse.urlparse(url2) - return p1[0:2] == p2[0:2] +def same_origin(url1, url2): + """ + Checks if two URLs are 'same-origin' + """ + p1, p2 = urlparse.urlparse(url1), urlparse.urlparse(url2) + return (p1.scheme, p1.hostname, p1.port) == (p2.scheme, p2.hostname, p2.port) diff --git a/tests/regressiontests/file_storage/tests.py b/tests/regressiontests/file_storage/tests.py index 769e2c7371..f03a7a8eac 100644 --- a/tests/regressiontests/file_storage/tests.py +++ b/tests/regressiontests/file_storage/tests.py @@ -2,7 +2,6 @@ import errno import os import shutil -import sys import tempfile import time from datetime import datetime, timedelta @@ -470,12 +469,7 @@ class FileStoragePathParsing(unittest.TestCase): self.storage.save('dotted.path/.test', ContentFile("2")) self.assertTrue(os.path.exists(os.path.join(self.storage_dir, 'dotted.path/.test'))) - # Before 2.6, a leading dot was treated as an extension, and so - # underscore gets added to beginning instead of end. - if sys.version_info < (2, 6): - self.assertTrue(os.path.exists(os.path.join(self.storage_dir, 'dotted.path/_1.test'))) - else: - self.assertTrue(os.path.exists(os.path.join(self.storage_dir, 'dotted.path/.test_1'))) + self.assertTrue(os.path.exists(os.path.join(self.storage_dir, 'dotted.path/.test_1'))) class DimensionClosingBug(unittest.TestCase): """