Skip to content

Commit a68dcd6

Browse files
authored
Return bytes from fetch_data_from_url() (#4653)
1 parent 639de7e commit a68dcd6

3 files changed

Lines changed: 7 additions & 10 deletions

File tree

archinstall/lib/mirror/mirror_handler.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ def load_remote_mirrors(self) -> bool:
5656

5757
for attempt_nr in range(attempts):
5858
try:
59-
mirrorlist = fetch_data_from_url(url)
60-
self._status_mappings = self._parse_remote_mirror_list(mirrorlist)
59+
data = fetch_data_from_url(url)
60+
self._status_mappings = self._parse_remote_mirror_list(data)
6161
return True
6262
except Exception as e:
6363
debug(f'Error while fetching mirror list: {e}')
@@ -85,9 +85,9 @@ def get_status_by_region(self, region: str, speed_sort: bool) -> list[MirrorStat
8585
# just return as-is without sorting?
8686
return region_list
8787

88-
def _parse_remote_mirror_list(self, mirrorlist: str) -> dict[str, list[MirrorStatusEntryV3]]:
88+
def _parse_remote_mirror_list(self, data: bytes) -> dict[str, list[MirrorStatusEntryV3]]:
8989
context = {'verbose': self.verbose}
90-
mirror_status = MirrorStatusListV3.model_validate_json(mirrorlist, context=context)
90+
mirror_status = MirrorStatusListV3.model_validate_json(data, context=context)
9191

9292
sorting_placeholder: dict[str, list[MirrorStatusEntryV3]] = {}
9393

archinstall/lib/networking.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def enrich_iface_types(interfaces: list[str]) -> dict[str, str]:
121121
return result
122122

123123

124-
def fetch_data_from_url(url: str, params: dict[str, str] | None = None, timeout: int = 30) -> str:
124+
def fetch_data_from_url(url: str, params: dict[str, str] | None = None, timeout: int = 30) -> bytes:
125125
ssl_context = ssl.create_default_context()
126126
ssl_context.check_hostname = False
127127
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:
134134

135135
try:
136136
response = urlopen(full_url, context=ssl_context, timeout=timeout)
137-
data = response.read().decode('UTF-8')
138-
return data
137+
return response.read()
139138
except URLError as e:
140139
raise ValueError(f'Unable to fetch data from url: {url}\n{e}')
141140
except Exception as e:

archinstall/lib/profile/profiles_handler.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -262,10 +262,8 @@ def _import_profile_from_url(self, url: str) -> None:
262262
err = tr('Unable to fetch profile from specified url: {}').format(url)
263263
error(err)
264264
else:
265-
b_data = bytes(data, 'utf-8')
266-
267265
with NamedTemporaryFile(delete=False, suffix='.py') as fp:
268-
fp.write(b_data)
266+
fp.write(data)
269267
filepath = Path(fp.name)
270268

271269
profiles = self._process_profile_file(filepath)

0 commit comments

Comments
 (0)