diff --git a/INSTALL b/INSTALL index be64877..dda9b4c 100644 --- a/INSTALL +++ b/INSTALL @@ -1,6 +1,6 @@ Thanks for downloading Django. -To install it, make sure you have Python 3.4 or greater installed. Then run +To install it, make sure you have Python 3.5 or greater installed. Then run this command from the command prompt: python setup.py install diff --git a/django/http/cookie.py b/django/http/cookie.py index 52dff78..5c3fb94 100644 --- a/django/http/cookie.py +++ b/django/http/cookie.py @@ -1,20 +1,7 @@ -import sys from http import cookies -# Cookie pickling bug is fixed in Python 3.4.3+ -# http://bugs.python.org/issue22775 -if sys.version_info >= (3, 4, 3): - SimpleCookie = cookies.SimpleCookie -else: - Morsel = cookies.Morsel - - class SimpleCookie(cookies.SimpleCookie): - def __setitem__(self, key, value): - if isinstance(value, Morsel): - # allow assignment of constructed Morsels (e.g. for pickling) - dict.__setitem__(self, key, value) - else: - super().__setitem__(key, value) +# For backwards compatibility in Django 2.X. +SimpleCookie = cookies.SimpleCookie def parse_cookie(cookie): diff --git a/django/test/html.py b/django/test/html.py index 900aa3d..d2e6efe 100644 --- a/django/test/html.py +++ b/django/test/html.py @@ -3,8 +3,7 @@ Comparing two html documents. """ import re - -from django.utils.html_parser import HTMLParseError, HTMLParser +from html.parser import HTMLParser WHITESPACE = re.compile(r'\s+') @@ -140,6 +139,10 @@ class RootElement(Element): return ''.join(str(c) for c in self.children) +class HTMLParseError(Exception): + pass + + class Parser(HTMLParser): SELF_CLOSING_TAGS = ( 'br', 'hr', 'input', 'img', 'meta', 'spacer', 'link', 'frame', 'base', @@ -147,7 +150,7 @@ class Parser(HTMLParser): ) def __init__(self): - HTMLParser.__init__(self) + HTMLParser.__init__(self, convert_charrefs=False) self.root = RootElement() self.open_tags = [] self.element_positions = {} diff --git a/django/utils/html.py b/django/utils/html.py index 18c650f..fb847a8 100644 --- a/django/utils/html.py +++ b/django/utils/html.py @@ -1,6 +1,7 @@ """HTML utilities suitable for global use.""" import re +from html.parser import HTMLParser from urllib.parse import ( parse_qsl, quote, unquote, urlencode, urlsplit, urlunsplit, ) @@ -11,8 +12,6 @@ from django.utils.http import RFC3986_GENDELIMS, RFC3986_SUBDELIMS from django.utils.safestring import SafeData, SafeText, mark_safe from django.utils.text import normalize_newlines -from .html_parser import HTMLParseError, HTMLParser - # Configuration for urlize() function. TRAILING_PUNCTUATION_RE = re.compile( '^' # Beginning of word @@ -131,7 +130,7 @@ def linebreaks(value, autoescape=False): class MLStripper(HTMLParser): def __init__(self): - HTMLParser.__init__(self) + HTMLParser.__init__(self, convert_charrefs=False) self.reset() self.fed = [] @@ -153,16 +152,9 @@ def _strip_once(value): Internal tag stripping utility used by strip_tags. """ s = MLStripper() - try: - s.feed(value) - except HTMLParseError: - return value - try: - s.close() - except HTMLParseError: - return s.get_data() + s.rawdata - else: - return s.get_data() + s.feed(value) + s.close() + return s.get_data() @keep_lazy_text diff --git a/django/utils/html_parser.py b/django/utils/html_parser.py deleted file mode 100644 index 6b46ddc..0000000 --- a/django/utils/html_parser.py +++ /dev/null @@ -1,17 +0,0 @@ -import html.parser - -try: - HTMLParseError = html.parser.HTMLParseError -except AttributeError: - # create a dummy class for Python 3.5+ where it's been removed - class HTMLParseError(Exception): - pass - - -class HTMLParser(html.parser.HTMLParser): - """Explicitly set convert_charrefs to be False. - - This silences a deprecation warning on Python 3.4. - """ - def __init__(self, convert_charrefs=False, **kwargs): - html.parser.HTMLParser.__init__(self, convert_charrefs=convert_charrefs, **kwargs) diff --git a/docs/intro/install.txt b/docs/intro/install.txt index 7a338ee..eda052c 100644 --- a/docs/intro/install.txt +++ b/docs/intro/install.txt @@ -29,7 +29,7 @@ your operating system's package manager. You can verify that Python is installed by typing ``python`` from your shell; you should see something like:: - Python 3.4.x + Python 3.x.y [GCC 4.x] on linux Type "help", "copyright", "credits" or "license" for more information. >>> diff --git a/docs/intro/tutorial01.txt b/docs/intro/tutorial01.txt index 05ee9c3..cbb5b73 100644 --- a/docs/intro/tutorial01.txt +++ b/docs/intro/tutorial01.txt @@ -23,7 +23,7 @@ in a shell prompt (indicated by the $ prefix): If Django is installed, you should see the version of your installation. If it isn't, you'll get an error telling "No module named django". -This tutorial is written for Django |version| and Python 3.4 or later. If the +This tutorial is written for Django |version| and Python 3.5 or later. If the Django version doesn't match, you can refer to the tutorial for your version of Django by using the version switcher at the bottom right corner of this page, or update Django to the newest version. If you are still using Python diff --git a/docs/ref/applications.txt b/docs/ref/applications.txt index be3f554..9fd2a41 100644 --- a/docs/ref/applications.txt +++ b/docs/ref/applications.txt @@ -192,7 +192,7 @@ Configurable attributes .. attribute:: AppConfig.path Filesystem path to the application directory, e.g. - ``'/usr/lib/python3.4/dist-packages/django/contrib/admin'``. + ``'/usr/lib/pythonX.Y/dist-packages/django/contrib/admin'``. In most cases, Django can automatically detect and set this, but you can also provide an explicit override as a class attribute on your diff --git a/setup.py b/setup.py index e9cfa4f..a936760 100644 --- a/setup.py +++ b/setup.py @@ -62,7 +62,6 @@ setup( 'Operating System :: OS Independent', 'Programming Language :: Python', 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.4', 'Programming Language :: Python :: 3.5', 'Programming Language :: Python :: 3.6', 'Topic :: Internet :: WWW/HTTP', diff --git a/tests/mail/tests.py b/tests/mail/tests.py index 63737b3..ade8993 100644 --- a/tests/mail/tests.py +++ b/tests/mail/tests.py @@ -1138,8 +1138,8 @@ class FakeSMTPServer(smtpd.SMTPServer, threading.Thread): def __init__(self, *args, **kwargs): threading.Thread.__init__(self) # New kwarg added in Python 3.5; default switching to False in 3.6. - if sys.version_info >= (3, 5): - kwargs['decode_data'] = True + # Setting a value only silences a deprecation warning in PY35. + kwargs['decode_data'] = True smtpd.SMTPServer.__init__(self, *args, **kwargs) self._sink = [] self.active = False diff --git a/tests/sessions_tests/tests.py b/tests/sessions_tests/tests.py index 9654c7d..de7e41f 100644 --- a/tests/sessions_tests/tests.py +++ b/tests/sessions_tests/tests.py @@ -2,7 +2,6 @@ import base64 import os import shutil import string -import sys import tempfile import unittest from datetime import timedelta @@ -726,10 +725,9 @@ class SessionMiddlewareTests(TestCase): # A deleted cookie header looks like: # Set-Cookie: sessionid=; expires=Thu, 01-Jan-1970 00:00:00 GMT; Max-Age=0; Path=/ self.assertEqual( - 'Set-Cookie: {}={}; expires=Thu, 01-Jan-1970 00:00:00 GMT; ' + 'Set-Cookie: {}=""; expires=Thu, 01-Jan-1970 00:00:00 GMT; ' 'Max-Age=0; Path=/'.format( settings.SESSION_COOKIE_NAME, - '""' if sys.version_info >= (3, 5) else '', ), str(response.cookies[settings.SESSION_COOKIE_NAME]) ) @@ -756,10 +754,9 @@ class SessionMiddlewareTests(TestCase): # expires=Thu, 01-Jan-1970 00:00:00 GMT; Max-Age=0; # Path=/example/ self.assertEqual( - 'Set-Cookie: {}={}; Domain=.example.local; expires=Thu, ' + 'Set-Cookie: {}=""; Domain=.example.local; expires=Thu, ' '01-Jan-1970 00:00:00 GMT; Max-Age=0; Path=/example/'.format( settings.SESSION_COOKIE_NAME, - '""' if sys.version_info >= (3, 5) else '', ), str(response.cookies[settings.SESSION_COOKIE_NAME]) ) diff --git a/tests/test_runner/test_debug_sql.py b/tests/test_runner/test_debug_sql.py index 1b36fbc..c73b260 100644 --- a/tests/test_runner/test_debug_sql.py +++ b/tests/test_runner/test_debug_sql.py @@ -1,4 +1,3 @@ -import sys import unittest from io import StringIO @@ -68,12 +67,9 @@ class TestDebugSQL(unittest.TestCase): ] verbose_expected_outputs = [ - # Output format changed in Python 3.5+ - x.format('' if sys.version_info < (3, 5) else 'TestDebugSQL.') for x in [ - 'runTest (test_runner.test_debug_sql.{}FailingTest) ... FAIL', - 'runTest (test_runner.test_debug_sql.{}ErrorTest) ... ERROR', - 'runTest (test_runner.test_debug_sql.{}PassingTest) ... ok', - ] + 'runTest (test_runner.test_debug_sql.TestDebugSQL.FailingTest) ... FAIL', + 'runTest (test_runner.test_debug_sql.TestDebugSQL.ErrorTest) ... ERROR', + 'runTest (test_runner.test_debug_sql.TestDebugSQL.PassingTest) ... ok', ] + [ ('''SELECT COUNT(*) AS "__count" ''' '''FROM "test_runner_person" WHERE ''' diff --git a/tests/test_utils/tests.py b/tests/test_utils/tests.py index 19ef405..baedf05 100644 --- a/tests/test_utils/tests.py +++ b/tests/test_utils/tests.py @@ -1,5 +1,4 @@ import os -import sys import unittest from io import StringIO @@ -646,9 +645,6 @@ class HTMLEqualTests(SimpleTestCase): error_msg = ( "First argument is not valid HTML:\n" "('Unexpected end tag `div` (Line 1, Column 6)', (1, 6))" - ) if sys.version_info >= (3, 5) else ( - "First argument is not valid HTML:\n" - "Unexpected end tag `div` (Line 1, Column 6), at line 1, column 7" ) with self.assertRaisesMessage(AssertionError, error_msg): self.assertHTMLEqual('< div> div>', '
')