Sun, 18 May 2014 14:13:09 +0200
Corrected a bunch of source docu issues.
278
c93823b96faa
Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
1 | # -*- coding: utf-8 -*- |
c93823b96faa
Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
2 | |
3160
209a07d7e401
Updated copyright for 2014.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3002
diff
changeset
|
3 | # Copyright (c) 2010 - 2014 Detlev Offenbach <detlev@die-offenbachs.de> |
278
c93823b96faa
Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
4 | # |
c93823b96faa
Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
5 | |
c93823b96faa
Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
6 | """ |
c93823b96faa
Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
7 | Module implementing a scheme access handler for FTP. |
c93823b96faa
Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
8 | """ |
c93823b96faa
Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
9 | |
3145
a9de05d4a22f
# __IGNORE_WARNING__ added/ removed.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3057
diff
changeset
|
10 | from __future__ import unicode_literals |
2525
8b507a9a2d40
Script changes: Future import added, super calls modified and unicode behavior for str.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
2403
diff
changeset
|
11 | |
278
c93823b96faa
Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
12 | from PyQt4.QtNetwork import QNetworkAccessManager |
c93823b96faa
Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
13 | |
c93823b96faa
Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
14 | from .SchemeAccessHandler import SchemeAccessHandler |
c93823b96faa
Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
15 | |
945
8cd4d08fa9f6
Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
791
diff
changeset
|
16 | |
278
c93823b96faa
Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
17 | class FtpAccessHandler(SchemeAccessHandler): |
c93823b96faa
Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
18 | """ |
c93823b96faa
Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
19 | Class implementing a scheme access handler for FTP. |
c93823b96faa
Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
20 | """ |
2050
585f6646bf50
Changed the FtpReply to support proxy access and to not show user and password in the URL.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1509
diff
changeset
|
21 | def __init__(self, parent=None): |
585f6646bf50
Changed the FtpReply to support proxy access and to not show user and password in the URL.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1509
diff
changeset
|
22 | """ |
585f6646bf50
Changed the FtpReply to support proxy access and to not show user and password in the URL.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1509
diff
changeset
|
23 | Constructor |
585f6646bf50
Changed the FtpReply to support proxy access and to not show user and password in the URL.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1509
diff
changeset
|
24 | |
585f6646bf50
Changed the FtpReply to support proxy access and to not show user and password in the URL.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1509
diff
changeset
|
25 | @param parent reference to the parent object (QObject) |
585f6646bf50
Changed the FtpReply to support proxy access and to not show user and password in the URL.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1509
diff
changeset
|
26 | """ |
2525
8b507a9a2d40
Script changes: Future import added, super calls modified and unicode behavior for str.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
2403
diff
changeset
|
27 | super(FtpAccessHandler, self).__init__(parent) |
2050
585f6646bf50
Changed the FtpReply to support proxy access and to not show user and password in the URL.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1509
diff
changeset
|
28 | |
585f6646bf50
Changed the FtpReply to support proxy access and to not show user and password in the URL.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1509
diff
changeset
|
29 | self.__authenticatorCache = {} |
585f6646bf50
Changed the FtpReply to support proxy access and to not show user and password in the URL.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1509
diff
changeset
|
30 | self.__proxyAuthenticator = None |
585f6646bf50
Changed the FtpReply to support proxy access and to not show user and password in the URL.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1509
diff
changeset
|
31 | |
945
8cd4d08fa9f6
Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
791
diff
changeset
|
32 | def createRequest(self, op, request, outgoingData=None): |
278
c93823b96faa
Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
33 | """ |
3591
2f2a4a76dd22
Corrected a bunch of source docu issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3178
diff
changeset
|
34 | Public method to create a request. |
278
c93823b96faa
Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
35 | |
3002
6ffc581f00f1
Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2403
diff
changeset
|
36 | @param op the operation to be performed |
6ffc581f00f1
Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2403
diff
changeset
|
37 | (QNetworkAccessManager.Operation) |
278
c93823b96faa
Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
38 | @param request reference to the request object (QNetworkRequest) |
c93823b96faa
Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
39 | @param outgoingData reference to an IODevice containing data to be sent |
c93823b96faa
Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
40 | (QIODevice) |
c93823b96faa
Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
41 | @return reference to the created reply object (QNetworkReply) |
c93823b96faa
Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
42 | """ |
c93823b96faa
Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
43 | if op == QNetworkAccessManager.GetOperation: |
2403
e3d7a861547c
Continued implementing the delayed import.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2302
diff
changeset
|
44 | from .FtpReply import FtpReply |
2050
585f6646bf50
Changed the FtpReply to support proxy access and to not show user and password in the URL.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1509
diff
changeset
|
45 | return FtpReply(request.url(), self, self.parent()) |
278
c93823b96faa
Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
46 | else: |
c93823b96faa
Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
47 | return None |
2050
585f6646bf50
Changed the FtpReply to support proxy access and to not show user and password in the URL.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1509
diff
changeset
|
48 | |
585f6646bf50
Changed the FtpReply to support proxy access and to not show user and password in the URL.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1509
diff
changeset
|
49 | def setAuthenticator(self, realm, authenticator): |
585f6646bf50
Changed the FtpReply to support proxy access and to not show user and password in the URL.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1509
diff
changeset
|
50 | """ |
585f6646bf50
Changed the FtpReply to support proxy access and to not show user and password in the URL.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1509
diff
changeset
|
51 | Public method to add or change an authenticator in our cache. |
585f6646bf50
Changed the FtpReply to support proxy access and to not show user and password in the URL.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1509
diff
changeset
|
52 | |
585f6646bf50
Changed the FtpReply to support proxy access and to not show user and password in the URL.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1509
diff
changeset
|
53 | @param realm name of the realm the authenticator belongs to (string) |
3002
6ffc581f00f1
Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2403
diff
changeset
|
54 | @param authenticator authenticator to add to the cache |
6ffc581f00f1
Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2403
diff
changeset
|
55 | (QAuthenticator). If it is None, the entry will be deleted from |
6ffc581f00f1
Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2403
diff
changeset
|
56 | the cache. |
2050
585f6646bf50
Changed the FtpReply to support proxy access and to not show user and password in the URL.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1509
diff
changeset
|
57 | """ |
585f6646bf50
Changed the FtpReply to support proxy access and to not show user and password in the URL.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1509
diff
changeset
|
58 | if realm: |
585f6646bf50
Changed the FtpReply to support proxy access and to not show user and password in the URL.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1509
diff
changeset
|
59 | if authenticator: |
585f6646bf50
Changed the FtpReply to support proxy access and to not show user and password in the URL.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1509
diff
changeset
|
60 | self.__authenticatorCache[realm] = authenticator |
585f6646bf50
Changed the FtpReply to support proxy access and to not show user and password in the URL.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1509
diff
changeset
|
61 | else: |
585f6646bf50
Changed the FtpReply to support proxy access and to not show user and password in the URL.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1509
diff
changeset
|
62 | if realm in self.__authenticatorCache: |
585f6646bf50
Changed the FtpReply to support proxy access and to not show user and password in the URL.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1509
diff
changeset
|
63 | del self.__authenticatorCache[realm] |
585f6646bf50
Changed the FtpReply to support proxy access and to not show user and password in the URL.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1509
diff
changeset
|
64 | |
585f6646bf50
Changed the FtpReply to support proxy access and to not show user and password in the URL.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1509
diff
changeset
|
65 | def getAuthenticator(self, realm): |
585f6646bf50
Changed the FtpReply to support proxy access and to not show user and password in the URL.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1509
diff
changeset
|
66 | """ |
585f6646bf50
Changed the FtpReply to support proxy access and to not show user and password in the URL.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1509
diff
changeset
|
67 | Public method to get an authenticator for the given realm. |
585f6646bf50
Changed the FtpReply to support proxy access and to not show user and password in the URL.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1509
diff
changeset
|
68 | |
585f6646bf50
Changed the FtpReply to support proxy access and to not show user and password in the URL.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1509
diff
changeset
|
69 | @param realm name of the realm to get the authenticator for (string) |
585f6646bf50
Changed the FtpReply to support proxy access and to not show user and password in the URL.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1509
diff
changeset
|
70 | @return authenticator for the given realm (QAuthenticator) or None |
585f6646bf50
Changed the FtpReply to support proxy access and to not show user and password in the URL.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1509
diff
changeset
|
71 | """ |
585f6646bf50
Changed the FtpReply to support proxy access and to not show user and password in the URL.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1509
diff
changeset
|
72 | if realm in self.__authenticatorCache: |
585f6646bf50
Changed the FtpReply to support proxy access and to not show user and password in the URL.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1509
diff
changeset
|
73 | return self.__authenticatorCache[realm] |
585f6646bf50
Changed the FtpReply to support proxy access and to not show user and password in the URL.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1509
diff
changeset
|
74 | else: |
585f6646bf50
Changed the FtpReply to support proxy access and to not show user and password in the URL.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1509
diff
changeset
|
75 | return None |
585f6646bf50
Changed the FtpReply to support proxy access and to not show user and password in the URL.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1509
diff
changeset
|
76 | |
585f6646bf50
Changed the FtpReply to support proxy access and to not show user and password in the URL.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1509
diff
changeset
|
77 | def setProxyAuthenticator(self, authenticator): |
585f6646bf50
Changed the FtpReply to support proxy access and to not show user and password in the URL.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1509
diff
changeset
|
78 | """ |
585f6646bf50
Changed the FtpReply to support proxy access and to not show user and password in the URL.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1509
diff
changeset
|
79 | Public method to add or change the authenticator for the FTP proxy. |
585f6646bf50
Changed the FtpReply to support proxy access and to not show user and password in the URL.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1509
diff
changeset
|
80 | |
585f6646bf50
Changed the FtpReply to support proxy access and to not show user and password in the URL.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1509
diff
changeset
|
81 | @param authenticator authenticator for the FTP proxy (QAuthenticator) |
585f6646bf50
Changed the FtpReply to support proxy access and to not show user and password in the URL.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1509
diff
changeset
|
82 | """ |
585f6646bf50
Changed the FtpReply to support proxy access and to not show user and password in the URL.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1509
diff
changeset
|
83 | self.__proxyAuthenticator = authenticator |
585f6646bf50
Changed the FtpReply to support proxy access and to not show user and password in the URL.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1509
diff
changeset
|
84 | |
585f6646bf50
Changed the FtpReply to support proxy access and to not show user and password in the URL.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1509
diff
changeset
|
85 | def getProxyAuthenticator(self): |
585f6646bf50
Changed the FtpReply to support proxy access and to not show user and password in the URL.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1509
diff
changeset
|
86 | """ |
585f6646bf50
Changed the FtpReply to support proxy access and to not show user and password in the URL.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1509
diff
changeset
|
87 | Public method to get the authenticator for the FTP proxy. |
585f6646bf50
Changed the FtpReply to support proxy access and to not show user and password in the URL.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1509
diff
changeset
|
88 | |
585f6646bf50
Changed the FtpReply to support proxy access and to not show user and password in the URL.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1509
diff
changeset
|
89 | @return authenticator for the FTP proxy (QAuthenticator) |
585f6646bf50
Changed the FtpReply to support proxy access and to not show user and password in the URL.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1509
diff
changeset
|
90 | """ |
585f6646bf50
Changed the FtpReply to support proxy access and to not show user and password in the URL.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1509
diff
changeset
|
91 | return self.__proxyAuthenticator |