mirror of
https://github.com/StevenBlack/hosts.git
synced 2026-10-04 06:11:13 +01:00
Use 'with' to not leave a resource open
This commit is contained in:
+3
-3
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user