WebBrowser/Network/NetworkManager.py

branch
QtWebEngine
changeset 4743
f9e2e536d130
parent 4726
c26e2a2dc0cb
child 4745
285bfd224a1b
equal deleted inserted replaced
4742:f9d1090f6ab9 4743:f9e2e536d130
7 Module implementing a network manager class. 7 Module implementing a network manager class.
8 """ 8 """
9 9
10 from __future__ import unicode_literals 10 from __future__ import unicode_literals
11 11
12 from PyQt5.QtNetwork import QNetworkAccessManager 12 from PyQt5.QtWidgets import QDialog
13 from PyQt5.QtNetwork import QNetworkAccessManager, QNetworkProxy
13 14
14 from E5Gui import E5MessageBox 15 from E5Gui import E5MessageBox
16
17 from E5Network.E5NetworkProxyFactory import proxyAuthenticationRequired
18
19 import Preferences
15 20
16 21
17 class NetworkManager(QNetworkAccessManager): 22 class NetworkManager(QNetworkAccessManager):
18 """ 23 """
19 Class implementing a network manager. 24 Class implementing a network manager.
27 super(NetworkManager, self).__init__(parent) 32 super(NetworkManager, self).__init__(parent)
28 33
29 self.__ignoredSslErrors = {} 34 self.__ignoredSslErrors = {}
30 # dictionary of temporarily ignore SSL errors 35 # dictionary of temporarily ignore SSL errors
31 36
32 # TODO: Proxy Authentication 37 self.proxyAuthenticationRequired.connect(
33 ## self.proxyAuthenticationRequired.connect(proxyAuthenticationRequired) 38 lambda proxy, auth: self.proxyAuthentication(
34 # TODO: Authentication 39 proxy.hostName(), auth))
35 ## self.authenticationRequired.connect(self.authenticationRequired) 40 self.authenticationRequired.connect(
41 lambda reply, auth: self.authentication(reply.url(), auth))
36 42
37 def certificateError(self, error, view): 43 def certificateError(self, error, view):
38 """ 44 """
39 Public method to handle SSL certificate errors. 45 Public method to handle SSL certificate errors.
40 46
66 if accept: 72 if accept:
67 self.__ignoredSslErrors[error.url().host()] = error.error() 73 self.__ignoredSslErrors[error.url().host()] = error.error()
68 return True 74 return True
69 75
70 return False 76 return False
77
78 def authentication(self, url, auth):
79 """
80 Public slot to handle an authentication request.
81
82 @param url URL requesting authentication (QUrl)
83 @param auth reference to the authenticator object (QAuthenticator)
84 """
85 urlRoot = "{0}://{1}"\
86 .format(url.scheme(), url.authority())
87 realm = auth.realm()
88 if not realm and 'realm' in auth.options():
89 realm = auth.option("realm")
90 if realm:
91 info = self.tr("<b>Enter username and password for '{0}', "
92 "realm '{1}'</b>").format(urlRoot, realm)
93 else:
94 info = self.tr("<b>Enter username and password for '{0}'</b>")\
95 .format(urlRoot)
96
97 from UI.AuthenticationDialog import AuthenticationDialog
98 # TODO: Password Manager
99 ## import WebBrowser.WebBrowserWindow
100
101 dlg = AuthenticationDialog(info, auth.user(),
102 Preferences.getUser("SavePasswords"),
103 Preferences.getUser("SavePasswords"))
104 # TODO: Password Manager
105 ## if Preferences.getUser("SavePasswords"):
106 ## username, password = \
107 ## WebBrowser.WebBrowserWindow.WebBrowserWindow.passwordManager()\
108 ## .getLogin(url, realm)
109 ## if username:
110 ## dlg.setData(username, password)
111 if dlg.exec_() == QDialog.Accepted:
112 username, password = dlg.getData()
113 auth.setUser(username)
114 auth.setPassword(password)
115 # TODO: Password Manager
116 ## if Preferences.getUser("SavePasswords"):
117 ## WebBrowser.WebBrowserWindow.WebBrowserWindow.passwordManager()\
118 ## .setLogin(url, realm, username, password)
119
120 def proxyAuthentication(self, hostname, auth):
121 """
122 Public slot to handle a proxy authentication request.
123
124 @param hostname name of the proxy host
125 @type str
126 @param auth reference to the authenticator object
127 @type QAuthenticator
128 """
129 proxy = QNetworkProxy.applicationProxy()
130 if proxy.user() and proxy.password():
131 auth.setUser(proxy.user())
132 auth.setPassword(proxy.password())
133 return
134
135 proxyAuthenticationRequired(proxy, auth)

eric ide

mercurial