From 1013fad4b75f164cef15c9beebe282ebcb41b88b Mon Sep 17 00:00:00 2001
From: Paul Marillonnet <pmarillonnet@entrouvert.com>
Date: Thu, 24 Jan 2019 17:21:26 +0100
Subject: [PATCH] python3: use django.utils.six.BytesIO (#31152)

---
 src/authentic2/management/commands/slapd-shell.py        | 4 ++--
 src/authentic2/saml/management/commands/sync-metadata.py | 4 ++--
 tests/test_idp_saml2.py                                  | 6 +++---
 3 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/src/authentic2/management/commands/slapd-shell.py b/src/authentic2/management/commands/slapd-shell.py
index 1bc92e4d..34f17e34 100644
--- a/src/authentic2/management/commands/slapd-shell.py
+++ b/src/authentic2/management/commands/slapd-shell.py
@@ -2,7 +2,6 @@ from __future__ import print_function
 
 import logging
 import sys
-from StringIO import StringIO
 import re
 
 from ldap.dn import escape_dn_chars
@@ -11,6 +10,7 @@ from ldif import LDIFWriter
 
 from django.contrib.auth import get_user_model
 from django.core.management.base import BaseCommand
+from django.utils import six
 from optparse import make_option
 
 COMMAND = 1
@@ -34,7 +34,7 @@ class Command(BaseCommand):
     def ldap(self, command, attrs):
         self.logger.debug('received command %s %s', command, attrs)
         if command == 'SEARCH':
-            out = StringIO()
+            out = six.BytesIO()
             ldif_writer = LDIFWriter(out)
             qs = get_user_model().objects.all()
             if attrs['filter'] != '(objectClass=*)':
diff --git a/src/authentic2/saml/management/commands/sync-metadata.py b/src/authentic2/saml/management/commands/sync-metadata.py
index dcc5b293..029ef2ca 100644
--- a/src/authentic2/saml/management/commands/sync-metadata.py
+++ b/src/authentic2/saml/management/commands/sync-metadata.py
@@ -4,11 +4,11 @@ import sys
 import xml.etree.ElementTree as etree
 import os
 import requests
-from StringIO import StringIO
 import warnings
 
 from django.core.management.base import BaseCommand, CommandError
 from django.template.defaultfilters import slugify
+from django.utils import six
 from django.utils.translation import gettext as _
 from django.contrib.contenttypes.models import ContentType
 
@@ -305,7 +305,7 @@ Any other kind of attribute filter policy is unsupported.
             response = requests.get(metadata_file_path)
             if not response.ok:
                 raise CommandError('Unable to open url %s' % metadata_file_path)
-            metadata_file = StringIO(response.content)
+            metadata_file = six.BytesIO(response.content)
         else:
             try:
                 metadata_file = file(metadata_file_path)
diff --git a/tests/test_idp_saml2.py b/tests/test_idp_saml2.py
index a2d44be5..59c89af1 100644
--- a/tests/test_idp_saml2.py
+++ b/tests/test_idp_saml2.py
@@ -2,7 +2,6 @@ import re
 import datetime
 import base64
 import unittest
-import StringIO
 from lxml.html import parse
 
 from django.test import Client
@@ -10,6 +9,7 @@ from django.test.utils import override_settings
 from django.contrib.auth import get_user_model, REDIRECT_FIELD_NAME
 from django.core.urlresolvers import reverse
 from django.core.files import File
+from django.utils import six
 from django.utils.translation import gettext as _
 from django.utils.six.moves.urllib import parse as urlparse
 
@@ -283,7 +283,7 @@ class SamlSSOTestCase(SamlBaseTestCase):
             self.assertEqual(response.status_code, 200)
             self.assertEqual(response['Content-type'].split(';')[0],
                              'text/html')
-            doc = parse(StringIO.StringIO(response.content)).getroot()
+            doc = parse(six.BytesIO(response.content)).getroot()
             self.assertEqual(len(doc.forms), 1,
                              msg='the number of forms is not 1')
             self.assertEqual(doc.forms[0].get('action'),
@@ -328,7 +328,7 @@ class SamlSSOTestCase(SamlBaseTestCase):
             response = client.get(response['Location'])
             self.assertEqual(response.status_code, 200)
             self.assertEqual(response['Content-type'].split(';')[0], 'text/html')
-            doc = parse(StringIO.StringIO(response.content)).getroot()
+            doc = parse(six.BytesIO(response.content)).getroot()
             self.assertEqual(len(doc.forms), 1, msg='the number of forms is not 1')
             self.assertEqual(
                 doc.forms[0].get('action'), '%s/sso/POST' % self.base_url)
-- 
2.20.1

