open() instead of file()
authorThierry Parmentelat <thierry.parmentelat@inria.fr>
Fri, 1 Apr 2016 09:22:25 +0000 (11:22 +0200)
committerThierry Parmentelat <thierry.parmentelat@inria.fr>
Fri, 1 Apr 2016 10:02:14 +0000 (12:02 +0200)
clientbin/sfiAddLinks.py
clientbin/sfiAddSliver.py
flashpolicy/sfa_flashpolicy.py
sfa/client/manifolduploader.py
sfa/client/sfaclientlib.py
sfa/client/sfascan.py
sfa/client/sfi.py
sfa/trust/credential.py

index 2e667b1..b16cae6 100755 (executable)
@@ -21,15 +21,15 @@ if not command.opts.linkfile:
     sys.exit(1)
     
 if command.opts.infile:
-    infile=file(command.opts.infile)
+    infile = open(command.opts.infile)
 else:
-    infile=sys.stdin
+    infile = sys.stdin
 if command.opts.outfile:
-    outfile=file(command.opts.outfile,"w")
+    outfile = open(command.opts.outfile, "w")
 else:
-    outfile=sys.stdout
+    outfile = sys.stdout
 ad_rspec = RSpec(infile)
-links = file(command.opts.linkfile).read().split('\n')
+links = open(command.opts.linkfile).read().split('\n')
 link_tuples = map(lambda x: tuple(x.split()), links)
 
 version_manager = VersionManager()
index 84ffa8b..6e6042c 100755 (executable)
@@ -21,15 +21,15 @@ if not command.opts.nodefile:
     sys.exit(1)
     
 if command.opts.infile:
-    infile=file(command.opts.infile)
+    infile = open(command.opts.infile)
 else:
-    infile=sys.stdin
+    infile = sys.stdin
 if command.opts.outfile:
-    outfile=file(command.opts.outfile,"w")
+    outfile = open(command.opts.outfile,"w")
 else:
-    outfile=sys.stdout
+    outfile = sys.stdout
 ad_rspec = RSpec(infile)
-nodes = file(command.opts.nodefile).read().split()
+nodes = open(command.opts.nodefile).read().split()
 version_manager = VersionManager()
 try:
     type = ad_rspec.version.type
index 1fe3f84..f4d3f16 100644 (file)
@@ -50,7 +50,7 @@ class policy_server(object):
         self.sock.bind(('', port))
         self.sock.listen(5)
     def read_policy(self, path):
-        with file(path, 'rb') as f:
+        with open(path, 'rb') as f:
             policy = f.read(10001)
             if len(policy) > 10000:
                 raise exceptions.RuntimeError('File probably too large to be a policy file',
index a9dd29d..3b9de16 100755 (executable)
@@ -164,7 +164,7 @@ def main ():
                                  logger=sfi_logger)
 
     for filename in args.credential_files:
-        with file(filename) as f:
+        with open(filename) as f:
             result=uploader.upload (f.read(),filename)
             sfi_logger.info('... result=%s'%result)
 
index ebadb01..b7114be 100644 (file)
@@ -306,15 +306,12 @@ class SfaClientBootstrap:
 #        return Credential(filename=self.my_credential()).save_to_string()
 # but in order to make it simpler to other implementations/languages..
     def plain_read(self, filename):
-        infile = file(filename, "r")
-        result = infile.read()
-        infile.close()
-        return result
+        with open(filename) as infile:
+            return infile.read()
 
     def plain_write(self, filename, contents):
-        outfile = file(filename, "w")
-        result = outfile.write(contents)
-        outfile.close()
+        with open(filename, "w") as outfile:
+            outfile.write(contents)
 
     def assert_filename(self, filename, kind):
         if not os.path.isfile(filename):
@@ -337,7 +334,7 @@ class SfaClientBootstrap:
         def wrap(f):
             def wrapped(self, *args, **kw):
                 filename = filename_method(self, *args, **kw)
-                if os.path.isfile( filename ):
+                if os.path.isfile(filename):
                     if not validate_method:
                         return filename
                     elif validate_method(self, filename): 
index d3ae2fd..136835d 100644 (file)
@@ -51,7 +51,7 @@ class VersionCache:
 
     def load (self):
         try:
-            infile=file(self.filename,'r')
+            infile=open(self.filename,'r')
             self.url2version=pickle.load(infile)
             infile.close()
         except:
@@ -61,7 +61,7 @@ class VersionCache:
 
     def save (self):
         try:
-            outfile=file(self.filename,'w')
+            outfile=open(self.filename,'w')
             pickle.dump(self.url2version,outfile)
             outfile.close()
         except:
index c0f1e41..95acf18 100644 (file)
@@ -1776,7 +1776,7 @@ $ sfi m -b http://mymanifold.foo.com:7080/
             filename = os.path.join( self.options.sfi_dir,
                                       "{}.{}_for_{}.{}.cred"\
                                       .format(hrn, htype, delegatee_hrn, delegatee_type))
-            with file(filename, 'w') as f:
+            with open(filename, 'w') as f:
                 f.write(delegated_credential)
             self.logger.debug("(Over)wrote {}".format(filename))
             hrn_delegated_credentials.append((hrn, htype, delegated_credential, filename, ))
index c4795cc..6f5336d 100644 (file)
@@ -299,7 +299,8 @@ class Credential(object):
             if string:                
                 str = string
             elif filename:
-                str = file(filename).read()
+                with open(filename) as infile:
+                    str = infile.read()
                 
             # if this is a legacy credential, write error and bail out
             if isinstance (str, StringType) and str.strip().startswith("-----"):