diff --git a/docs/api-guide/serializers.md b/docs/api-guide/serializers.md index 7cf7a6974..19501718e 100644 --- a/docs/api-guide/serializers.md +++ b/docs/api-guide/serializers.md @@ -57,10 +57,10 @@ At this point we've translated the model instance into Python native datatypes. Deserialization is similar. First we parse a stream into Python native datatypes... - from django.utils.six import BytesIO + import io from rest_framework.parsers import JSONParser - stream = BytesIO(json) + stream = io.BytesIO(json) data = JSONParser().parse(stream) ...then we restore those native datatypes into a dictionary of validated data. diff --git a/docs/tutorial/1-serialization.md b/docs/tutorial/1-serialization.md index aa94eeb0e..630c3da0a 100644 --- a/docs/tutorial/1-serialization.md +++ b/docs/tutorial/1-serialization.md @@ -154,9 +154,9 @@ At this point we've translated the model instance into Python native datatypes. Deserialization is similar. First we parse a stream into Python native datatypes... - from django.utils.six import BytesIO + import io - stream = BytesIO(content) + stream = io.BytesIO(content) data = JSONParser().parse(stream) ...then we restore those native datatypes into a fully populated object instance. diff --git a/rest_framework/request.py b/rest_framework/request.py index 9d4f73d30..a6d92e2bd 100644 --- a/rest_framework/request.py +++ b/rest_framework/request.py @@ -10,6 +10,7 @@ The wrapped request then offers a richer API, in particular : """ from __future__ import unicode_literals +import io import sys from contextlib import contextmanager @@ -301,7 +302,7 @@ class Request(object): elif not self._request._read_started: self._stream = self._request else: - self._stream = six.BytesIO(self.body) + self._stream = io.BytesIO(self.body) def _supports_form_parsing(self): """ diff --git a/tests/test_parsers.py b/tests/test_parsers.py index d1287ecd6..e793948e3 100644 --- a/tests/test_parsers.py +++ b/tests/test_parsers.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals +import io import math import pytest @@ -10,7 +11,7 @@ from django.core.files.uploadhandler import ( ) from django.http.request import RawPostDataException from django.test import TestCase -from django.utils.six import BytesIO, StringIO +from django.utils.six import StringIO from rest_framework.exceptions import ParseError from rest_framework.parsers import ( @@ -43,7 +44,7 @@ class TestFileUploadParser(TestCase): def setUp(self): class MockRequest(object): pass - self.stream = BytesIO( + self.stream = io.BytesIO( "Test text file".encode('utf-8') ) request = MockRequest() @@ -131,7 +132,7 @@ class TestFileUploadParser(TestCase): class TestJSONParser(TestCase): def bytes(self, value): - return BytesIO(value.encode('utf-8')) + return io.BytesIO(value.encode('utf-8')) def test_float_strictness(self): parser = JSONParser()