Return bytes from fetch_data_from_url() (#4653)
This commit is contained in:
parent
639de7e953
commit
a68dcd6a28
|
|
@ -56,8 +56,8 @@ class MirrorListHandler:
|
|||
|
||||
for attempt_nr in range(attempts):
|
||||
try:
|
||||
mirrorlist = fetch_data_from_url(url)
|
||||
self._status_mappings = self._parse_remote_mirror_list(mirrorlist)
|
||||
data = fetch_data_from_url(url)
|
||||
self._status_mappings = self._parse_remote_mirror_list(data)
|
||||
return True
|
||||
except Exception as e:
|
||||
debug(f'Error while fetching mirror list: {e}')
|
||||
|
|
@ -85,9 +85,9 @@ class MirrorListHandler:
|
|||
# just return as-is without sorting?
|
||||
return region_list
|
||||
|
||||
def _parse_remote_mirror_list(self, mirrorlist: str) -> dict[str, list[MirrorStatusEntryV3]]:
|
||||
def _parse_remote_mirror_list(self, data: bytes) -> dict[str, list[MirrorStatusEntryV3]]:
|
||||
context = {'verbose': self.verbose}
|
||||
mirror_status = MirrorStatusListV3.model_validate_json(mirrorlist, context=context)
|
||||
mirror_status = MirrorStatusListV3.model_validate_json(data, context=context)
|
||||
|
||||
sorting_placeholder: dict[str, list[MirrorStatusEntryV3]] = {}
|
||||
|
||||
|
|
|
|||
|
|
@ -121,7 +121,7 @@ def enrich_iface_types(interfaces: list[str]) -> dict[str, str]:
|
|||
return result
|
||||
|
||||
|
||||
def fetch_data_from_url(url: str, params: dict[str, str] | None = None, timeout: int = 30) -> str:
|
||||
def fetch_data_from_url(url: str, params: dict[str, str] | None = None, timeout: int = 30) -> bytes:
|
||||
ssl_context = ssl.create_default_context()
|
||||
ssl_context.check_hostname = False
|
||||
ssl_context.verify_mode = ssl.CERT_NONE
|
||||
|
|
@ -134,8 +134,7 @@ def fetch_data_from_url(url: str, params: dict[str, str] | None = None, timeout:
|
|||
|
||||
try:
|
||||
response = urlopen(full_url, context=ssl_context, timeout=timeout)
|
||||
data = response.read().decode('UTF-8')
|
||||
return data
|
||||
return response.read()
|
||||
except URLError as e:
|
||||
raise ValueError(f'Unable to fetch data from url: {url}\n{e}')
|
||||
except Exception as e:
|
||||
|
|
|
|||
|
|
@ -262,10 +262,8 @@ class ProfileHandler:
|
|||
err = tr('Unable to fetch profile from specified url: {}').format(url)
|
||||
error(err)
|
||||
else:
|
||||
b_data = bytes(data, 'utf-8')
|
||||
|
||||
with NamedTemporaryFile(delete=False, suffix='.py') as fp:
|
||||
fp.write(b_data)
|
||||
fp.write(data)
|
||||
filepath = Path(fp.name)
|
||||
|
||||
profiles = self._process_profile_file(filepath)
|
||||
|
|
|
|||
Loading…
Reference in New Issue