From dbeca9f785cb90139fde37ad0aaad61f70b5506f Mon Sep 17 00:00:00 2001 From: Brian May Date: Mon, 4 Mar 2019 17:21:45 +1100 Subject: Replace file() with open() for Python 3 compatability --- lib/python/debian_support.py | 8 ++++---- lib/python/nvd.py | 2 +- lib/python/secmaster.py | 2 +- lib/python/sectracker/repo.py | 6 +++--- lib/python/sectracker/xpickle.py | 4 ++-- lib/python/security_db.py | 2 +- 6 files changed, 12 insertions(+), 12 deletions(-) (limited to 'lib') diff --git a/lib/python/debian_support.py b/lib/python/debian_support.py index 8bece17da3..8657be82f2 100644 --- a/lib/python/debian_support.py +++ b/lib/python/debian_support.py @@ -131,7 +131,7 @@ class PackageFile: file with the indicated name. """ if fileObj is None: - fileObj = file(name) + fileObj = open(name) self.name = name self.file = fileObj self.lineno = 0 @@ -274,7 +274,7 @@ def replaceFile(lines, local): import os.path local_new = local + '.new' - new_file = file(local_new, 'w+') + new_file = open(local_new, 'w+') try: for l in lines: @@ -318,7 +318,7 @@ def updateFile(remote, local, verbose=None): """ try: - local_file = file(local) + local_file = open(local) except IOError: if verbose: print("updateFile: no local copy, downloading full file") @@ -521,7 +521,7 @@ def getconfig(): global _config if _config is not None: return _config - _config = json.load(file(findresource("data", "config.json"))) + _config = json.load(open(findresource("data", "config.json"))) return _config _releasecodename = None diff --git a/lib/python/nvd.py b/lib/python/nvd.py index 1e0771e13d..f62acdfb0d 100644 --- a/lib/python/nvd.py +++ b/lib/python/nvd.py @@ -125,4 +125,4 @@ def parse(file): if __name__ == "__main__": import sys for name in sys.argv[1:]: - parse(file(name)) + parse(open(name)) diff --git a/lib/python/secmaster.py b/lib/python/secmaster.py index f87cdfd1e4..f1f17303ee 100644 --- a/lib/python/secmaster.py +++ b/lib/python/secmaster.py @@ -34,7 +34,7 @@ def listqueue(): """ ssh = subprocess.Popen( ("ssh", HOST, "secure-testing/bin/list-queue"), - stdin=file("/dev/null"), + stdin=open("/dev/null"), stdout=subprocess.PIPE) data = ssh.stdout.read() ssh.wait() diff --git a/lib/python/sectracker/repo.py b/lib/python/sectracker/repo.py index 7e6d454f51..bbe25822f6 100644 --- a/lib/python/sectracker/repo.py +++ b/lib/python/sectracker/repo.py @@ -132,7 +132,7 @@ class RepoCollection(object): _os.makedirs(root) l = _os.listdir(root) if len(l) == 0: - file(root + "/" + MARKER_NAME, "w").close() + open(root + "/" + MARKER_NAME, "w").close() elif MARKER_NAME not in l: raise ValueError("not a Debian repository mirror directory: " + repr(root)) @@ -197,7 +197,7 @@ class RepoCollection(object): def release(self, name): if name not in self.repos: raise ValueError("name not registered: " + repr(name)) - with file(self._relname(name)) as f: + with open(self._relname(name)) as f: return _parserelease(name, f) def filemap(self, load=False): @@ -255,7 +255,7 @@ class RepoCollection(object): class Config(object): def __init__(self, config, root): - with file(config) as f: + with open(config) as f: self.config = _cjson.decode(f.read()) self.repositories = self.config["repositories"] self.distributions = self.config["distributions"] diff --git a/lib/python/sectracker/xpickle.py b/lib/python/sectracker/xpickle.py index 9a7296e4cc..78a8e95075 100644 --- a/lib/python/sectracker/xpickle.py +++ b/lib/python/sectracker/xpickle.py @@ -63,7 +63,7 @@ def _wraploader(typ, parser): def safeload(path): try: - with file(path + EXTENSION) as f: + with open(path + EXTENSION, "rb") as f: return (_pickle.load(f), True) except (EOFError, IOError, _pickle.PickleError): return (None, False) @@ -78,7 +78,7 @@ def _wraploader(typ, parser): return (None, False) def reparse(path, st): - with file(path) as f: + with open(path) as f: obj = parser(path, f) data = _pickle.dumps( ((typ, st.st_size, st.st_mtime, st.st_ino), obj), -1) diff --git a/lib/python/security_db.py b/lib/python/security_db.py index 72a4308668..5b94e74774 100644 --- a/lib/python/security_db.py +++ b/lib/python/security_db.py @@ -1921,7 +1921,7 @@ class DB: """Reads a file of removed packages and stores it in the database. The original contents of the removed_packages table is preserved.""" - f = file(filename) + f = open(filename) re_package = re.compile(r'^\s*([a-z0-9]\S+)\s*$') -- cgit v1.2.3