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()
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
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',
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)
# 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):
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):
def load (self):
try:
- infile=file(self.filename,'r')
+ infile=open(self.filename,'r')
self.url2version=pickle.load(infile)
infile.close()
except:
def save (self):
try:
- outfile=file(self.filename,'w')
+ outfile=open(self.filename,'w')
pickle.dump(self.url2version,outfile)
outfile.close()
except:
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, ))
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("-----"):