Commit af8d0cb8 authored by Rémi Cardona's avatar Rémi Cardona
Browse files

[py3k] file → open

parent 8d9fe02387e3
......@@ -961,7 +961,7 @@ the repository',
i = 1
while exists(path) and i < 100: # arbitrary limit to avoid infinite loop
try:
file(path, 'a')
open(path, 'a')
break
except IOError:
path = '%s-%s.log' % (basepath, i)
......
......@@ -115,7 +115,7 @@ class InstanceCommand(Command):
_allinstances = list_instances(regdir)
if isfile(join(regdir, 'startorder')):
allinstances = []
for line in file(join(regdir, 'startorder')):
for line in open(join(regdir, 'startorder')):
line = line.strip()
if line and not line.startswith('#'):
try:
......
......@@ -322,7 +322,7 @@ class UpdateCubicWebCatalogCommand(Command):
potfiles.append(schemapot)
# explicit close necessary else the file may not be yet flushed when
# we'll using it below
schemapotstream = file(schemapot, 'w')
schemapotstream = open(schemapot, 'w')
generate_schema_pot(schemapotstream.write, cubedir=None)
schemapotstream.close()
print('TAL', end=' ')
......@@ -446,7 +446,7 @@ def update_cube_catalogs(cubedir):
potfiles.append(schemapot)
# explicit close necessary else the file may not be yet flushed when
# we'll using it below
schemapotstream = file(schemapot, 'w')
schemapotstream = open(schemapot, 'w')
generate_schema_pot(schemapotstream.write, cubedir)
schemapotstream.close()
print('TAL', end=' ')
......@@ -712,7 +712,7 @@ class ExamineLogCommand(Command):
requests = {}
for filepath in args:
try:
stream = file(filepath)
stream = open(filepath)
except OSError as ex:
raise BadCommandUsage("can't open rql log file %s: %s"
% (filepath, ex))
......
......@@ -156,7 +156,7 @@ def run(args):
elif opt in ('-P', '--profile'):
prof_file = val
elif opt in ('-o', '--report-output'):
report_output = file(val, 'w')
report_output = open(val, 'w')
if len(args) != 2:
usage(1)
queries = [query for query in lines(args[1]) if not query.startswith('#')]
......
......@@ -52,7 +52,7 @@ class ValueGeneratorTC(TestCase):
return None
def _available_Person_firstname(self, etype, attrname):
return [f.strip() for f in file(osp.join(DATADIR, 'firstnames.txt'))]
return [f.strip() for f in open(osp.join(DATADIR, 'firstnames.txt'))]
def setUp(self):
config = ApptestConfiguration('data', apphome=DATADIR)
......
......@@ -63,7 +63,7 @@ class CubicWebDebugger(Debugger):
def do_view(self, arg):
import webbrowser
data = self._getval(arg)
with file('/tmp/toto.html', 'w') as toto:
with open('/tmp/toto.html', 'w') as toto:
toto.write(data)
webbrowser.open('file:///tmp/toto.html')
......
......@@ -206,7 +206,7 @@ def compile_template_file(filepath):
:type filepath: str
:param template: path of the file to compile
"""
fp = file(filepath)
fp = open(filepath)
file_content = unicode(fp.read()) # template file should be pure ASCII
fp.close()
return compile_template(file_content)
......
......@@ -30,7 +30,7 @@ def spec_parser(filename) :
sections = []
buffer = ""
in_section = False
for line in file(filename) :
for line in open(filename) :
if line.startswith('Test::'):
in_section = True
buffer = ""
......
......@@ -235,7 +235,7 @@ notified of every changes.',
def bootstrap_cubes(self):
from logilab.common.textutils import splitstrip
for line in file(join(self.apphome, 'bootstrap_cubes')):
for line in open(join(self.apphome, 'bootstrap_cubes')):
line = line.strip()
if not line or line.startswith('#'):
continue
......@@ -246,7 +246,7 @@ notified of every changes.',
self.init_cubes(())
def write_bootstrap_cubes_file(self, cubes):
stream = file(join(self.apphome, 'bootstrap_cubes'), 'w')
stream = open(join(self.apphome, 'bootstrap_cubes'), 'w')
stream.write('# this is a generated file only used for bootstraping\n')
stream.write('# you should not have to edit this\n')
stream.write('%s\n' % ','.join(cubes))
......
......@@ -55,8 +55,8 @@ def create_slapd_configuration(cls):
slapddir = tempfile.mkdtemp('cw-unittest-ldap')
config = cls.config
slapdconf = join(config.apphome, "slapd.conf")
confin = file(join(config.apphome, "slapd.conf.in")).read()
confstream = file(slapdconf, 'w')
confin = open(join(config.apphome, "slapd.conf.in")).read()
confstream = open(slapdconf, 'w')
confstream.write(confin % {'apphome': config.apphome, 'testdir': slapddir})
confstream.close()
# fill ldap server with some data
......
......@@ -215,7 +215,7 @@ class StorageTC(CubicWebTC):
f1 = cnx.create_entity('File', data=Binary(filepath),
data_format=u'text/plain', data_name=u'foo')
cw_value = f1.data.getvalue()
fs_value = file(filepath).read()
fs_value = open(filepath).read()
if cw_value != fs_value:
self.fail('cw value %r is different from file content' % cw_value)
......@@ -304,7 +304,7 @@ class StorageTC(CubicWebTC):
old_fspath = self.fspath(cnx, f1)
cnx.transaction_data['fs_importing'] = True
new_fspath = osp.join(self.tempdir, 'newfile.txt')
file(new_fspath, 'w').write('the new data')
open(new_fspath, 'w').write('the new data')
cnx.execute('SET F data %(d)s WHERE F eid %(f)s',
{'d': Binary(new_fspath), 'f': f1.eid})
cnx.commit()
......
......@@ -42,7 +42,7 @@ from distutils.command import install_data
from __pkginfo__ import modname, version, license, description, web, \
author, author_email
long_description = file('README').read()
long_description = open('README').read()
# import optional features
import __pkginfo__
......
......@@ -44,7 +44,7 @@ from __pkginfo__ import modname, version, license, description, web, \
author, author_email, classifiers
if exists('README'):
long_description = file('README').read()
long_description = open('README').read()
else:
long_description = ''
......
......@@ -26,5 +26,5 @@ def registration_callback(vreg):
if vreg.config.apphome:
url_mapping_file = osp.join(vreg.config.apphome, 'urlmapping.py')
if osp.exists(url_mapping_file):
URL_MAPPING = eval(file(url_mapping_file).read())
URL_MAPPING = eval(open(url_mapping_file).read())
vreg.info('using url mapping %s from %s', URL_MAPPING, url_mapping_file)
......@@ -112,7 +112,7 @@ def show_diffs(appl_file, ref_file, askconfirm=True):
sys.exit(0)
else:
copy_file = appl_file + '.default'
copy = file(copy_file, 'w')
copy = open(copy_file, 'w')
copy.write(open(ref_file).read())
copy.close()
print('keep current version, the new file has been written to', copy_file)
......@@ -151,8 +151,8 @@ def copy_skeleton(skeldir, targetdir, context,
shutil.copyfile(fpath, tfpath)
def fill_templated_file(fpath, tfpath, context):
fobj = file(tfpath, 'w')
templated = file(fpath).read()
fobj = open(tfpath, 'w')
templated = open(fpath).read()
fobj.write(templated % context)
fobj.close()
......
......@@ -96,7 +96,7 @@ class PropertySheet(dict):
if not osp.exists(rcachedir):
os.makedirs(rcachedir)
sourcefile = osp.join(rdirectory, rid)
content = file(sourcefile).read()
content = open(sourcefile).read()
# XXX replace % not followed by a paren by %% to avoid having to do
# this in the source css file ?
try:
......@@ -105,7 +105,7 @@ class PropertySheet(dict):
self.error("can't process %s/%s: %s", rdirectory, rid, ex)
adirectory = rdirectory
else:
stream = file(cachefile, 'w')
stream = open(cachefile, 'w')
stream.write(content)
stream.close()
adirectory = self._cache_directory
......
......@@ -460,7 +460,7 @@ have the python imaging library installed to use captcha)',
staticdir = join(staticdir, rdir)
if not isdir(staticdir) and 'w' in mode:
os.makedirs(staticdir)
return file(join(staticdir, filename), mode)
return open(join(staticdir, filename), mode)
def static_file_add(self, rpath, data):
stream = self.static_file_open(rpath)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment