Browse Source

Fixed #28137 -- Deprecated HttpRequest.xreadlines().

Josh Schneier 8 years ago
parent
commit
a1b2c1d76e

+ 9 - 2
django/http/request.py

@@ -1,5 +1,6 @@
 import copy
 import copy
 import re
 import re
+import warnings
 from io import BytesIO
 from io import BytesIO
 from itertools import chain
 from itertools import chain
 from urllib.parse import quote, urlencode, urljoin, urlsplit
 from urllib.parse import quote, urlencode, urljoin, urlsplit
@@ -12,6 +13,7 @@ from django.core.exceptions import (
 from django.core.files import uploadhandler
 from django.core.files import uploadhandler
 from django.http.multipartparser import MultiPartParser, MultiPartParserError
 from django.http.multipartparser import MultiPartParser, MultiPartParserError
 from django.utils.datastructures import ImmutableList, MultiValueDict
 from django.utils.datastructures import ImmutableList, MultiValueDict
+from django.utils.deprecation import RemovedInDjango30Warning
 from django.utils.encoding import escape_uri_path, force_bytes, iri_to_uri
 from django.utils.encoding import escape_uri_path, force_bytes, iri_to_uri
 from django.utils.http import is_same_domain, limited_parse_qsl
 from django.utils.http import is_same_domain, limited_parse_qsl
 
 
@@ -328,14 +330,19 @@ class HttpRequest:
         except IOError as e:
         except IOError as e:
             raise UnreadablePostError(*e.args) from e
             raise UnreadablePostError(*e.args) from e
 
 
-    def xreadlines(self):
+    def __iter__(self):
         while True:
         while True:
             buf = self.readline()
             buf = self.readline()
             if not buf:
             if not buf:
                 break
                 break
             yield buf
             yield buf
 
 
-    __iter__ = xreadlines
+    def xreadlines(self):
+        warnings.warn(
+            'HttpRequest.xreadlines() is deprecated in favor of iterating the '
+            'request.', RemovedInDjango30Warning, stacklevel=2,
+        )
+        yield from self
 
 
     def readlines(self):
     def readlines(self):
         return list(iter(self))
         return list(iter(self))

+ 2 - 0
docs/internals/deprecation.txt

@@ -21,6 +21,8 @@ details on these changes.
 
 
 * The ``DEFAULT_CONTENT_TYPE`` setting will be removed.
 * The ``DEFAULT_CONTENT_TYPE`` setting will be removed.
 
 
+* ``HttpRequest.xreadlines()`` will be removed.
+
 .. _deprecation-removed-in-2.1:
 .. _deprecation-removed-in-2.1:
 
 
 2.1
 2.1

+ 0 - 1
docs/ref/request-response.txt

@@ -362,7 +362,6 @@ Methods
 .. method:: HttpRequest.read(size=None)
 .. method:: HttpRequest.read(size=None)
 .. method:: HttpRequest.readline()
 .. method:: HttpRequest.readline()
 .. method:: HttpRequest.readlines()
 .. method:: HttpRequest.readlines()
-.. method:: HttpRequest.xreadlines()
 .. method:: HttpRequest.__iter__()
 .. method:: HttpRequest.__iter__()
 
 
     Methods implementing a file-like interface for reading from an
     Methods implementing a file-like interface for reading from an

+ 3 - 0
docs/releases/2.0.txt

@@ -334,6 +334,9 @@ Miscellaneous
   well with third-party apps and is obsolete since HTML5 has mostly superseded
   well with third-party apps and is obsolete since HTML5 has mostly superseded
   XHTML.
   XHTML.
 
 
+* ``HttpRequest.xreadlines()`` is deprecated in favor of iterating over the
+  request.
+
 .. _removed-features-2.0:
 .. _removed-features-2.0:
 
 
 Features removed in 2.0
 Features removed in 2.0