Addon Manager: Fix Qt6 redirect-following code
Also fixes data type problems with variable declarations in __init__
This commit is contained in:
@@ -201,8 +201,8 @@ class CommandAddonManager(QtCore.QObject):
|
||||
self.packages_with_updates = set()
|
||||
|
||||
self.macro_repo_dir = None
|
||||
self.number_of_progress_regions = None
|
||||
self.current_progress_region = None
|
||||
self.number_of_progress_regions = 0
|
||||
self.current_progress_region = 0
|
||||
|
||||
self.check_worker = None
|
||||
self.check_for_python_package_updates_worker = None
|
||||
@@ -214,8 +214,8 @@ class CommandAddonManager(QtCore.QObject):
|
||||
self.get_basic_addon_stats_worker = None
|
||||
self.load_macro_metadata_worker = None
|
||||
|
||||
self.macro_cache = None
|
||||
self.package_cache = None
|
||||
self.macro_cache = []
|
||||
self.package_cache = {}
|
||||
self.manage_python_packages_dialog = None
|
||||
|
||||
# Set up the connection checker
|
||||
|
||||
@@ -171,6 +171,7 @@ if HAVE_QTNETWORK:
|
||||
self.QNAM = QtNetwork.QNetworkAccessManager()
|
||||
self.QNAM.proxyAuthenticationRequired.connect(self.__authenticate_proxy)
|
||||
self.QNAM.authenticationRequired.connect(self.__authenticate_resource)
|
||||
self.QNAM.setRedirectPolicy(QtNetwork.QNetworkRequest.ManualRedirectPolicy)
|
||||
|
||||
qnam_cache = QtCore.QStandardPaths.writableLocation(QtCore.QStandardPaths.CacheLocation)
|
||||
os.makedirs(qnam_cache, exist_ok=True)
|
||||
@@ -325,7 +326,6 @@ if HAVE_QTNETWORK:
|
||||
|
||||
self.__last_started_index = index
|
||||
reply.finished.connect(self.__reply_finished)
|
||||
reply.redirected.connect(self.__follow_redirect)
|
||||
reply.sslErrors.connect(self.__on_ssl_error)
|
||||
if index in self.monitored_connections:
|
||||
reply.readyRead.connect(self.__ready_to_read)
|
||||
@@ -429,7 +429,7 @@ if HAVE_QTNETWORK:
|
||||
request = QtNetwork.QNetworkRequest(QtCore.QUrl(url))
|
||||
request.setAttribute(
|
||||
QtNetwork.QNetworkRequest.RedirectPolicyAttribute,
|
||||
QtNetwork.QNetworkRequest.UserVerifiedRedirectPolicy,
|
||||
QtNetwork.QNetworkRequest.ManualRedirectPolicy,
|
||||
)
|
||||
request.setAttribute(QtNetwork.QNetworkRequest.CacheSaveControlAttribute, True)
|
||||
request.setAttribute(
|
||||
@@ -505,21 +505,6 @@ if HAVE_QTNETWORK:
|
||||
):
|
||||
"""Unused."""
|
||||
|
||||
def __follow_redirect(self, url):
|
||||
"""Used with the QNetworkAccessManager to follow redirects."""
|
||||
sender = self.sender()
|
||||
current_index = -1
|
||||
timeout_ms = default_timeout
|
||||
# TODO: Figure out what the actual timeout value should be from the original request
|
||||
if sender:
|
||||
for index, reply in self.replies.items():
|
||||
if reply == sender:
|
||||
current_index = index
|
||||
break
|
||||
|
||||
if current_index != -1:
|
||||
self.__launch_request(current_index, self.__create_get_request(url, timeout_ms))
|
||||
|
||||
def __on_ssl_error(self, reply: str, errors: List[str] = None):
|
||||
"""Called when an SSL error occurs: prints the error information."""
|
||||
if HAVE_FREECAD:
|
||||
@@ -593,8 +578,15 @@ if HAVE_QTNETWORK:
|
||||
return
|
||||
|
||||
response_code = reply.attribute(QtNetwork.QNetworkRequest.HttpStatusCodeAttribute)
|
||||
if response_code == 301 or response_code == 302: # This is a redirect, bail out
|
||||
return
|
||||
redirect_codes = [301, 302, 303, 305, 307, 308]
|
||||
if response_code in redirect_codes: # This is a redirect
|
||||
timeout_ms = default_timeout
|
||||
if hasattr(reply, "request"):
|
||||
request = reply.request()
|
||||
timeout_ms = request.transferTimeout()
|
||||
new_url = reply.attribute(QtNetwork.QNetworkRequest.RedirectionTargetAttribute)
|
||||
self.__launch_request(index, self.__create_get_request(new_url, timeout_ms))
|
||||
return # The task is not done, so get out of this method now
|
||||
if reply.error() != QtNetwork.QNetworkReply.NetworkError.OperationCanceledError:
|
||||
# It this was not a timeout, make sure we mark the queue task done
|
||||
self.queue.task_done()
|
||||
|
||||
@@ -783,6 +783,7 @@ class CacheMacroCodeWorker(QtCore.QThread):
|
||||
"AddonsInstaller",
|
||||
"Out of {num_macros} macros, {num_failed} timed out while processing",
|
||||
).format(num_macros=num_macros, num_failed=num_failed)
|
||||
+ "\n"
|
||||
)
|
||||
|
||||
def _process_queue(self, num_macros) -> bool:
|
||||
|
||||
Reference in New Issue
Block a user