mirror of
https://github.com/markqvist/NomadNet.git
synced 2026-08-29 01:08:18 +00:00
Directory/Node: replace some bare open/close's with with's
This commit is contained in:
@@ -97,9 +97,8 @@ class Directory:
|
||||
"announce_stream": self.announce_stream
|
||||
}
|
||||
|
||||
file = open(self.app.directorypath, "wb")
|
||||
file.write(msgpack.packb(directory))
|
||||
file.close()
|
||||
with open(self.app.directorypath, "wb") as file:
|
||||
file.write(msgpack.packb(directory))
|
||||
|
||||
except Exception as e:
|
||||
RNS.log("Could not write directory to disk. Then contained exception was: "+str(e), RNS.LOG_ERROR)
|
||||
@@ -107,10 +106,9 @@ class Directory:
|
||||
def load_from_disk(self):
|
||||
if os.path.isfile(self.app.directorypath):
|
||||
try:
|
||||
file = open(self.app.directorypath, "rb")
|
||||
unpacked_directory = msgpack.unpackb(file.read())
|
||||
with open(self.app.directorypath, "rb") as file:
|
||||
unpacked_directory = msgpack.unpackb(file.read())
|
||||
unpacked_list = unpacked_directory["entry_list"]
|
||||
file.close()
|
||||
|
||||
entries = {}
|
||||
for e in unpacked_list:
|
||||
|
||||
+4
-6
@@ -128,9 +128,8 @@ class Node:
|
||||
allowed_input = allowed_result.stdout
|
||||
|
||||
else:
|
||||
fh = open(allowed_path, "rb")
|
||||
allowed_input = fh.read()
|
||||
fh.close()
|
||||
with open(allowed_path, "rb") as fh:
|
||||
allowed_input = fh.read()
|
||||
|
||||
allowed_hash_strs = allowed_input.splitlines()
|
||||
|
||||
@@ -176,9 +175,8 @@ class Node:
|
||||
generated = subprocess.run([file_path], stdout=subprocess.PIPE, stderr=subprocess.DEVNULL, env=env_map)
|
||||
return generated.stdout
|
||||
else:
|
||||
fh = open(file_path, "rb")
|
||||
response_data = fh.read()
|
||||
fh.close()
|
||||
with open(file_path, "rb") as fh:
|
||||
response_data = fh.read()
|
||||
return response_data
|
||||
else:
|
||||
RNS.log("Request denied", RNS.LOG_VERBOSE)
|
||||
|
||||
Reference in New Issue
Block a user