[elbe-devel] [PATCH 08/25] py3: use open instead of file

Manuel Traut manut at linutronix.de
Fri Dec 1 16:51:05 CET 2017


When opening a file, it's preferable to use open() instead of invoking
the file constructor directly. file is more suited to type testing
(for example, writing "isinstance(f, file)").

Also, file() has been removed since Python 3.0

Signed-off-by: Manuel Traut <manut at linutronix.de>
---
 elbepack/daemons/soap/esoap.py | 2 +-
 elbepack/soapclient.py         | 4 ++--
 elbepack/templates.py          | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/elbepack/daemons/soap/esoap.py b/elbepack/daemons/soap/esoap.py
index a866aee5..8189a94f 100644
--- a/elbepack/daemons/soap/esoap.py
+++ b/elbepack/daemons/soap/esoap.py
@@ -119,7 +119,7 @@ class ESoap (ServiceBase):
         if (pos >= file_stat.st_size):
             return "EndOfFile"
 
-        with file (file_name) as fp:
+        with open (file_name) as fp:
             if not fp:
                 return "FileNotFound"
             try:
diff --git a/elbepack/soapclient.py b/elbepack/soapclient.py
index 1384acc1..ede9164e 100644
--- a/elbepack/soapclient.py
+++ b/elbepack/soapclient.py
@@ -255,7 +255,7 @@ class SetXmlAction(ClientAction):
 
         size = 1024 * 1024
         part = 0
-        with file (filename, "rb") as fp:
+        with open (filename, "rb") as fp:
             while (True):
                 xml_base64 = binascii.b2a_base64(fp.read (size))
                 # finish upload
@@ -684,7 +684,7 @@ class UploadPackageAction(RepoAction):
         # Uploads file f into builddir in intivm
         size = 1024 * 1024
         part = 0
-        with file (f, "rb") as fp:
+        with open (f, "rb") as fp:
             while (True):
                 xml_base64 = binascii.b2a_base64(fp.read (size))
                 # finish upload
diff --git a/elbepack/templates.py b/elbepack/templates.py
index 9808ad1c..634b7ccd 100644
--- a/elbepack/templates.py
+++ b/elbepack/templates.py
@@ -38,7 +38,7 @@ def template(fname, d, linebreak=False):
         raise
 
 def write_template( outname, fname, d, linebreak=False ):
-    outfile = file(outname, "w")
+    outfile = open(outname, "w")
     outfile.write( template( fname, d, linebreak ) )
     outfile.close()
 
-- 
2.15.1




More information about the elbe-devel mailing list