diff options
| author | Tim Graham <timograham@gmail.com> | 2013-07-13 13:29:11 -0400 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2013-07-14 13:02:55 -0400 |
| commit | 2456ffa42c33d63b54579eae0f5b9cf2a8cd3714 (patch) | |
| tree | 06a8364994fcb6689f39cdf47b0f0372302ee2c5 /django | |
| parent | 0d81fd0e5f44432cbd1efb9b0e655116427dee6e (diff) | |
Fixed #20746 -- Removed Python 2.6 specific code/docs
Diffstat (limited to 'django')
| -rw-r--r-- | django/core/mail/message.py | 4 | ||||
| -rw-r--r-- | django/db/models/fields/__init__.py | 4 | ||||
| -rw-r--r-- | django/db/models/sql/where.py | 4 | ||||
| -rw-r--r-- | django/test/testcases.py | 101 | ||||
| -rw-r--r-- | django/utils/functional.py | 5 | ||||
| -rw-r--r-- | django/utils/itercompat.py | 14 |
6 files changed, 7 insertions, 125 deletions
diff --git a/django/core/mail/message.py b/django/core/mail/message.py index 98ab3c9075..db9023a0bb 100644 --- a/django/core/mail/message.py +++ b/django/core/mail/message.py @@ -3,7 +3,6 @@ from __future__ import unicode_literals import mimetypes import os import random -import sys import time from email import charset as Charset, encoders as Encoders from email.generator import Generator @@ -139,9 +138,6 @@ class SafeMIMEText(MIMEText): """ fp = six.StringIO() g = Generator(fp, mangle_from_ = False) - if sys.version_info < (2, 6, 6) and isinstance(self._payload, six.text_type): - # Workaround for http://bugs.python.org/issue1368247 - self._payload = self._payload.encode(self._charset.output_charset) g.flatten(self, unixfrom=unixfrom) return fp.getvalue() diff --git a/django/db/models/fields/__init__.py b/django/db/models/fields/__init__.py index a7e0b52e87..ddc76fccf7 100644 --- a/django/db/models/fields/__init__.py +++ b/django/db/models/fields/__init__.py @@ -1,5 +1,6 @@ from __future__ import unicode_literals +import collections import copy import datetime import decimal @@ -17,7 +18,6 @@ from django.core import exceptions, validators from django.utils.datastructures import DictWrapper from django.utils.dateparse import parse_date, parse_datetime, parse_time from django.utils.functional import curry, total_ordering -from django.utils.itercompat import is_iterator from django.utils.text import capfirst from django.utils import timezone from django.utils.translation import ugettext_lazy as _ @@ -585,7 +585,7 @@ class Field(object): return bound_field_class(self, fieldmapping, original) def _get_choices(self): - if is_iterator(self._choices): + if isinstance(self._choices, collections.Iterator): choices, self._choices = tee(self._choices) return choices else: diff --git a/django/db/models/sql/where.py b/django/db/models/sql/where.py index 024b995c99..2e83ecdce4 100644 --- a/django/db/models/sql/where.py +++ b/django/db/models/sql/where.py @@ -4,6 +4,7 @@ Code to manage the creation and SQL rendering of 'where' constraints. from __future__ import absolute_import +import collections import datetime from itertools import repeat @@ -11,7 +12,6 @@ from django.conf import settings from django.db.models.fields import DateTimeField, Field from django.db.models.sql.datastructures import EmptyResultSet, Empty from django.db.models.sql.aggregates import Aggregate -from django.utils.itercompat import is_iterator from django.utils.six.moves import xrange from django.utils import timezone from django.utils import tree @@ -61,7 +61,7 @@ class WhereNode(tree.Node): if not isinstance(data, (list, tuple)): return data obj, lookup_type, value = data - if is_iterator(value): + if isinstance(value, collections.Iterator): # Consume any generators immediately, so that we can determine # emptiness and transform any non-empty values correctly. value = list(value) diff --git a/django/test/testcases.py b/django/test/testcases.py index 04d044de27..d0442360ac 100644 --- a/django/test/testcases.py +++ b/django/test/testcases.py @@ -8,7 +8,6 @@ import json import os import re import sys -import select import socket import threading import unittest @@ -924,104 +923,6 @@ class QuietWSGIRequestHandler(WSGIRequestHandler): pass -if sys.version_info >= (3, 3, 0): - _ImprovedEvent = threading.Event -elif sys.version_info >= (2, 7, 0): - _ImprovedEvent = threading._Event -else: - class _ImprovedEvent(threading._Event): - """ - Does the same as `threading.Event` except it overrides the wait() method - with some code borrowed from Python 2.7 to return the set state of the - event (see: http://hg.python.org/cpython/rev/b5aa8aa78c0f/). This allows - to know whether the wait() method exited normally or because of the - timeout. This class can be removed when Django supports only Python >= 2.7. - """ - - def wait(self, timeout=None): - self._Event__cond.acquire() - try: - if not self._Event__flag: - self._Event__cond.wait(timeout) - return self._Event__flag - finally: - self._Event__cond.release() - - -class StoppableWSGIServer(WSGIServer): - """ - The code in this class is borrowed from the `SocketServer.BaseServer` class - in Python 2.6. The important functionality here is that the server is non- - blocking and that it can be shut down at any moment. This is made possible - by the server regularly polling the socket and checking if it has been - asked to stop. - Note for the future: Once Django stops supporting Python 2.6, this class - can be removed as `WSGIServer` will have this ability to shutdown on - demand and will not require the use of the _ImprovedEvent class whose code - is borrowed from Python 2.7. - """ - - def __init__(self, *args, **kwargs): - super(StoppableWSGIServer, self).__init__(*args, **kwargs) - self.__is_shut_down = _ImprovedEvent() - self.__serving = False - - def serve_forever(self, poll_interval=0.5): - """ - Handle one request at a time until shutdown. - - Polls for shutdown every poll_interval seconds. - """ - self.__serving = True - self.__is_shut_down.clear() - while self.__serving: - r, w, e = select.select([self], [], [], poll_interval) - if r: - self._handle_request_noblock() - self.__is_shut_down.set() - - def shutdown(self): - """ - Stops the serve_forever loop. - - Blocks until the loop has finished. This must be called while - serve_forever() is running in another thread, or it will - deadlock. - """ - self.__serving = False - if not self.__is_shut_down.wait(2): - raise RuntimeError( - "Failed to shutdown the live test server in 2 seconds. The " - "server might be stuck or generating a slow response.") - - def handle_request(self): - """Handle one request, possibly blocking. - """ - fd_sets = select.select([self], [], [], None) - if not fd_sets[0]: - return - self._handle_request_noblock() - - def _handle_request_noblock(self): - """ - Handle one request, without blocking. - - I assume that select.select has returned that the socket is - readable before this function was called, so there should be - no risk of blocking in get_request(). - """ - try: - request, client_address = self.get_request() - except socket.error: - return - if self.verify_request(request, client_address): - try: - self.process_request(request, client_address) - except Exception: - self.handle_error(request, client_address) - self.close_request(request) - - class _MediaFilesHandler(StaticFilesHandler): """ Handler for serving the media files. This is a private class that is @@ -1071,7 +972,7 @@ class LiveServerThread(threading.Thread): # one that is free to use for the WSGI server. for index, port in enumerate(self.possible_ports): try: - self.httpd = StoppableWSGIServer( + self.httpd = WSGIServer( (self.host, port), QuietWSGIRequestHandler) except WSGIServerException as e: if (index + 1 < len(self.possible_ports) and diff --git a/django/utils/functional.py b/django/utils/functional.py index 93befcf59e..d5d52205d7 100644 --- a/django/utils/functional.py +++ b/django/utils/functional.py @@ -398,9 +398,8 @@ def partition(predicate, values): if sys.version_info >= (2, 7, 2): from functools import total_ordering else: - # For Python < 2.7.2. Python 2.6 does not have total_ordering, and - # total_ordering in 2.7 versions prior to 2.7.2 is buggy. See - # http://bugs.python.org/issue10042 for details. For these versions use + # For Python < 2.7.2. total_ordering in versions prior to 2.7.2 is buggy. + # See http://bugs.python.org/issue10042 for details. For these versions use # code borrowed from Python 2.7.3. def total_ordering(cls): """Class decorator that fills in missing ordering methods""" diff --git a/django/utils/itercompat.py b/django/utils/itercompat.py index 1df1e57cb2..096f808671 100644 --- a/django/utils/itercompat.py +++ b/django/utils/itercompat.py @@ -4,9 +4,6 @@ Where possible, we try to use the system-native version and only fall back to these implementations if necessary. """ -import collections -import sys - def is_iterable(x): "A implementation independent way of checking for iterables" @@ -16,14 +13,3 @@ def is_iterable(x): return False else: return True - -def is_iterator(x): - """An implementation independent way of checking for iterators - - Python 2.6 has a different implementation of collections.Iterator which - accepts anything with a `next` method. 2.7+ requires and `__iter__` method - as well. - """ - if sys.version_info >= (2, 7): - return isinstance(x, collections.Iterator) - return isinstance(x, collections.Iterator) and hasattr(x, '__iter__') |
