E5Network/E5NetworkProxyFactory.py

Fri, 01 Nov 2013 15:48:48 +0100

author
T.Rzepka <Tobias.Rzepka@gmail.com>
date
Fri, 01 Nov 2013 15:48:48 +0100
branch
Py2 comp.
changeset 3058
0a02c433f52d
parent 3057
10516539f238
parent 3022
57179e4cdadd
child 3145
a9de05d4a22f
permissions
-rw-r--r--

Merge with default branch after fixed indentation issues.

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

eric ide

mercurial