E5Network/E5NetworkProxyFactory.py

Mon, 25 Mar 2013 03:11:06 +0100

author
T.Rzepka <Tobias.Rzepka@gmail.com>
date
Mon, 25 Mar 2013 03:11:06 +0100
branch
Py2 comp.
changeset 2525
8b507a9a2d40
parent 2401
4f428de32b69
child 3057
10516539f238
permissions
-rw-r--r--

Script changes: Future import added, super calls modified and unicode behavior for str.

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
2525
8b507a9a2d40 Script changes: Future import added, super calls modified and unicode behavior for str.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2401
diff changeset
10 from __future__ import unicode_literals # __IGNORE_WARNING__
8b507a9a2d40 Script changes: Future import added, super calls modified and unicode behavior for str.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2401
diff changeset
11
286
652f5159f1c3 Prepared to have individual proxies per scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 283
diff changeset
12 import os
652f5159f1c3 Prepared to have individual proxies per scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 283
diff changeset
13
2080
4b33165dd55b Made the third set of Qt5 compatibility changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1936
diff changeset
14 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
15 from PyQt4.QtGui import QDialog
286
652f5159f1c3 Prepared to have individual proxies per scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 283
diff changeset
16 from PyQt4.QtNetwork import QNetworkProxyFactory, QNetworkProxy, QNetworkProxyQuery
652f5159f1c3 Prepared to have individual proxies per scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 283
diff changeset
17
537
72b32daeb8d6 Continued replacing QMessageBox methods with own methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 319
diff changeset
18 from E5Gui import E5MessageBox
72b32daeb8d6 Continued replacing QMessageBox methods with own methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 319
diff changeset
19
286
652f5159f1c3 Prepared to have individual proxies per scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 283
diff changeset
20 import Preferences
882
34b86be88bf0 Redid the native file dialog code to be future proof.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
21 import Globals
2080
4b33165dd55b Made the third set of Qt5 compatibility changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1936
diff changeset
22 import Utilities
286
652f5159f1c3 Prepared to have individual proxies per scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 283
diff changeset
23
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 882
diff changeset
24
289
baf4c1354c6a Extended the proxy handling to HTTPS and FTP.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 286
diff changeset
25 def schemeFromProxyType(proxyType):
baf4c1354c6a Extended the proxy handling to HTTPS and FTP.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 286
diff changeset
26 """
baf4c1354c6a Extended the proxy handling to HTTPS and FTP.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 286
diff changeset
27 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
28
baf4c1354c6a Extended the proxy handling to HTTPS and FTP.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 286
diff changeset
29 @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
30 @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
31 """
baf4c1354c6a Extended the proxy handling to HTTPS and FTP.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 286
diff changeset
32 scheme = ""
baf4c1354c6a Extended the proxy handling to HTTPS and FTP.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 286
diff changeset
33 if proxyType == QNetworkProxy.HttpProxy:
baf4c1354c6a Extended the proxy handling to HTTPS and FTP.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 286
diff changeset
34 scheme = "Http"
baf4c1354c6a Extended the proxy handling to HTTPS and FTP.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 286
diff changeset
35 elif proxyType == QNetworkProxy.HttpCachingProxy:
baf4c1354c6a Extended the proxy handling to HTTPS and FTP.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 286
diff changeset
36 scheme = "Https"
baf4c1354c6a Extended the proxy handling to HTTPS and FTP.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 286
diff changeset
37 elif proxyType == QNetworkProxy.FtpCachingProxy:
baf4c1354c6a Extended the proxy handling to HTTPS and FTP.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 286
diff changeset
38 scheme = "Ftp"
baf4c1354c6a Extended the proxy handling to HTTPS and FTP.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 286
diff changeset
39 elif proxyType == QNetworkProxy.NoProxy:
baf4c1354c6a Extended the proxy handling to HTTPS and FTP.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 286
diff changeset
40 scheme = "NoProxy"
baf4c1354c6a Extended the proxy handling to HTTPS and FTP.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 286
diff changeset
41 return scheme
baf4c1354c6a Extended the proxy handling to HTTPS and FTP.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 286
diff changeset
42
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 882
diff changeset
43
289
baf4c1354c6a Extended the proxy handling to HTTPS and FTP.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 286
diff changeset
44 def proxyAuthenticationRequired(proxy, auth):
baf4c1354c6a Extended the proxy handling to HTTPS and FTP.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 286
diff changeset
45 """
baf4c1354c6a Extended the proxy handling to HTTPS and FTP.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 286
diff changeset
46 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
47
baf4c1354c6a Extended the proxy handling to HTTPS and FTP.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 286
diff changeset
48 @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
49 @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
50 """
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 882
diff changeset
51 info = QCoreApplication.translate("E5NetworkProxyFactory",
289
baf4c1354c6a Extended the proxy handling to HTTPS and FTP.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 286
diff changeset
52 "<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
53 .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
54
2401
4f428de32b69 Continued implementing the delayed import.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
55 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
56 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
57 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
58 if dlg.exec_() == QDialog.Accepted:
baf4c1354c6a Extended the proxy handling to HTTPS and FTP.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 286
diff changeset
59 username, password = dlg.getData()
baf4c1354c6a Extended the proxy handling to HTTPS and FTP.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 286
diff changeset
60 auth.setUser(username)
baf4c1354c6a Extended the proxy handling to HTTPS and FTP.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 286
diff changeset
61 auth.setPassword(password)
baf4c1354c6a Extended the proxy handling to HTTPS and FTP.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 286
diff changeset
62 if dlg.shallSave():
baf4c1354c6a Extended the proxy handling to HTTPS and FTP.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 286
diff changeset
63 scheme = schemeFromProxyType(proxy.type())
baf4c1354c6a Extended the proxy handling to HTTPS and FTP.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 286
diff changeset
64 if scheme and scheme != "NoProxy":
baf4c1354c6a Extended the proxy handling to HTTPS and FTP.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 286
diff changeset
65 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
66 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
67 proxy.setUser(username)
536b88d73d53 Little enhancement to the network proxy factory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1932
diff changeset
68 proxy.setPassword(password)
289
baf4c1354c6a Extended the proxy handling to HTTPS and FTP.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 286
diff changeset
69
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 882
diff changeset
70
286
652f5159f1c3 Prepared to have individual proxies per scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 283
diff changeset
71 class E5NetworkProxyFactory(QNetworkProxyFactory):
652f5159f1c3 Prepared to have individual proxies per scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 283
diff changeset
72 """
652f5159f1c3 Prepared to have individual proxies per scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 283
diff changeset
73 Class implementing a network proxy factory.
652f5159f1c3 Prepared to have individual proxies per scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 283
diff changeset
74 """
652f5159f1c3 Prepared to have individual proxies per scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 283
diff changeset
75 def __init__(self):
652f5159f1c3 Prepared to have individual proxies per scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 283
diff changeset
76 """
652f5159f1c3 Prepared to have individual proxies per scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 283
diff changeset
77 Constructor
652f5159f1c3 Prepared to have individual proxies per scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 283
diff changeset
78 """
2525
8b507a9a2d40 Script changes: Future import added, super calls modified and unicode behavior for str.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2401
diff changeset
79 super(E5NetworkProxyFactory, self).__init__()
286
652f5159f1c3 Prepared to have individual proxies per scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 283
diff changeset
80
652f5159f1c3 Prepared to have individual proxies per scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 283
diff changeset
81 def queryProxy(self, query):
652f5159f1c3 Prepared to have individual proxies per scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 283
diff changeset
82 """
652f5159f1c3 Prepared to have individual proxies per scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 283
diff changeset
83 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
84
652f5159f1c3 Prepared to have individual proxies per scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 283
diff changeset
85 @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
86 @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
87 """
652f5159f1c3 Prepared to have individual proxies per scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 283
diff changeset
88 if query.queryType() == QNetworkProxyQuery.UrlRequest and \
652f5159f1c3 Prepared to have individual proxies per scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 283
diff changeset
89 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
90 Preferences.getUI("UseProxy"):
652f5159f1c3 Prepared to have individual proxies per scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 283
diff changeset
91 if Preferences.getUI("UseSystemProxy"):
652f5159f1c3 Prepared to have individual proxies per scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 283
diff changeset
92 proxyList = QNetworkProxyFactory.systemProxyForQuery(query)
1363
d650915a903c Some changes for Mac computers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
93 if not Globals.isWindowsPlatform() and \
286
652f5159f1c3 Prepared to have individual proxies per scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 283
diff changeset
94 len(proxyList) == 1 and \
652f5159f1c3 Prepared to have individual proxies per scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 283
diff changeset
95 proxyList[0].type() == QNetworkProxy.NoProxy:
652f5159f1c3 Prepared to have individual proxies per scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 283
diff changeset
96 # try it the Python way
652f5159f1c3 Prepared to have individual proxies per scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 283
diff changeset
97 # 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
98 # 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
99 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
100 name = name.lower()
652f5159f1c3 Prepared to have individual proxies per scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 283
diff changeset
101 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
102 name[:-6] == query.protocolTag().lower():
652f5159f1c3 Prepared to have individual proxies per scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 283
diff changeset
103 url = QUrl(value)
289
baf4c1354c6a Extended the proxy handling to HTTPS and FTP.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 286
diff changeset
104 if url.scheme() == "http":
286
652f5159f1c3 Prepared to have individual proxies per scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 283
diff changeset
105 proxyType = QNetworkProxy.HttpProxy
289
baf4c1354c6a Extended the proxy handling to HTTPS and FTP.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 286
diff changeset
106 elif url.scheme() == "https":
baf4c1354c6a Extended the proxy handling to HTTPS and FTP.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 286
diff changeset
107 proxyType = QNetworkProxy.HttpCachingProxy
baf4c1354c6a Extended the proxy handling to HTTPS and FTP.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 286
diff changeset
108 elif url.scheme() == "ftp":
baf4c1354c6a Extended the proxy handling to HTTPS and FTP.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 286
diff changeset
109 proxyType = QNetworkProxy.FtpCachingProxy
286
652f5159f1c3 Prepared to have individual proxies per scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 283
diff changeset
110 else:
289
baf4c1354c6a Extended the proxy handling to HTTPS and FTP.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 286
diff changeset
111 proxyType = QNetworkProxy.HttpProxy
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 882
diff changeset
112 proxy = QNetworkProxy(proxyType, url.host(), url.port(),
286
652f5159f1c3 Prepared to have individual proxies per scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 283
diff changeset
113 url.userName(), url.password())
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(
f6b0163a21be Fixed an issue in the network proxy factory class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 289
diff changeset
124 Preferences.getUI("ProxyPassword/{0}".format(scheme)))
319
09f456ec6fcf Fixed a few issues in the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 317
diff changeset
125 return proxyList
09f456ec6fcf Fixed a few issues in the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 317
diff changeset
126 else:
09f456ec6fcf Fixed a few issues in the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 317
diff changeset
127 return [QNetworkProxy(QNetworkProxy.NoProxy)]
286
652f5159f1c3 Prepared to have individual proxies per scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 283
diff changeset
128 else:
289
baf4c1354c6a Extended the proxy handling to HTTPS and FTP.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 286
diff changeset
129 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
130 protocolKey = "Http"
289
baf4c1354c6a Extended the proxy handling to HTTPS and FTP.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 286
diff changeset
131 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
132 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
133 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
134 if not host:
537
72b32daeb8d6 Continued replacing QMessageBox methods with own methods.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 319
diff changeset
135 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
136 QCoreApplication.translate("E5NetworkProxyFactory",
289
baf4c1354c6a Extended the proxy handling to HTTPS and FTP.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 286
diff changeset
137 "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
138 QCoreApplication.translate("E5NetworkProxyFactory",
289
baf4c1354c6a Extended the proxy handling to HTTPS and FTP.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 286
diff changeset
139 """Proxy usage was activated"""
baf4c1354c6a Extended the proxy handling to HTTPS and FTP.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 286
diff changeset
140 """ 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
141 """ '{0}' configured.""").format(protocolKey))
286
652f5159f1c3 Prepared to have individual proxies per scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 283
diff changeset
142 return [QNetworkProxy(QNetworkProxy.DefaultProxy)]
652f5159f1c3 Prepared to have individual proxies per scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 283
diff changeset
143 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
144 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
145 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
146 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
147 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
148 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
149 else:
fa1c0fa31041 Fixed an issue in the web browser related to selecting the correct proxy type.
detlev@die-offenbachs.de
parents: 945
diff changeset
150 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
151 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
152 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
153 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
154 Preferences.getUI("ProxyPassword/" + protocolKey))
289
baf4c1354c6a Extended the proxy handling to HTTPS and FTP.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 286
diff changeset
155 else:
baf4c1354c6a Extended the proxy handling to HTTPS and FTP.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 286
diff changeset
156 proxy = QNetworkProxy(QNetworkProxy.DefaultProxy)
286
652f5159f1c3 Prepared to have individual proxies per scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 283
diff changeset
157 return [proxy, QNetworkProxy(QNetworkProxy.DefaultProxy)]
652f5159f1c3 Prepared to have individual proxies per scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 283
diff changeset
158 else:
652f5159f1c3 Prepared to have individual proxies per scheme.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 283
diff changeset
159 return [QNetworkProxy(QNetworkProxy.NoProxy)]

eric ide

mercurial