src/eric7/WebBrowser/Network/NetworkManager.py

branch
eric7
changeset 9482
a2bc06a54d9d
parent 9473
3f23dbf37dbe
child 9653
e67609152c5e
equal deleted inserted replaced
9481:0b936ff1bbb9 9482:a2bc06a54d9d
18 QNetworkRequest, 18 QNetworkRequest,
19 ) 19 )
20 from PyQt6.QtWidgets import QDialog, QStyle 20 from PyQt6.QtWidgets import QDialog, QStyle
21 21
22 from eric7 import Preferences 22 from eric7 import Preferences
23 from eric7.EricNetwork.EricNetworkProxyFactory import proxyAuthenticationRequired 23 from eric7.EricNetwork.EricNetworkProxyFactory import (
24 EricNetworkProxyFactory,
25 proxyAuthenticationRequired,
26 )
24 from eric7.EricWidgets import EricMessageBox 27 from eric7.EricWidgets import EricMessageBox
25 from eric7.EricWidgets.EricApplication import ericApp 28 from eric7.EricWidgets.EricApplication import ericApp
29 from eric7.UI.AuthenticationDialog import AuthenticationDialog
26 from eric7.Utilities.AutoSaver import AutoSaver 30 from eric7.Utilities.AutoSaver import AutoSaver
27 from eric7.WebBrowser.WebBrowserWindow import WebBrowserWindow 31 from eric7.WebBrowser.WebBrowserWindow import WebBrowserWindow
28 32
29 try: 33 try:
30 from eric7.EricNetwork.EricSslErrorHandler import EricSslErrorHandler 34 from eric7.EricNetwork.EricSslErrorHandler import EricSslErrorHandler
32 SSL_AVAILABLE = True 36 SSL_AVAILABLE = True
33 except ImportError: 37 except ImportError:
34 SSL_AVAILABLE = False 38 SSL_AVAILABLE = False
35 39
36 from ..Tools.WebBrowserTools import getHtmlPage, pixmapToDataUrl 40 from ..Tools.WebBrowserTools import getHtmlPage, pixmapToDataUrl
41 from .EricSchemeHandler import EricSchemeHandler
37 from .NetworkUrlInterceptor import NetworkUrlInterceptor 42 from .NetworkUrlInterceptor import NetworkUrlInterceptor
38 43
39 44
40 class NetworkManager(QNetworkAccessManager): 45 class NetworkManager(QNetworkAccessManager):
41 """ 46 """
52 57
53 @param engine reference to the help engine (QHelpEngine) 58 @param engine reference to the help engine (QHelpEngine)
54 @param parent reference to the parent object (QObject) 59 @param parent reference to the parent object (QObject)
55 """ 60 """
56 super().__init__(parent) 61 super().__init__(parent)
57
58 from eric7.EricNetwork.EricNetworkProxyFactory import EricNetworkProxyFactory
59 62
60 self.__proxyFactory = EricNetworkProxyFactory() 63 self.__proxyFactory = EricNetworkProxyFactory()
61 if Preferences.getUI("UseSystemProxy"): 64 if Preferences.getUI("UseSystemProxy"):
62 QNetworkProxyFactory.setUseSystemConfiguration(True) 65 QNetworkProxyFactory.setUseSystemConfiguration(True)
63 else: 66 else:
83 self.proxyAuthenticationRequired.connect(proxyAuthenticationRequired) 86 self.proxyAuthenticationRequired.connect(proxyAuthenticationRequired)
84 self.authenticationRequired.connect( 87 self.authenticationRequired.connect(
85 lambda reply, auth: self.authentication(reply.url(), auth) 88 lambda reply, auth: self.authentication(reply.url(), auth)
86 ) 89 )
87 90
88 from .EricSchemeHandler import EricSchemeHandler
89
90 self.__ericSchemeHandler = EricSchemeHandler() 91 self.__ericSchemeHandler = EricSchemeHandler()
91 WebBrowserWindow.webProfile().installUrlSchemeHandler( 92 WebBrowserWindow.webProfile().installUrlSchemeHandler(
92 QByteArray(b"eric"), self.__ericSchemeHandler 93 QByteArray(b"eric"), self.__ericSchemeHandler
93 ) 94 )
94 95
95 if engine: 96 if engine:
96 from .QtHelpSchemeHandler import QtHelpSchemeHandler 97 from .QtHelpSchemeHandler import ( # __IGNORE_WARNING_I101__
98 QtHelpSchemeHandler,
99 )
97 100
98 self.__qtHelpSchemeHandler = QtHelpSchemeHandler(engine) 101 self.__qtHelpSchemeHandler = QtHelpSchemeHandler(engine)
99 WebBrowserWindow.webProfile().installUrlSchemeHandler( 102 WebBrowserWindow.webProfile().installUrlSchemeHandler(
100 QByteArray(b"qthelp"), self.__qtHelpSchemeHandler 103 QByteArray(b"qthelp"), self.__qtHelpSchemeHandler
101 ) 104 )
109 """ 112 """
110 Private slot to save the permanent SSL error exceptions. 113 Private slot to save the permanent SSL error exceptions.
111 """ 114 """
112 if not self.__loaded: 115 if not self.__loaded:
113 return 116 return
114
115 from eric7.WebBrowser.WebBrowserWindow import WebBrowserWindow
116 117
117 if not WebBrowserWindow.isPrivate(): 118 if not WebBrowserWindow.isPrivate():
118 dbString = json.dumps(self.__permanentlyIgnoredSslErrors) 119 dbString = json.dumps(self.__permanentlyIgnoredSslErrors)
119 Preferences.setWebBrowser("SslExceptionsDB", dbString) 120 Preferences.setWebBrowser("SslExceptionsDB", dbString)
120 121
143 self.__permanentlyIgnoredSslErrors = {} 144 self.__permanentlyIgnoredSslErrors = {}
144 145
145 # set proxy factory to None to avoid crashes 146 # set proxy factory to None to avoid crashes
146 QNetworkProxyFactory.setApplicationProxyFactory(None) 147 QNetworkProxyFactory.setApplicationProxyFactory(None)
147 148
148 def showSslErrorExceptionsDialog(self): 149 def showSslErrorExceptionsDialog(self, parent=None):
149 """ 150 """
150 Public method to show the SSL error exceptions dialog. 151 Public method to show the SSL error exceptions dialog.
151 """ 152
153 @param parent reference to the parent widget
154 @type QWidget
155 """
156 from .SslErrorExceptionsDialog import SslErrorExceptionsDialog
157
152 self.__load() 158 self.__load()
153 159
154 from .SslErrorExceptionsDialog import SslErrorExceptionsDialog 160 dlg = SslErrorExceptionsDialog(
155 161 self.__permanentlyIgnoredSslErrors,
156 dlg = SslErrorExceptionsDialog(self.__permanentlyIgnoredSslErrors) 162 parent=parent,
163 )
157 if dlg.exec() == QDialog.DialogCode.Accepted: 164 if dlg.exec() == QDialog.DialogCode.Accepted:
158 self.__permanentlyIgnoredSslErrors = dlg.getSslErrorExceptions() 165 self.__permanentlyIgnoredSslErrors = dlg.getSslErrorExceptions()
159 self.changed.emit() 166 self.changed.emit()
160 167
161 def clearSslExceptions(self): 168 def clearSslExceptions(self):
290 urlRoot, realm 297 urlRoot, realm
291 ) 298 )
292 if realm 299 if realm
293 else self.tr("<b>Enter username and password for '{0}'</b>").format(urlRoot) 300 else self.tr("<b>Enter username and password for '{0}'</b>").format(urlRoot)
294 ) 301 )
295
296 from eric7.UI.AuthenticationDialog import AuthenticationDialog
297 from eric7.WebBrowser.WebBrowserWindow import WebBrowserWindow
298 302
299 dlg = AuthenticationDialog( 303 dlg = AuthenticationDialog(
300 info, 304 info,
301 auth.user(), 305 auth.user(),
302 Preferences.getUser("SavePasswords"), 306 Preferences.getUser("SavePasswords"),

eric ide

mercurial