mirror of
https://github.com/StevenBlack/hosts.git
synced 2026-11-18 08:11:33 +00:00
Use 'with' to not leave a resource open
This commit is contained in:
1 parent
0f727b8bed
commit
0a96dcad34
1 file changed
+3
-3
+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