E5Network/E5NetworkProxyFactory.py

Sun, 06 Oct 2013 19:45:29 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sun, 06 Oct 2013 19:45:29 +0200
changeset 2990
583beaf0b4b8
parent 2401
4f428de32b69
child 3020
542e97d4ecb3
child 3057
10516539f238
permissions
-rw-r--r--

Continued to shorten the code lines to max. 79 characters.

286
652f5159f1c3 Prepared to have individual proxies per scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 283
diff changeset
1 # -*- coding: utf-8 -*-
652f5159f1c3 Prepared to have individual proxies per scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 283
diff changeset
2
2302
f29e9405c851 Updated copyright for 2013.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2080
diff changeset
3 # Copyright (c) 2010 - 2013 Detlev Offenbach <detlev@die-offenbachs.de>
286
652f5159f1c3 Prepared to have individual proxies per scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 283
diff changeset
4 #
652f5159f1c3 Prepared to have individual proxies per scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 283
diff changeset
5
652f5159f1c3 Prepared to have individual proxies per scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 283
diff changeset
6 """
652f5159f1c3 Prepared to have individual proxies per scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 283
diff changeset
7 Module implementing a network proxy factory.
652f5159f1c3 Prepared to have individual proxies per scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 283
diff changeset
8 """
652f5159f1c3 Prepared to have individual proxies per scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 283
diff changeset
9
652f5159f1c3 Prepared to have individual proxies per scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 283
diff changeset
10 import os
652f5159f1c3 Prepared to have individual proxies per scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 283
diff changeset
11
2080
4b33165dd55b Made the third set of Qt5 compatibility changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1936
diff changeset
12 from PyQt4.QtCore import QUrl, QCoreApplication
537
72b32daeb8d6 Continued replacing QMessageBox methods with own methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 319
diff changeset
13 from PyQt4.QtGui import QDialog
2990
583beaf0b4b8 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2401
diff changeset
14 from PyQt4.QtNetwork import QNetworkProxyFactory, QNetworkProxy, \
583beaf0b4b8 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2401
diff changeset
15 QNetworkProxyQuery
286
652f5159f1c3 Prepared to have individual proxies per scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 283
diff changeset
16
537
72b32daeb8d6 Continued replacing QMessageBox methods with own methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 319
diff changeset
17 from E5Gui import E5MessageBox
72b32daeb8d6 Continued replacing QMessageBox methods with own methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 319
diff changeset
18
286
652f5159f1c3 Prepared to have individual proxies per scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 283
diff changeset
19 import Preferences
882
34b86be88bf0 Redid the native file dialog code to be future proof.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
20 import Globals
2080
4b33165dd55b Made the third set of Qt5 compatibility changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1936
diff changeset
21 import Utilities
286
652f5159f1c3 Prepared to have individual proxies per scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 283
diff changeset
22
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 882
diff changeset
23
289
baf4c1354c6a Extended the proxy handling to HTTPS and FTP.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 286
diff changeset
24 def schemeFromProxyType(proxyType):
baf4c1354c6a Extended the proxy handling to HTTPS and FTP.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 286
diff changeset
25 """
baf4c1354c6a Extended the proxy handling to HTTPS and FTP.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 286
diff changeset
26 Module function to determine the scheme name from the proxy type.
baf4c1354c6a Extended the proxy handling to HTTPS and FTP.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 286
diff changeset
27
baf4c1354c6a Extended the proxy handling to HTTPS and FTP.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 286
diff changeset
28 @param proxyType type of the proxy (QNetworkProxy.ProxyType)
baf4c1354c6a Extended the proxy handling to HTTPS and FTP.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 286
diff changeset
29 @return scheme (string, one of Http, Https, Ftp)
baf4c1354c6a Extended the proxy handling to HTTPS and FTP.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 286
diff changeset
30 """
baf4c1354c6a Extended the proxy handling to HTTPS and FTP.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 286
diff changeset
31 scheme = ""
baf4c1354c6a Extended the proxy handling to HTTPS and FTP.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 286
diff changeset
32 if proxyType == QNetworkProxy.HttpProxy:
baf4c1354c6a Extended the proxy handling to HTTPS and FTP.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 286
diff changeset
33 scheme = "Http"
baf4c1354c6a Extended the proxy handling to HTTPS and FTP.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 286
diff changeset
34 elif proxyType == QNetworkProxy.HttpCachingProxy:
baf4c1354c6a Extended the proxy handling to HTTPS and FTP.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 286
diff changeset
35 scheme = "Https"
baf4c1354c6a Extended the proxy handling to HTTPS and FTP.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 286
diff changeset
36 elif proxyType == QNetworkProxy.FtpCachingProxy:
baf4c1354c6a Extended the proxy handling to HTTPS and FTP.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 286
diff changeset
37 scheme = "Ftp"
baf4c1354c6a Extended the proxy handling to HTTPS and FTP.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 286
diff changeset
38 elif proxyType == QNetworkProxy.NoProxy:
baf4c1354c6a Extended the proxy handling to HTTPS and FTP.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 286
diff changeset
39 scheme = "NoProxy"
baf4c1354c6a Extended the proxy handling to HTTPS and FTP.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 286
diff changeset
40 return scheme
baf4c1354c6a Extended the proxy handling to HTTPS and FTP.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 286
diff changeset
41
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 882
diff changeset
42
289
baf4c1354c6a Extended the proxy handling to HTTPS and FTP.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 286
diff changeset
43 def proxyAuthenticationRequired(proxy, auth):
baf4c1354c6a Extended the proxy handling to HTTPS and FTP.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 286
diff changeset
44 """
baf4c1354c6a Extended the proxy handling to HTTPS and FTP.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 286
diff changeset
45 Module slot to handle a proxy authentication request.
baf4c1354c6a Extended the proxy handling to HTTPS and FTP.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 286
diff changeset
46
baf4c1354c6a Extended the proxy handling to HTTPS and FTP.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 286
diff changeset
47 @param proxy reference to the proxy object (QNetworkProxy)
baf4c1354c6a Extended the proxy handling to HTTPS and FTP.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 286
diff changeset
48 @param auth reference to the authenticator object (QAuthenticator)
baf4c1354c6a Extended the proxy handling to HTTPS and FTP.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 286
diff changeset
49 """
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 882
diff changeset
50 info = QCoreApplication.translate("E5NetworkProxyFactory",
289
baf4c1354c6a Extended the proxy handling to HTTPS and FTP.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 286
diff changeset
51 "<b>Connect to proxy '{0}' using:</b>")\
2080
4b33165dd55b Made the third set of Qt5 compatibility changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1936
diff changeset
52 .format(Utilities.html_encode(proxy.hostName()))
289
baf4c1354c6a Extended the proxy handling to HTTPS and FTP.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 286
diff changeset
53
2401
4f428de32b69 Continued implementing the delayed import.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
54 from UI.AuthenticationDialog import AuthenticationDialog
289
baf4c1354c6a Extended the proxy handling to HTTPS and FTP.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 286
diff changeset
55 dlg = AuthenticationDialog(info, proxy.user(), True)
1936
536b88d73d53 Little enhancement to the network proxy factory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1932
diff changeset
56 dlg.setData(proxy.user(), proxy.password())
289
baf4c1354c6a Extended the proxy handling to HTTPS and FTP.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 286
diff changeset
57 if dlg.exec_() == QDialog.Accepted:
baf4c1354c6a Extended the proxy handling to HTTPS and FTP.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 286
diff changeset
58 username, password = dlg.getData()
baf4c1354c6a Extended the proxy handling to HTTPS and FTP.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 286
diff changeset
59 auth.setUser(username)
baf4c1354c6a Extended the proxy handling to HTTPS and FTP.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 286
diff changeset
60 auth.setPassword(password)
baf4c1354c6a Extended the proxy handling to HTTPS and FTP.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 286
diff changeset
61 if dlg.shallSave():
baf4c1354c6a Extended the proxy handling to HTTPS and FTP.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 286
diff changeset
62 scheme = schemeFromProxyType(proxy.type())
baf4c1354c6a Extended the proxy handling to HTTPS and FTP.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 286
diff changeset
63 if scheme and scheme != "NoProxy":
baf4c1354c6a Extended the proxy handling to HTTPS and FTP.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 286
diff changeset
64 Preferences.setUI("ProxyUser/{0}".format(scheme), username)
baf4c1354c6a Extended the proxy handling to HTTPS and FTP.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 286
diff changeset
65 Preferences.setUI("ProxyPassword/{0}".format(scheme), password)
1936
536b88d73d53 Little enhancement to the network proxy factory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1932
diff changeset
66 proxy.setUser(username)
536b88d73d53 Little enhancement to the network proxy factory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1932
diff changeset
67 proxy.setPassword(password)
289
baf4c1354c6a Extended the proxy handling to HTTPS and FTP.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 286
diff changeset
68
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 882
diff changeset
69
286
652f5159f1c3 Prepared to have individual proxies per scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 283
diff changeset
70 class E5NetworkProxyFactory(QNetworkProxyFactory):
652f5159f1c3 Prepared to have individual proxies per scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 283
diff changeset
71 """
652f5159f1c3 Prepared to have individual proxies per scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 283
diff changeset
72 Class implementing a network proxy factory.
652f5159f1c3 Prepared to have individual proxies per scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 283
diff changeset
73 """
652f5159f1c3 Prepared to have individual proxies per scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 283
diff changeset
74 def __init__(self):
652f5159f1c3 Prepared to have individual proxies per scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 283
diff changeset
75 """
652f5159f1c3 Prepared to have individual proxies per scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 283
diff changeset
76 Constructor
652f5159f1c3 Prepared to have individual proxies per scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 283
diff changeset
77 """
1131
7781e396c903 Changed the code to use super() to access the superclass.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1058
diff changeset
78 super().__init__()
286
652f5159f1c3 Prepared to have individual proxies per scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 283
diff changeset
79
652f5159f1c3 Prepared to have individual proxies per scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 283
diff changeset
80 def queryProxy(self, query):
652f5159f1c3 Prepared to have individual proxies per scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 283
diff changeset
81 """
652f5159f1c3 Prepared to have individual proxies per scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 283
diff changeset
82 Public method to determine a proxy for a given query.
652f5159f1c3 Prepared to have individual proxies per scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 283
diff changeset
83
652f5159f1c3 Prepared to have individual proxies per scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 283
diff changeset
84 @param query reference to the query object (QNetworkProxyQuery)
652f5159f1c3 Prepared to have individual proxies per scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 283
diff changeset
85 @return list of proxies in order of preference (list of QNetworkProxy)
652f5159f1c3 Prepared to have individual proxies per scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 283
diff changeset
86 """
652f5159f1c3 Prepared to have individual proxies per scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 283
diff changeset
87 if query.queryType() == QNetworkProxyQuery.UrlRequest and \
652f5159f1c3 Prepared to have individual proxies per scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 283
diff changeset
88 query.protocolTag() in ["http", "https", "ftp"] and \
652f5159f1c3 Prepared to have individual proxies per scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 283
diff changeset
89 Preferences.getUI("UseProxy"):
652f5159f1c3 Prepared to have individual proxies per scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 283
diff changeset
90 if Preferences.getUI("UseSystemProxy"):
652f5159f1c3 Prepared to have individual proxies per scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 283
diff changeset
91 proxyList = QNetworkProxyFactory.systemProxyForQuery(query)
1363
d650915a903c Some changes for Mac computers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
92 if not Globals.isWindowsPlatform() and \
286
652f5159f1c3 Prepared to have individual proxies per scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 283
diff changeset
93 len(proxyList) == 1 and \
652f5159f1c3 Prepared to have individual proxies per scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 283
diff changeset
94 proxyList[0].type() == QNetworkProxy.NoProxy:
652f5159f1c3 Prepared to have individual proxies per scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 283
diff changeset
95 # try it the Python way
652f5159f1c3 Prepared to have individual proxies per scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 283
diff changeset
96 # scan the environment for variables named <scheme>_proxy
652f5159f1c3 Prepared to have individual proxies per scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 283
diff changeset
97 # scan over whole environment to make this case insensitive
652f5159f1c3 Prepared to have individual proxies per scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 283
diff changeset
98 for name, value in os.environ.items():
652f5159f1c3 Prepared to have individual proxies per scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 283
diff changeset
99 name = name.lower()
652f5159f1c3 Prepared to have individual proxies per scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 283
diff changeset
100 if value and name[-6:] == '_proxy' and \
652f5159f1c3 Prepared to have individual proxies per scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 283
diff changeset
101 name[:-6] == query.protocolTag().lower():
652f5159f1c3 Prepared to have individual proxies per scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 283
diff changeset
102 url = QUrl(value)
289
baf4c1354c6a Extended the proxy handling to HTTPS and FTP.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 286
diff changeset
103 if url.scheme() == "http":
286
652f5159f1c3 Prepared to have individual proxies per scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 283
diff changeset
104 proxyType = QNetworkProxy.HttpProxy
289
baf4c1354c6a Extended the proxy handling to HTTPS and FTP.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 286
diff changeset
105 elif url.scheme() == "https":
baf4c1354c6a Extended the proxy handling to HTTPS and FTP.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 286
diff changeset
106 proxyType = QNetworkProxy.HttpCachingProxy
baf4c1354c6a Extended the proxy handling to HTTPS and FTP.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 286
diff changeset
107 elif url.scheme() == "ftp":
baf4c1354c6a Extended the proxy handling to HTTPS and FTP.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 286
diff changeset
108 proxyType = QNetworkProxy.FtpCachingProxy
286
652f5159f1c3 Prepared to have individual proxies per scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 283
diff changeset
109 else:
289
baf4c1354c6a Extended the proxy handling to HTTPS and FTP.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 286
diff changeset
110 proxyType = QNetworkProxy.HttpProxy
2990
583beaf0b4b8 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2401
diff changeset
111 proxy = QNetworkProxy(
583beaf0b4b8 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2401
diff changeset
112 proxyType, url.host(), url.port(),
583beaf0b4b8 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2401
diff changeset
113 url.userName(), url.password())
286
652f5159f1c3 Prepared to have individual proxies per scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 283
diff changeset
114 proxyList = [proxy]
652f5159f1c3 Prepared to have individual proxies per scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 283
diff changeset
115 break
317
f6b0163a21be Fixed an issue in the network proxy factory class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 289
diff changeset
116 if proxyList:
f6b0163a21be Fixed an issue in the network proxy factory class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 289
diff changeset
117 scheme = schemeFromProxyType(proxyList[0].type())
f6b0163a21be Fixed an issue in the network proxy factory class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 289
diff changeset
118 if scheme == "":
f6b0163a21be Fixed an issue in the network proxy factory class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 289
diff changeset
119 scheme = "Http"
f6b0163a21be Fixed an issue in the network proxy factory class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 289
diff changeset
120 if scheme != "NoProxy":
f6b0163a21be Fixed an issue in the network proxy factory class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 289
diff changeset
121 proxyList[0].setUser(
f6b0163a21be Fixed an issue in the network proxy factory class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 289
diff changeset
122 Preferences.getUI("ProxyUser/{0}".format(scheme)))
f6b0163a21be Fixed an issue in the network proxy factory class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 289
diff changeset
123 proxyList[0].setPassword(
2990
583beaf0b4b8 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2401
diff changeset
124 Preferences.getUI(
583beaf0b4b8 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2401
diff changeset
125 "ProxyPassword/{0}".format(scheme)))
319
09f456ec6fcf Fixed a few issues in the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 317
diff changeset
126 return proxyList
09f456ec6fcf Fixed a few issues in the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 317
diff changeset
127 else:
09f456ec6fcf Fixed a few issues in the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 317
diff changeset
128 return [QNetworkProxy(QNetworkProxy.NoProxy)]
286
652f5159f1c3 Prepared to have individual proxies per scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 283
diff changeset
129 else:
289
baf4c1354c6a Extended the proxy handling to HTTPS and FTP.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 286
diff changeset
130 if Preferences.getUI("UseHttpProxyForAll"):
1058
fa1c0fa31041 Fixed an issue in the web browser related to selecting the correct proxy type.
detlev@die-offenbachs.de
parents: 945
diff changeset
131 protocolKey = "Http"
289
baf4c1354c6a Extended the proxy handling to HTTPS and FTP.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 286
diff changeset
132 else:
1058
fa1c0fa31041 Fixed an issue in the web browser related to selecting the correct proxy type.
detlev@die-offenbachs.de
parents: 945
diff changeset
133 protocolKey = query.protocolTag().capitalize()
fa1c0fa31041 Fixed an issue in the web browser related to selecting the correct proxy type.
detlev@die-offenbachs.de
parents: 945
diff changeset
134 host = Preferences.getUI("ProxyHost/{0}".format(protocolKey))
286
652f5159f1c3 Prepared to have individual proxies per scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 283
diff changeset
135 if not host:
537
72b32daeb8d6 Continued replacing QMessageBox methods with own methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 319
diff changeset
136 E5MessageBox.critical(None,
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 882
diff changeset
137 QCoreApplication.translate("E5NetworkProxyFactory",
289
baf4c1354c6a Extended the proxy handling to HTTPS and FTP.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 286
diff changeset
138 "Proxy Configuration Error"),
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 882
diff changeset
139 QCoreApplication.translate("E5NetworkProxyFactory",
289
baf4c1354c6a Extended the proxy handling to HTTPS and FTP.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 286
diff changeset
140 """Proxy usage was activated"""
baf4c1354c6a Extended the proxy handling to HTTPS and FTP.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 286
diff changeset
141 """ but no proxy host for protocol"""
1058
fa1c0fa31041 Fixed an issue in the web browser related to selecting the correct proxy type.
detlev@die-offenbachs.de
parents: 945
diff changeset
142 """ '{0}' configured.""").format(protocolKey))
286
652f5159f1c3 Prepared to have individual proxies per scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 283
diff changeset
143 return [QNetworkProxy(QNetworkProxy.DefaultProxy)]
652f5159f1c3 Prepared to have individual proxies per scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 283
diff changeset
144 else:
1058
fa1c0fa31041 Fixed an issue in the web browser related to selecting the correct proxy type.
detlev@die-offenbachs.de
parents: 945
diff changeset
145 if protocolKey in ["Http", "Https", "Ftp"]:
fa1c0fa31041 Fixed an issue in the web browser related to selecting the correct proxy type.
detlev@die-offenbachs.de
parents: 945
diff changeset
146 if query.protocolTag() == "ftp":
fa1c0fa31041 Fixed an issue in the web browser related to selecting the correct proxy type.
detlev@die-offenbachs.de
parents: 945
diff changeset
147 proxyType = QNetworkProxy.FtpCachingProxy
fa1c0fa31041 Fixed an issue in the web browser related to selecting the correct proxy type.
detlev@die-offenbachs.de
parents: 945
diff changeset
148 elif query.protocolTag() == "https":
fa1c0fa31041 Fixed an issue in the web browser related to selecting the correct proxy type.
detlev@die-offenbachs.de
parents: 945
diff changeset
149 proxyType = QNetworkProxy.HttpCachingProxy
fa1c0fa31041 Fixed an issue in the web browser related to selecting the correct proxy type.
detlev@die-offenbachs.de
parents: 945
diff changeset
150 else:
fa1c0fa31041 Fixed an issue in the web browser related to selecting the correct proxy type.
detlev@die-offenbachs.de
parents: 945
diff changeset
151 proxyType = QNetworkProxy.HttpProxy
fa1c0fa31041 Fixed an issue in the web browser related to selecting the correct proxy type.
detlev@die-offenbachs.de
parents: 945
diff changeset
152 proxy = QNetworkProxy(proxyType, host,
fa1c0fa31041 Fixed an issue in the web browser related to selecting the correct proxy type.
detlev@die-offenbachs.de
parents: 945
diff changeset
153 Preferences.getUI("ProxyPort/" + protocolKey),
fa1c0fa31041 Fixed an issue in the web browser related to selecting the correct proxy type.
detlev@die-offenbachs.de
parents: 945
diff changeset
154 Preferences.getUI("ProxyUser/" + protocolKey),
fa1c0fa31041 Fixed an issue in the web browser related to selecting the correct proxy type.
detlev@die-offenbachs.de
parents: 945
diff changeset
155 Preferences.getUI("ProxyPassword/" + protocolKey))
289
baf4c1354c6a Extended the proxy handling to HTTPS and FTP.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 286
diff changeset
156 else:
baf4c1354c6a Extended the proxy handling to HTTPS and FTP.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 286
diff changeset
157 proxy = QNetworkProxy(QNetworkProxy.DefaultProxy)
286
652f5159f1c3 Prepared to have individual proxies per scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 283
diff changeset
158 return [proxy, QNetworkProxy(QNetworkProxy.DefaultProxy)]
652f5159f1c3 Prepared to have individual proxies per scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 283
diff changeset
159 else:
652f5159f1c3 Prepared to have individual proxies per scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 283
diff changeset
160 return [QNetworkProxy(QNetworkProxy.NoProxy)]

eric ide

mercurial