On 2015-07-14 13:24, Christian Heimes wrote:
> The patch replaces file() with open() and a proper with statement.
> 
> The patch is related to https://fedorahosted.org/freeipa/ticket/5127
> 
> Christian

The first patch has a typo.

Note to self: save file first, then commit

Christian

From da3d6910f3997d5d411cd20bcad4b75efb333b65 Mon Sep 17 00:00:00 2001
From: Christian Heimes <chei...@redhat.com>
Date: Tue, 14 Jul 2015 13:18:55 +0200
Subject: [PATCH] [py3] Replace file() with open()

The open() function is the recommended way to open a file. In Python 3
the file type is gone, but open() still works the same.

The patch is related to https://fedorahosted.org/freeipa/ticket/5127
---
 ipapython/sysrestore.py | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/ipapython/sysrestore.py b/ipapython/sysrestore.py
index 580df9a4fd6d0fae35602dad1f81d498fa8f0173..c058ff7c04d4604ba96c2a4ece68d476b5b6491f 100644
--- a/ipapython/sysrestore.py
+++ b/ipapython/sysrestore.py
@@ -93,9 +93,8 @@ class FileStore:
         for (key, value) in self.files.items():
             p.set('files', key, str(value))
 
-        f = file(self._index, "w")
-        p.write(f)
-        f.close()
+        with open(self._index, "w") as f:
+            p.write(f)
 
     def backup_file(self, path):
         """Create a copy of the file at @path - so long as a copy
@@ -354,9 +353,8 @@ class StateFile:
             for (key, value) in self.modules[module].items():
                 p.set(module, key, str(value))
 
-        f = file(self._path, "w")
-        p.write(f)
-        f.close()
+        with open(self._path, "w") as f:
+            p.write(f)
 
     def backup_state(self, module, key, value):
         """Backup an item of system state from @module, identified
-- 
2.4.3

Attachment: signature.asc
Description: OpenPGP digital signature

-- 
Manage your subscription for the Freeipa-devel mailing list:
https://www.redhat.com/mailman/listinfo/freeipa-devel
Contribute to FreeIPA: http://www.freeipa.org/page/Contribute/Code

Reply via email to