From 0ac0a2013564ead1e64be2700cfaec1291ed53ce Mon Sep 17 00:00:00 2001
From: Paul Marillonnet <pmarillonnet@entrouvert.com>
Date: Wed, 10 Apr 2019 18:56:46 +0200
Subject: [PATCH 2/2] python3: deprecate file builtin

---
 debian-wheezy/debian_config.py                           | 3 ++-
 debian/debian_config.py                                  | 3 ++-
 samples/authentic2-plugin-template/setup.py              | 5 ++---
 src/authentic2/management/commands/load-ldif.py          | 4 ++--
 src/authentic2/saml/management/commands/sync-metadata.py | 2 +-
 tests/test_commands.py                                   | 4 ++--
 6 files changed, 11 insertions(+), 10 deletions(-)

diff --git a/debian-wheezy/debian_config.py b/debian-wheezy/debian_config.py
index 7ab3e7a4..3f50a813 100644
--- a/debian-wheezy/debian_config.py
+++ b/debian-wheezy/debian_config.py
@@ -17,7 +17,8 @@ LOCALE_PATHS = ('/var/lib/authentic2/locale',) + LOCALE_PATHS
 ADMINS = (('root', 'root@localhost'),)
 
 if os.path.exists('/var/lib/authentic2/secret_key'):
-    SECRET_KEY = file('/var/lib/authentic2/secret_key').read()
+    with open('/var/lib/authentic2/secret_key') as f:
+        SECRET_KEY = f.read()
 
 LOGGING = {
     'version': 1,
diff --git a/debian/debian_config.py b/debian/debian_config.py
index 5fe72aa1..f78a9616 100644
--- a/debian/debian_config.py
+++ b/debian/debian_config.py
@@ -17,7 +17,8 @@ LOCALE_PATHS = ('/var/lib/authentic2/locale',) + LOCALE_PATHS
 ADMINS = (('root', 'root@localhost'),)
 
 if os.path.exists('/var/lib/authentic2/secret_key'):
-    SECRET_KEY = file('/var/lib/authentic2/secret_key').read()
+    with open('/var/lib/authentic2/secret_key') as f:
+        SECRET_KEY = f.read()
 
 LOGGING = {
     'version': 1,
diff --git a/samples/authentic2-plugin-template/setup.py b/samples/authentic2-plugin-template/setup.py
index f629505c..9cacd7df 100755
--- a/samples/authentic2-plugin-template/setup.py
+++ b/samples/authentic2-plugin-template/setup.py
@@ -22,9 +22,8 @@ def get_version():
                             ['git', 'rev-list', 'HEAD']).splitlines())
     return '0.0.0'
 
-README = file(os.path.join(
-    os.path.dirname(__file__),
-    'README')).read()
+with open(os.path.join(os.path.dirname(__file__), 'README')) as f:
+    README = f.read()
 
 setup(name='authentic2-plugin-template',
         version=get_version(),
diff --git a/src/authentic2/management/commands/load-ldif.py b/src/authentic2/management/commands/load-ldif.py
index adac2eab..ceddeaa1 100644
--- a/src/authentic2/management/commands/load-ldif.py
+++ b/src/authentic2/management/commands/load-ldif.py
@@ -77,7 +77,7 @@ class DjangoUserLDIFParser(ldif.LDIFParser):
     def parse(self, *args, **kwargs):
         ldif.LDIFParser.parse(self, *args, **kwargs)
         if self.options['result']:
-            with file(self.options['result'], 'w') as f:
+            with open(self.options['result'], 'w') as f:
                 json.dump(self.json, f)
 
 
@@ -138,7 +138,7 @@ class Command(BaseCommand):
         options['verbosity'] = int(options['verbosity'])
         ldif_files = options.pop('ldif_file')
         for arg in ldif_files:
-            f = file(arg)
+            f = open(arg)
             parser = DjangoUserLDIFParser(f, options=options, command=self)
             parser.parse()
             if not options['fake']:
diff --git a/src/authentic2/saml/management/commands/sync-metadata.py b/src/authentic2/saml/management/commands/sync-metadata.py
index 029ef2ca..c6f309da 100644
--- a/src/authentic2/saml/management/commands/sync-metadata.py
+++ b/src/authentic2/saml/management/commands/sync-metadata.py
@@ -308,7 +308,7 @@ Any other kind of attribute filter policy is unsupported.
             metadata_file = six.BytesIO(response.content)
         else:
             try:
-                metadata_file = file(metadata_file_path)
+                metadata_file = open(metadata_file_path)
             except:
                 raise CommandError('Unable to open file %s' % metadata_file_path)
 
diff --git a/tests/test_commands.py b/tests/test_commands.py
index 9aa18f08..d5d9584a 100644
--- a/tests/test_commands.py
+++ b/tests/test_commands.py
@@ -49,7 +49,7 @@ def test_load_ldif(db, monkeypatch, tmpdir):
         def __init__(self, *args, **kwargs):
             self.users = []
             assert len(args) == 1
-            assert isinstance(args[0], file)
+            assert isinstance(args[0], FileType)
             assert kwargs['options']['extra_attribute'] == {'ldap_attr': 'first_name'}
             assert kwargs['options']['result'] == 'result'
 
@@ -67,7 +67,7 @@ def test_load_ldif(db, monkeypatch, tmpdir):
         def __init__(self, *args, **kwargs):
             self.users = []
             assert len(args) == 1
-            assert isinstance(args[0], file)
+            assert isinstance(args[0], FileType)
             assert kwargs['options']['extra_attribute'] == {
                 'ldap_attr': 'first_name'}
             assert kwargs['options']['result'] == 'result'
-- 
2.20.1

