E5Network/E5NetworkProxyFactory.py

changeset 945
8cd4d08fa9f6
parent 882
34b86be88bf0
child 1058
fa1c0fa31041
equal deleted inserted replaced
944:1b59c4ba121e 945:8cd4d08fa9f6
18 from UI.AuthenticationDialog import AuthenticationDialog 18 from UI.AuthenticationDialog import AuthenticationDialog
19 19
20 import Preferences 20 import Preferences
21 import Globals 21 import Globals
22 22
23
23 def schemeFromProxyType(proxyType): 24 def schemeFromProxyType(proxyType):
24 """ 25 """
25 Module function to determine the scheme name from the proxy type. 26 Module function to determine the scheme name from the proxy type.
26 27
27 @param proxyType type of the proxy (QNetworkProxy.ProxyType) 28 @param proxyType type of the proxy (QNetworkProxy.ProxyType)
36 scheme = "Ftp" 37 scheme = "Ftp"
37 elif proxyType == QNetworkProxy.NoProxy: 38 elif proxyType == QNetworkProxy.NoProxy:
38 scheme = "NoProxy" 39 scheme = "NoProxy"
39 return scheme 40 return scheme
40 41
42
41 def proxyAuthenticationRequired(proxy, auth): 43 def proxyAuthenticationRequired(proxy, auth):
42 """ 44 """
43 Module slot to handle a proxy authentication request. 45 Module slot to handle a proxy authentication request.
44 46
45 @param proxy reference to the proxy object (QNetworkProxy) 47 @param proxy reference to the proxy object (QNetworkProxy)
46 @param auth reference to the authenticator object (QAuthenticator) 48 @param auth reference to the authenticator object (QAuthenticator)
47 """ 49 """
48 info = QCoreApplication.translate("E5NetworkProxyFactory", 50 info = QCoreApplication.translate("E5NetworkProxyFactory",
49 "<b>Connect to proxy '{0}' using:</b>")\ 51 "<b>Connect to proxy '{0}' using:</b>")\
50 .format(Qt.escape(proxy.hostName())) 52 .format(Qt.escape(proxy.hostName()))
51 53
52 dlg = AuthenticationDialog(info, proxy.user(), True) 54 dlg = AuthenticationDialog(info, proxy.user(), True)
53 if dlg.exec_() == QDialog.Accepted: 55 if dlg.exec_() == QDialog.Accepted:
59 if scheme and scheme != "NoProxy": 61 if scheme and scheme != "NoProxy":
60 Preferences.setUI("ProxyUser/{0}".format(scheme), username) 62 Preferences.setUI("ProxyUser/{0}".format(scheme), username)
61 Preferences.setUI("ProxyPassword/{0}".format(scheme), password) 63 Preferences.setUI("ProxyPassword/{0}".format(scheme), password)
62 proxy.setUser(username) 64 proxy.setUser(username)
63 proxy.setPassword(password) 65 proxy.setPassword(password)
66
64 67
65 class E5NetworkProxyFactory(QNetworkProxyFactory): 68 class E5NetworkProxyFactory(QNetworkProxyFactory):
66 """ 69 """
67 Class implementing a network proxy factory. 70 Class implementing a network proxy factory.
68 """ 71 """
102 proxyType = QNetworkProxy.HttpCachingProxy 105 proxyType = QNetworkProxy.HttpCachingProxy
103 elif url.scheme() == "ftp": 106 elif url.scheme() == "ftp":
104 proxyType = QNetworkProxy.FtpCachingProxy 107 proxyType = QNetworkProxy.FtpCachingProxy
105 else: 108 else:
106 proxyType = QNetworkProxy.HttpProxy 109 proxyType = QNetworkProxy.HttpProxy
107 proxy = QNetworkProxy(proxyType, url.host(), url.port(), 110 proxy = QNetworkProxy(proxyType, url.host(), url.port(),
108 url.userName(), url.password()) 111 url.userName(), url.password())
109 proxyList = [proxy] 112 proxyList = [proxy]
110 break 113 break
111 if proxyList: 114 if proxyList:
112 scheme = schemeFromProxyType(proxyList[0].type()) 115 scheme = schemeFromProxyType(proxyList[0].type())
126 else: 129 else:
127 protocol = query.protocolTag().capitalize() 130 protocol = query.protocolTag().capitalize()
128 host = Preferences.getUI("ProxyHost/{0}".format(protocol)) 131 host = Preferences.getUI("ProxyHost/{0}".format(protocol))
129 if not host: 132 if not host:
130 E5MessageBox.critical(None, 133 E5MessageBox.critical(None,
131 QCoreApplication.translate("E5NetworkProxyFactory", 134 QCoreApplication.translate("E5NetworkProxyFactory",
132 "Proxy Configuration Error"), 135 "Proxy Configuration Error"),
133 QCoreApplication.translate("E5NetworkProxyFactory", 136 QCoreApplication.translate("E5NetworkProxyFactory",
134 """Proxy usage was activated""" 137 """Proxy usage was activated"""
135 """ but no proxy host for protocol""" 138 """ but no proxy host for protocol"""
136 """ '{0}' configured.""").format(protocol)) 139 """ '{0}' configured.""").format(protocol))
137 return [QNetworkProxy(QNetworkProxy.DefaultProxy)] 140 return [QNetworkProxy(QNetworkProxy.DefaultProxy)]
138 else: 141 else:
139 if protocol == "Http": 142 if protocol == "Http":
140 proxy = QNetworkProxy(QNetworkProxy.HttpProxy, host, 143 proxy = QNetworkProxy(QNetworkProxy.HttpProxy, host,
141 Preferences.getUI("ProxyPort/Http"), 144 Preferences.getUI("ProxyPort/Http"),
142 Preferences.getUI("ProxyUser/Http"), 145 Preferences.getUI("ProxyUser/Http"),
143 Preferences.getUI("ProxyPassword/Http")) 146 Preferences.getUI("ProxyPassword/Http"))
144 elif protocol == "Https": 147 elif protocol == "Https":
145 proxy = QNetworkProxy(QNetworkProxy.HttpCachingProxy, host, 148 proxy = QNetworkProxy(QNetworkProxy.HttpCachingProxy, host,
146 Preferences.getUI("ProxyPort/Https"), 149 Preferences.getUI("ProxyPort/Https"),
147 Preferences.getUI("ProxyUser/Https"), 150 Preferences.getUI("ProxyUser/Https"),
148 Preferences.getUI("ProxyPassword/Https")) 151 Preferences.getUI("ProxyPassword/Https"))
149 elif protocol == "Ftp": 152 elif protocol == "Ftp":
150 proxy = QNetworkProxy(QNetworkProxy.FtpCachingProxy, host, 153 proxy = QNetworkProxy(QNetworkProxy.FtpCachingProxy, host,
151 Preferences.getUI("ProxyPort/Ftp"), 154 Preferences.getUI("ProxyPort/Ftp"),
152 Preferences.getUI("ProxyUser/Ftp"), 155 Preferences.getUI("ProxyUser/Ftp"),
153 Preferences.getUI("ProxyPassword/Ftp")) 156 Preferences.getUI("ProxyPassword/Ftp"))
154 else: 157 else:
155 proxy = QNetworkProxy(QNetworkProxy.DefaultProxy) 158 proxy = QNetworkProxy(QNetworkProxy.DefaultProxy)

eric ide

mercurial