From 5a6cbf4fa6837c81354b616d4cfa0352ec5367be Mon Sep 17 00:00:00 2001 From: Thierry Parmentelat Date: Fri, 1 Apr 2016 11:22:25 +0200 Subject: [PATCH] open() instead of file() --- clientbin/sfiAddLinks.py | 10 +++++----- clientbin/sfiAddSliver.py | 10 +++++----- flashpolicy/sfa_flashpolicy.py | 2 +- sfa/client/manifolduploader.py | 2 +- sfa/client/sfaclientlib.py | 13 +++++-------- sfa/client/sfascan.py | 4 ++-- sfa/client/sfi.py | 2 +- sfa/trust/credential.py | 3 ++- 8 files changed, 22 insertions(+), 24 deletions(-) diff --git a/clientbin/sfiAddLinks.py b/clientbin/sfiAddLinks.py index 2e667b1b..b16cae6a 100755 --- a/clientbin/sfiAddLinks.py +++ b/clientbin/sfiAddLinks.py @@ -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() diff --git a/clientbin/sfiAddSliver.py b/clientbin/sfiAddSliver.py index 84ffa8b0..6e6042ce 100755 --- a/clientbin/sfiAddSliver.py +++ b/clientbin/sfiAddSliver.py @@ -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 diff --git a/flashpolicy/sfa_flashpolicy.py b/flashpolicy/sfa_flashpolicy.py index 1fe3f844..f4d3f165 100644 --- a/flashpolicy/sfa_flashpolicy.py +++ b/flashpolicy/sfa_flashpolicy.py @@ -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', diff --git a/sfa/client/manifolduploader.py b/sfa/client/manifolduploader.py index a9dd29d7..3b9de167 100755 --- a/sfa/client/manifolduploader.py +++ b/sfa/client/manifolduploader.py @@ -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) diff --git a/sfa/client/sfaclientlib.py b/sfa/client/sfaclientlib.py index ebadb013..b7114be4 100644 --- a/sfa/client/sfaclientlib.py +++ b/sfa/client/sfaclientlib.py @@ -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): diff --git a/sfa/client/sfascan.py b/sfa/client/sfascan.py index d3ae2fdb..136835db 100644 --- a/sfa/client/sfascan.py +++ b/sfa/client/sfascan.py @@ -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: diff --git a/sfa/client/sfi.py b/sfa/client/sfi.py index c0f1e410..95acf181 100644 --- a/sfa/client/sfi.py +++ b/sfa/client/sfi.py @@ -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, )) diff --git a/sfa/trust/credential.py b/sfa/trust/credential.py index c4795cc2..6f5336d6 100644 --- a/sfa/trust/credential.py +++ b/sfa/trust/credential.py @@ -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("-----"): -- 2.43.0