MCPcopy
hub / github.com/StevenBlack/hosts / get_file_by_url

Function get_file_by_url

updateHostsFile.py:1696–1726  ·  view source on GitHub ↗

Retrieve the contents of the hosts file at the URL, then pass it through domain_to_idna(). Parameters are passed to the requests.get() function. Parameters ---------- url : str or bytes URL for the new Request object. params : Dictionary, list of tuples or

(url, params=None, **kwargs)

Source from the content-addressed store, hash-verified

1694
1695
1696def get_file_by_url(url, params=None, **kwargs):
1697 """
1698 Retrieve the contents of the hosts file at the URL, then pass it through domain_to_idna().
1699
1700 Parameters are passed to the requests.get() function.
1701
1702 Parameters
1703 ----------
1704 url : str or bytes
1705 URL for the new Request object.
1706 params :
1707 Dictionary, list of tuples or bytes to send in the query string for the Request.
1708 kwargs :
1709 Optional arguments that request takes.
1710
1711 Returns
1712 -------
1713 url_data : str or None
1714 The data retrieved at that URL from the file. Returns None if the
1715 attempted retrieval is unsuccessful.
1716 """
1717
1718 try:
1719 req = requests.get(url=url, params=params, **kwargs)
1720 except requests.exceptions.RequestException:
1721 print("Error retrieving data from {}".format(url))
1722 return None
1723
1724 req.encoding = req.apparent_encoding
1725 res_text = "\n".join([domain_to_idna(line) for line in req.text.split("\n")])
1726 return res_text
1727
1728
1729def write_data(f, data):

Callers 5

test_basicMethod · 0.90
test_with_idnaMethod · 0.90
test_invalid_urlMethod · 0.90
update_all_sourcesFunction · 0.85

Calls 1

domain_to_idnaFunction · 0.85

Tested by 4

test_basicMethod · 0.72
test_with_idnaMethod · 0.72
test_invalid_urlMethod · 0.72