Commit e114af97 authored by Robert Luberda's avatar Robert Luberda
Browse files

Merge branch 'fix-resource-warnings-unclosed-file' into 'debian-sid'

Fix several ResourceWarning: unclosed file

See merge request !2
parents a5bff002 8a80edb7
Loading
Loading
Loading
Loading
+10 −11
Original line number Diff line number Diff line
@@ -71,10 +71,9 @@ def main(config):
            # See Debian Bug #343423.  (Note: with $APT_HOOK_INFO_FD
            # support introduced in version 3.2, stdin should point to
            # a terminal already, so there should be no need to reopen it).
             tty = open('/dev/tty', 'rb+', buffering=0)
            with open('/dev/tty', 'rb+', buffering=0) as tty:
                os.close(0)
                os.dup2(tty.fileno(), 0)
             tty.close()
        except Exception as ex:
            ALCLog.warning(_("Cannot reopen /dev/tty for stdin: %s") % str(ex))

+4 −5
Original line number Diff line number Diff line
@@ -53,11 +53,10 @@ class AptPipeline(object):
        self._config = config

    def read(self):
        fd = self._open_apt_fd()

        if self._config.debug:
            ALCLog.debug(_("APT pipeline messages:"))

        with self._open_apt_fd() as fd:
            self._read_version(fd)
            self._read_options(fd)
            debs = self._read_packages(fd)
+4 −2
Original line number Diff line number Diff line
@@ -113,7 +113,8 @@ class ControlParser:

    def readfile(self, file):
        try:
            self.stanzas += [ControlStanza(x) for x in open(file, 'r', encoding='utf-8', errors='replace').read().split('\n\n') if x]
            with open(file, encoding='utf-8', errors='replace') as f:
                self.stanzas += [ControlStanza(x) for x in f.read().split('\n\n') if x]
        except Exception as ex:
            raise RuntimeError(_("Error processing '%(what)s': %(errmsg)s") %
                                {'what': file, 'errmsg': str(ex)}) from ex
@@ -335,6 +336,7 @@ class Package:
        if not fd:
            return None

        with fd:
            entries, urgency = ChangelogParser().parse(fd, since_version)

        if urgency is None:
+4 −4
Original line number Diff line number Diff line
@@ -277,8 +277,8 @@ class ttyconfirm(base):
        if sys.stdin.isatty() and sys.stdout.isatty():
            return input(prompt).rstrip()

        tty = open('/dev/tty', 'rb+', buffering=0)
        enc = ALChacks.system_encoding()
        with open('/dev/tty', 'rb+', buffering=0) as tty:
            tty.write(enc.to_bytes(prompt))
            tty.flush()
            return enc.from_bytes(tty.readline()).rstrip()