Commit d7dfab59 authored by Claude Paroz's avatar Claude Paroz
Browse files

Replaced cStringIO.StringIO by io.BytesIO.

Also replaced StringIO.StringIO by BytesIO in some other appropriate
places. StringIO is not available in Python 3.
parent 1583d402
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -203,12 +203,12 @@ class GEOSTest(unittest.TestCase, TestDataMixin):

    def test01k_fromfile(self):
        "Testing the fromfile() factory."
        from StringIO import StringIO
        from io import BytesIO
        ref_pnt = GEOSGeometry('POINT(5 23)')

        wkt_f = StringIO()
        wkt_f = BytesIO()
        wkt_f.write(ref_pnt.wkt)
        wkb_f = StringIO()
        wkb_f = BytesIO()
        wkb_f.write(str(ref_pnt.wkb))

        # Other tests use `fromfile()` on string filenames so those
+2 −5
Original line number Diff line number Diff line
try:
    from cStringIO import StringIO
except ImportError:
    from StringIO import StringIO
import zipfile
from io import BytesIO

from django.conf import settings
from django.http import HttpResponse
@@ -10,7 +7,7 @@ from django.template import loader

def compress_kml(kml):
    "Returns compressed KMZ from the given KML string."
    kmz = StringIO()
    kmz = BytesIO()
    zf = zipfile.ZipFile(kmz, 'a', zipfile.ZIP_DEFLATED)
    zf.writestr('doc.kml', kml.encode(settings.DEFAULT_CHARSET))
    zf.close()
+2 −5
Original line number Diff line number Diff line
from __future__ import absolute_import

try:
    from cStringIO import StringIO
except ImportError:
    from StringIO import StringIO
from io import BytesIO
from xml.dom import minidom
import zipfile

@@ -66,7 +63,7 @@ class GeoSitemapTest(TestCase):
                    kml_doc = minidom.parseString(self.client.get(kml_url).content)
                elif kml_type == 'kmz':
                    # Have to decompress KMZ before parsing.
                    buf = StringIO(self.client.get(kml_url).content)
                    buf = BytesIO(self.client.get(kml_url).content)
                    zf = zipfile.ZipFile(buf)
                    self.assertEqual(1, len(zf.filelist))
                    self.assertEqual('doc.kml', zf.filelist[0].filename)
+2 −5
Original line number Diff line number Diff line
import os
try:
    from cStringIO import StringIO
except ImportError:
    from StringIO import StringIO
from io import BytesIO, StringIO

from django.utils.encoding import smart_str, smart_unicode
from django.core.files.utils import FileProxyMixin
@@ -89,7 +86,7 @@ class File(FileProxyMixin):
        # Iterate over this file-like object by newlines
        buffer_ = None
        for chunk in self.chunks():
            chunk_buffer = StringIO(chunk)
            chunk_buffer = BytesIO(chunk)

            for line in chunk_buffer:
                if buffer_:
+3 −6
Original line number Diff line number Diff line
@@ -3,10 +3,7 @@ Classes representing uploaded files.
"""

import os
try:
    from cStringIO import StringIO
except ImportError:
    from StringIO import StringIO
from io import BytesIO

from django.conf import settings
from django.core.files.base import File
@@ -110,8 +107,8 @@ class SimpleUploadedFile(InMemoryUploadedFile):
    A simple representation of a file, which just has content, size, and a name.
    """
    def __init__(self, name, content, content_type='text/plain'):
        content = content or ''
        super(SimpleUploadedFile, self).__init__(StringIO(content), None, name,
        content = content or b''
        super(SimpleUploadedFile, self).__init__(BytesIO(content), None, name,
                                                 content_type, len(content), None)

    def from_dict(cls, file_dict):
Loading