mirror of
https://github.com/StevenBlack/hosts.git
synced 2024-07-14 00:00:34 +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:
|
try:
|
||||||
f = urlopen(url)
|
with urlopen(url) as f:
|
||||||
soup = BeautifulSoup(f.read(), "lxml").get_text()
|
soup = BeautifulSoup(f.read(), "lxml").get_text()
|
||||||
return "\n".join(list(map(domain_to_idna, soup.split("\n"))))
|
return "\n".join(list(map(domain_to_idna, soup.split("\n"))))
|
||||||
except Exception:
|
except Exception:
|
||||||
print("Problem getting file: ", url)
|
print("Problem getting file: ", url)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user