[Git][security-tracker-team/security-tracker][master] 2 commits: Replace file() with open() for Python 3 compatability

Salvatore Bonaccorso carnil at debian.org
Mon Mar 4 21:18:31 GMT 2019


Salvatore Bonaccorso pushed to branch master at Debian Security Tracker / security-tracker


Commits:
dbeca9f7 by Brian May at 2019-03-04T06:31:32Z
Replace file() with open() for Python 3 compatability

- - - - -
e41e6b51 by Salvatore Bonaccorso at 2019-03-04T21:18:02Z
Merge branch 'bam/security-tracker-fix_file_open'

- - - - -


10 changed files:

- bin/check-syntax
- bin/list-queue
- bin/mass-bug-filer
- bin/update-nvd
- lib/python/debian_support.py
- lib/python/nvd.py
- lib/python/secmaster.py
- lib/python/sectracker/repo.py
- lib/python/sectracker/xpickle.py
- lib/python/security_db.py


Changes:

=====================================
bin/check-syntax
=====================================
@@ -49,7 +49,7 @@ def construct(c, name):
         f = sys.stdin
         name = '<stdin>'
     else:
-        f  = file(name)
+        f  = open(name)
     return c(name, f)
 
 sources = debian_support.getconfig()["sources"]


=====================================
bin/list-queue
=====================================
@@ -176,7 +176,7 @@ def updatechanges(db, ondisk):
     need_update = prepareupdate(db, ondisk, indb, "changes")
     def do_update():
         for (path, stat) in need_update:
-            changes = Changes(file(path))
+            changes = Changes(open(path))
             try:
                 dist = changes["Distribution"]
                 debs = set(pkg["name"] for pkg in changes["Checksums-Sha1"])


=====================================
bin/mass-bug-filer
=====================================
@@ -11,7 +11,7 @@ if len(sys.argv) < 3:
     print("usage: %s FILE PACKAGE..." % sys.argv[0], file=sys.stderr)
     sys.exit(1)
 
-message_file = file(sys.argv[1])
+message_file = open(sys.argv[1])
 packages = sys.argv[2:]
 
 cache = apt.Cache()


=====================================
bin/update-nvd
=====================================
@@ -30,7 +30,7 @@ for name in sys.argv[1:]:
     if name == '-i':
         incremental = True
         continue
-    f = file(name)
+    f = open(name)
     data += nvd.parse(f)
     f.close()
 


=====================================
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


=====================================
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))


=====================================
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()


=====================================
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"]


=====================================
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)


=====================================
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*$')
 



View it on GitLab: https://salsa.debian.org/security-tracker-team/security-tracker/compare/088a6b02451486d4a4c2ae5547a93d10a9d41439...e41e6b5151dcf2abe0c34bc27dfe96d056e0762c

-- 
View it on GitLab: https://salsa.debian.org/security-tracker-team/security-tracker/compare/088a6b02451486d4a4c2ae5547a93d10a9d41439...e41e6b5151dcf2abe0c34bc27dfe96d056e0762c
You're receiving this email because of your account on salsa.debian.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/debian-security-tracker-commits/attachments/20190304/ee609442/attachment-0001.html>


More information about the debian-security-tracker-commits mailing list