Address ResourceWarning warnings

Signed-off-by: JoeLametta <JoeLametta@users.noreply.github.com>
This commit is contained in:
JoeLametta
2019-08-12 09:00:00 +00:00
parent fff3014e15
commit bb4c25df97
11 changed files with 49 additions and 47 deletions

View File

@@ -147,7 +147,8 @@ def _save_entry(raw_entry, path):
except OSError as e:
logger.error('could not save entry to %s: %s', path, e)
return
open(path, 'wb').write(raw_entry)
with open(path, 'wb') as f:
f.write(raw_entry)
def get_db_entry(path):
@@ -160,7 +161,8 @@ def get_db_entry(path):
cached_path = join(_CACHE_DIR, path)
if exists(cached_path):
logger.debug('found accuraterip entry at %s', cached_path)
raw_entry = open(cached_path, 'rb').read()
with open(cached_path, 'rb') as f:
raw_entry = f.read()
else:
raw_entry = _download_entry(path)
if raw_entry:

View File

@@ -98,17 +98,16 @@ class Persister:
if not os.path.exists(self._path):
return
handle = open(self._path, 'rb')
import pickle
try:
self.object = pickle.load(handle)
logger.debug('loaded persisted object from %r', self._path)
# FIXME: catching too general exception (Exception)
except Exception as e:
# can fail for various reasons; in that case, pretend we didn't
# load it
logger.debug(e)
with open(self._path, 'rb') as handle:
import pickle
try:
self.object = pickle.load(handle)
logger.debug('loaded persisted object from %r', self._path)
# FIXME: catching too general exception (Exception)
except Exception as e:
# can fail for various reasons; in that case, pretend we didn't
# load it
logger.debug(e)
def delete(self):
self.object = None

View File

@@ -317,11 +317,11 @@ class VersionGetter:
version = "(Unknown)"
try:
p = asyncsub.Popen(self._args,
stdin=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, close_fds=True)
p.wait()
output = asyncsub.recv_some(p, e=0, stderr=1).decode()
with asyncsub.Popen(self._args,
stdin=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, close_fds=True) as p:
p.wait()
output = asyncsub.recv_some(p, e=0, stderr=1).decode()
vre = self._regexp.search(output)
if vre:
version = self._expander % vre.groupdict()