mirror of
https://github.com/miurahr/aqtinstall.git
synced 2025-12-18 13:14:37 +03:00
Check blacklist when downloading Update.xml
Signed-off-by: Hiroshi Miura <miurahr@linux.com>
This commit is contained in:
@@ -24,8 +24,10 @@ import xml.etree.ElementTree as ElementTree
|
|||||||
from logging import getLogger
|
from logging import getLogger
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
|
from requests.adapters import HTTPAdapter
|
||||||
|
from urllib3 import Retry
|
||||||
|
|
||||||
from aqt.helper import Settings
|
from aqt.helper import Settings, altlink
|
||||||
|
|
||||||
|
|
||||||
class ArchiveConnectionError(Exception):
|
class ArchiveConnectionError(Exception):
|
||||||
@@ -215,25 +217,34 @@ class QtArchives:
|
|||||||
self._parse_update_xml(archive_url, target_packages)
|
self._parse_update_xml(archive_url, target_packages)
|
||||||
|
|
||||||
def _download_update_xml(self, update_xml_url):
|
def _download_update_xml(self, update_xml_url):
|
||||||
try:
|
with requests.Session() as session:
|
||||||
r = requests.get(update_xml_url, timeout=self.timeout)
|
retry = Retry(connect=5, backoff_factor=0.5)
|
||||||
except (
|
adapter = HTTPAdapter(max_retries=retry)
|
||||||
ConnectionResetError,
|
session.mount("http://", adapter)
|
||||||
requests.exceptions.ConnectionError,
|
session.mount("https://", adapter)
|
||||||
requests.exceptions.Timeout,
|
try:
|
||||||
):
|
r = requests.get(update_xml_url, allow_redirects=False, timeout=self.timeout)
|
||||||
raise ArchiveConnectionError()
|
if r.status_code == 302:
|
||||||
else:
|
newurl = altlink(r.url, r.headers["Location"], logger=self.logger)
|
||||||
if r.status_code == 200:
|
self.logger.info("Redirected URL: {}".format(newurl))
|
||||||
self.update_xml_text = r.text
|
r = session.get(newurl, stream=True, timeout=self.timeout)
|
||||||
|
except (
|
||||||
|
ConnectionResetError,
|
||||||
|
requests.exceptions.ConnectionError,
|
||||||
|
requests.exceptions.Timeout,
|
||||||
|
):
|
||||||
|
raise ArchiveConnectionError()
|
||||||
else:
|
else:
|
||||||
self.logger.error(
|
if r.status_code == 200:
|
||||||
"Download error when access to {}\n"
|
self.update_xml_text = r.text
|
||||||
"Server response code: {}, reason: {}".format(
|
else:
|
||||||
update_xml_url, r.status_code, r.reason
|
self.logger.error(
|
||||||
|
"Download error when access to {}\n"
|
||||||
|
"Server response code: {}, reason: {}".format(
|
||||||
|
update_xml_url, r.status_code, r.reason
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
raise ArchiveDownloadError("Download error!")
|
||||||
raise ArchiveDownloadError("Download error!")
|
|
||||||
|
|
||||||
def _parse_update_xml(self, archive_url, target_packages):
|
def _parse_update_xml(self, archive_url, target_packages):
|
||||||
try:
|
try:
|
||||||
|
|||||||
Reference in New Issue
Block a user