|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2010 - 2019 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing a scheme access handler for FTP. |
|
8 """ |
|
9 |
|
10 from __future__ import unicode_literals |
|
11 |
|
12 from PyQt5.QtNetwork import QNetworkAccessManager |
|
13 |
|
14 from .SchemeAccessHandler import SchemeAccessHandler |
|
15 |
|
16 |
|
17 class FtpAccessHandler(SchemeAccessHandler): |
|
18 """ |
|
19 Class implementing a scheme access handler for FTP. |
|
20 """ |
|
21 def __init__(self, parent=None): |
|
22 """ |
|
23 Constructor |
|
24 |
|
25 @param parent reference to the parent object (QObject) |
|
26 """ |
|
27 super(FtpAccessHandler, self).__init__(parent) |
|
28 |
|
29 self.__authenticatorCache = {} |
|
30 self.__proxyAuthenticator = None |
|
31 |
|
32 def createRequest(self, op, request, outgoingData=None): |
|
33 """ |
|
34 Public method to create a request. |
|
35 |
|
36 @param op the operation to be performed |
|
37 (QNetworkAccessManager.Operation) |
|
38 @param request reference to the request object (QNetworkRequest) |
|
39 @param outgoingData reference to an IODevice containing data to be sent |
|
40 (QIODevice) |
|
41 @return reference to the created reply object (QNetworkReply) |
|
42 """ |
|
43 if op == QNetworkAccessManager.GetOperation: |
|
44 from .FtpReply import FtpReply |
|
45 return FtpReply(request.url(), self, self.parent()) |
|
46 else: |
|
47 return None |
|
48 |
|
49 def setAuthenticator(self, realm, authenticator): |
|
50 """ |
|
51 Public method to add or change an authenticator in our cache. |
|
52 |
|
53 @param realm name of the realm the authenticator belongs to (string) |
|
54 @param authenticator authenticator to add to the cache |
|
55 (QAuthenticator). If it is None, the entry will be deleted from |
|
56 the cache. |
|
57 """ |
|
58 if realm: |
|
59 if authenticator: |
|
60 self.__authenticatorCache[realm] = authenticator |
|
61 else: |
|
62 if realm in self.__authenticatorCache: |
|
63 del self.__authenticatorCache[realm] |
|
64 |
|
65 def getAuthenticator(self, realm): |
|
66 """ |
|
67 Public method to get an authenticator for the given realm. |
|
68 |
|
69 @param realm name of the realm to get the authenticator for (string) |
|
70 @return authenticator for the given realm (QAuthenticator) or None |
|
71 """ |
|
72 if realm in self.__authenticatorCache: |
|
73 return self.__authenticatorCache[realm] |
|
74 else: |
|
75 return None |
|
76 |
|
77 def setProxyAuthenticator(self, authenticator): |
|
78 """ |
|
79 Public method to add or change the authenticator for the FTP proxy. |
|
80 |
|
81 @param authenticator authenticator for the FTP proxy (QAuthenticator) |
|
82 """ |
|
83 self.__proxyAuthenticator = authenticator |
|
84 |
|
85 def getProxyAuthenticator(self): |
|
86 """ |
|
87 Public method to get the authenticator for the FTP proxy. |
|
88 |
|
89 @return authenticator for the FTP proxy (QAuthenticator) |
|
90 """ |
|
91 return self.__proxyAuthenticator |