Skip to content

Commit

Permalink
Remove part of HTTP download code from urlopen() context manager
Browse files Browse the repository at this point in the history
  • Loading branch information
ptgolden committed Sep 12, 2024
1 parent 1a04064 commit d957ece
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions kghub_downloader/download_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,18 +214,19 @@ def download_from_yaml(
) # first 5 kB of a `bytes` object
else:
data = response.read() # a `bytes` object
with open(outfile, "wb") as out_file:
out_file.write(data)
if snippet_only: # Need to clean up the outfile
in_file = open(outfile, "r+")
in_lines = in_file.read()
in_file.close()
splitlines = in_lines.split("\n")
outstring = "\n".join(splitlines[:-1])
cleanfile = open(outfile, "w+")
for i in range(len(outstring)):
cleanfile.write(outstring[i])
cleanfile.close()

with open(outfile, "wb") as out_file:
out_file.write(data)
if snippet_only: # Need to clean up the outfile
in_file = open(outfile, "r+")
in_lines = in_file.read()
in_file.close()
splitlines = in_lines.split("\n")
outstring = "\n".join(splitlines[:-1])
cleanfile = open(outfile, "w+")
for i in range(len(outstring)):
cleanfile.write(outstring[i])
cleanfile.close()
except URLError:
logging.error(f"Failed to download: {url}")
raise
Expand Down

0 comments on commit d957ece

Please sign in to comment.