Commit c9d3d93d authored by Guido Günther's avatar Guido Günther

Use open() instead of file()

since the later doesn't exist in python3
parent 8f073ebc
......@@ -115,7 +115,7 @@ class ChangeLog(object):
self._cp = cp
def _read(self):
with file(self.filename) as f:
with open(self.filename) as f:
self._contents = f.read()
def __getitem__(self, item):
......
......@@ -47,7 +47,7 @@ class Control(object):
if not os.access(filename, os.F_OK):
raise NoControlError("Control file %s does not exist" % filename)
with file(filename) as f:
with open(filename) as f:
control = email.message_from_file(f)
if not control.items():
......
......@@ -49,7 +49,7 @@ class DscFile(object):
self.native = False
self.dscfile = os.path.abspath(dscfile)
f = file(self.dscfile)
f = open(self.dscfile)
fromdir = os.path.dirname(os.path.abspath(dscfile))
for line in f:
m = self.version_re.match(line)
......
......@@ -92,7 +92,7 @@ class DebianSourceFormat(object):
'quilt'
>>> os.unlink(t.name)
"""
with file(filename) as f:
with open(filename) as f:
return klass(f.read())
@classmethod
......@@ -107,7 +107,7 @@ class DebianSourceFormat(object):
the above parameters
"""
format_file = format_file or klass.format_file
with file(klass.format_file, 'w') as f:
with open(klass.format_file, 'w') as f:
f.write("%s (%s)" % (version, type))
return klass.parse_file(klass.format_file)
......
......@@ -32,7 +32,7 @@ class FileVfs(object):
def open(self, path, flags=None):
flags = flags or 'r'
return file(os.path.join(self._dir, path), flags)
return open(os.path.join(self._dir, path), flags)
class DebianSourceError(Exception):
pass
......
......@@ -1653,7 +1653,7 @@ class GitRepository(object):
raise GitRepositoryError("Error running git init: %s" % stderr)
if description:
with file(os.path.join(abspath, git_dir, "description"), 'w') as f:
with open(os.path.join(abspath, git_dir, "description"), 'w') as f:
description += '\n' if description[-1] != '\n' else ''
f.write(description)
return klass(abspath)
......
......@@ -167,7 +167,7 @@ class PatchSeries(list):
return []
try:
s = file(seriesfile)
s = open(seriesfile)
except Exception as err:
raise GbpError("Cannot open series file: %s" % err)
......
......@@ -148,14 +148,14 @@ def patch_write_header(srcname, dstname):
"""
topic = None
with file(srcname) as src:
with open(srcname) as src:
header = patch_read_header(src)
header_len = len(''.join(header))
topic = patch_header_parse_topic(header)
patch_header_mangle_newline(header)
with file(dstname, 'w') as dst:
with open(dstname, 'w') as dst:
dst.write(''.join(header[1:]))
return (header_len, topic)
......@@ -165,9 +165,9 @@ def patch_write_content(srcname, dstname, header_len):
"""
Write out the patch body skipping the header
"""
with file(srcname) as src:
with open(srcname) as src:
src.seek(header_len, 0)
with file(dstname, 'a') as dst:
with open(dstname, 'a') as dst:
dst.write(src.read())
......
......@@ -126,8 +126,8 @@ def mangle_changelog(changelog, cp, snapshot=''):
"""
try:
tmpfile = '%s.%s' % (changelog, snapshot)
cw = file(tmpfile, 'w')
cr = file(changelog, 'r')
cw = open(tmpfile, 'w')
cr = open(changelog, 'r')
print >>cw, ("%(Source)s (%(MangledVersion)s) "
"%(Distribution)s; urgency=%(urgency)s\n" % cp)
......
......@@ -59,7 +59,7 @@ def export_patches(repo, branch, options):
signature=False,
symmetric=False)
if patches:
f = file(SERIES_FILE, 'w')
f = open(SERIES_FILE, 'w')
gbp.log.info("Regenerating patch queue in '%s'." % PATCH_DIR)
for patch in patches:
filename = write_patch(patch, PATCH_DIR, options)
......
......@@ -36,7 +36,7 @@ def fetch_version():
except OSError:
pass # Failing is fine, we just can't print the version then
with file('gbp/version.py', 'w') as f:
with open('gbp/version.py', 'w') as f:
f.write('"The current gbp version number"\n')
f.write('gbp_version="%s"\n' % version)
......
......@@ -38,7 +38,7 @@ def test_add_file():
fastimport.deleteall()
testfile = os.path.join(repo.path, '.git', 'description')
fastimport.add_file('./testfile',
file(testfile),
open(testfile),
os.path.getsize(testfile))
def test_add_symlink():
......
......@@ -19,7 +19,7 @@ class TestWriteTree(testutils.DebianGitTestRepo):
paths = []
for i in range(4):
path = os.path.join(self.repo.path, 'testfile%d' % i)
with file(path, 'w') as f:
with open(path, 'w') as f:
print >>f, "testdata %d" % i
paths.append(path)
return paths
......
......@@ -79,7 +79,7 @@ class TestScriptDch(DebianGitTestRepo):
options.extend(dch_options)
ret = dch.main(options)
self.assertEqual(ret, 0)
return file("debian/changelog").readlines()
return open("debian/changelog").readlines()
def test_dch_main_new_upstream_version(self):
......
......@@ -52,7 +52,7 @@ class TestDebianSource(testutils.DebianGitTestRepo):
self.assertRaises(DebianSourceError,
source.is_native)
with file('debian/changelog', 'w') as f:
with open('debian/changelog', 'w') as f:
f.write("""git-buildpackage (0.2.3) git-buildpackage; urgency=low
* git doesn't like '~' in tag names so replace this with a dot when tagging
......
......@@ -37,7 +37,7 @@ class TestSuperCommand(unittest.TestCase):
def test_invalid_command(self):
"""Test if we fail correctly with an invalid command"""
old_stderr = sys.stderr
with file('/dev/null', 'w') as sys.stderr:
with open('/dev/null', 'w') as sys.stderr:
self.assertEqual(gbp.scripts.supercommand.supercommand(
['argv0', 'asdf']), 2)
self.assertEqual(gbp.scripts.supercommand.supercommand(
......
......@@ -71,7 +71,7 @@ def test_parser_fallback():
>>> tmpdir = str(context.new_tmpdir('foo'))
>>> confname = os.path.join(tmpdir, 'gbp.conf')
>>> parser.config_files = [confname]
>>> f = file(confname, 'w')
>>> f = open(confname, 'w')
>>> f.write('[foo]\\nthere = is\\n[git-foo]\\nno = truth\\n')
>>> f.close()
>>> parser._parse_config_files()
......@@ -90,13 +90,13 @@ def test_filter():
>>> tmpdir = str(context.new_tmpdir('bar'))
>>> confname = os.path.join(tmpdir, 'gbp.conf')
>>> parser.config_files = [confname]
>>> f = file(confname, 'w')
>>> f = open(confname, 'w')
>>> f.write('[bar]\\nfilter = asdf\\n')
>>> f.close()
>>> parser._parse_config_files()
>>> parser.config['filter']
['asdf']
>>> f = file(confname, 'w')
>>> f = open(confname, 'w')
>>> f.write("[bar]\\nfilter = ['this', 'is', 'a', 'list']\\n")
>>> f.close()
>>> parser._parse_config_files()
......
......@@ -26,7 +26,7 @@ def test_read():
>>> import os, gbp.git.vfs
>>> repo_dir = context.new_tmpdir(__name__)
>>> repo = gbp.git.GitRepository.create(str(repo_dir))
>>> f = file(os.path.join(repo.path, 'foo.txt'), 'w')
>>> f = open(os.path.join(repo.path, 'foo.txt'), 'w')
>>> content = 'al pha\\na\\nb\\nc'
>>> f.write('al pha\\na\\nb\\nc')
>>> f.close()
......
......@@ -38,7 +38,7 @@ class DebianGitTestRepo(unittest.TestCase):
if not os.path.exists(d):
os.makedirs(d)
with file(path, 'w+') as f:
with open(path, 'w+') as f:
content == None or f.write(content)
self.repo.add_files(name, force=True)
self.repo.commit_files(path, msg or "added %s" % name)
......
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