mirror of
https://github.com/StevenBlack/hosts.git
synced 2024-07-07 13:02:27 +02:00
Use 'with' to not leave a resource open
This commit is contained in:
parent
0f727b8bed
commit
0a96dcad34
@ -1483,9 +1483,9 @@ def get_file_by_url(url):
|
||||
"""
|
||||
|
||||
try:
|
||||
f = urlopen(url)
|
||||
soup = BeautifulSoup(f.read(), "lxml").get_text()
|
||||
return "\n".join(list(map(domain_to_idna, soup.split("\n"))))
|
||||
with urlopen(url) as f:
|
||||
soup = BeautifulSoup(f.read(), "lxml").get_text()
|
||||
return "\n".join(list(map(domain_to_idna, soup.split("\n"))))
|
||||
except Exception:
|
||||
print("Problem getting file: ", url)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user