Helpviewer/Network/FtpReply.py

changeset 304
98429932e0c9
parent 287
52b4c72080d2
child 311
df292f01b392
equal deleted inserted replaced
303:17906f47712a 304:98429932e0c9
8 """ 8 """
9 9
10 from PyQt4.QtCore import QByteArray, QIODevice, Qt, QUrl, QTimer, QBuffer 10 from PyQt4.QtCore import QByteArray, QIODevice, Qt, QUrl, QTimer, QBuffer
11 from PyQt4.QtGui import QPixmap 11 from PyQt4.QtGui import QPixmap
12 from PyQt4.QtNetwork import QFtp, QNetworkReply, QNetworkRequest, QUrlInfo, \ 12 from PyQt4.QtNetwork import QFtp, QNetworkReply, QNetworkRequest, QUrlInfo, \
13 QNetworkProxyQuery, QNetworkProxy 13 QNetworkProxyQuery, QNetworkProxy, QAuthenticator
14 from PyQt4.QtWebKit import QWebSettings 14 from PyQt4.QtWebKit import QWebSettings
15 15
16 import UI.PixmapCache 16 import UI.PixmapCache
17 17
18 ftpListPage_html = """\ 18 ftpListPage_html = """\
100 100
101 @param url requested FTP URL (QUrl) 101 @param url requested FTP URL (QUrl)
102 @param parent reference to the parent object (QObject) 102 @param parent reference to the parent object (QObject)
103 """ 103 """
104 QNetworkReply.__init__(self, parent) 104 QNetworkReply.__init__(self, parent)
105
106 self.__manager = parent
105 107
106 self.__ftp = QFtp(self) 108 self.__ftp = QFtp(self)
107 self.__ftp.listInfo.connect(self.__processListInfo) 109 self.__ftp.listInfo.connect(self.__processListInfo)
108 self.__ftp.readyRead.connect(self.__processData) 110 self.__ftp.readyRead.connect(self.__processData)
109 self.__ftp.commandFinished.connect(self.__processCommand) 111 self.__ftp.commandFinished.connect(self.__processCommand)
201 203
202 @param id id of the command to be processed (integer) (ignored) 204 @param id id of the command to be processed (integer) (ignored)
203 @param error flag indicating an error condition (boolean) 205 @param error flag indicating an error condition (boolean)
204 """ 206 """
205 if error: 207 if error:
206 if error == QFtp.HostNotFound: 208 if self.__ftp.error() == QFtp.HostNotFound:
207 err = QNetworkReply.HostNotFoundError 209 err = QNetworkReply.HostNotFoundError
208 elif error == QFtp.ConnectionRefused: 210 elif self.__ftp.error() == QFtp.ConnectionRefused:
209 err = QNetworkReply.ConnectionRefusedError 211 err = QNetworkReply.ConnectionRefusedError
210 else: 212 else:
211 err = QNetworkReply.ContentNotFoundError 213 if self.__ftp.state() != QFtp.LoggedIn and \
214 self.__ftp.state() == QFtp.Connected:
215 # authentication is required
216 newUrl = self.url()
217 auth = QAuthenticator()
218 self.__manager.authenticationRequired.emit(self, auth)
219 if not auth.isNull():
220 newUrl.setUserName(auth.user())
221 newUrl.setPassword(auth.password())
222 self.setUrl(newUrl)
223 self.__ftp.login(auth.user(), auth.password())
224 return
225
226 err = QNetworkReply.ProtocolFailure
212 self.setError(err, self.__ftp.errorString()) 227 self.setError(err, self.__ftp.errorString())
213 self.error.emit(err) 228 self.error.emit(err)
229 self.finished.emit()
230 if self.__ftp.state() != QFtp.Unconnected:
231 self.__ftp.close()
214 return 232 return
215 233
216 cmd = self.__ftp.currentCommand() 234 cmd = self.__ftp.currentCommand()
217 if cmd == QFtp.ConnectToHost: 235 if cmd == QFtp.ConnectToHost:
218 self.__ftp.login() 236 self.__ftp.login(self.url().userName(), self.url().password())
219 elif cmd == QFtp.Login: 237 elif cmd == QFtp.Login:
220 self.__ftp.list(self.url().path()) 238 self.__ftp.list(self.url().path())
221 elif cmd == QFtp.List: 239 elif cmd == QFtp.List:
222 if len(self.__items) == 1 and \ 240 if len(self.__items) == 1 and \
223 self.__items[0].isFile(): 241 self.__items[0].isFile():

eric ide

mercurial