Helpviewer/Network/FtpReply.py

changeset 311
df292f01b392
parent 304
98429932e0c9
child 791
9ec2ac20e54e
equal deleted inserted replaced
309:93f16dafbbf2 311:df292f01b392
134 QTimer.singleShot(0, self.__errorSignals) 134 QTimer.singleShot(0, self.__errorSignals)
135 return 135 return
136 elif ftpProxy.type() == QNetworkProxy.FtpCachingProxy: 136 elif ftpProxy.type() == QNetworkProxy.FtpCachingProxy:
137 self.__ftp.setProxy(ftpProxy.hostName(), ftpProxy.port()) 137 self.__ftp.setProxy(ftpProxy.hostName(), ftpProxy.port())
138 138
139 self.__loggingIn = False
140
139 QTimer.singleShot(0, self.__connectToHost) 141 QTimer.singleShot(0, self.__connectToHost)
140 142
141 def __errorSignals(self): 143 def __errorSignals(self):
142 """ 144 """
143 Private slot to send signal for errors during initialisation. 145 Private slot to send signal for errors during initialisation.
208 if self.__ftp.error() == QFtp.HostNotFound: 210 if self.__ftp.error() == QFtp.HostNotFound:
209 err = QNetworkReply.HostNotFoundError 211 err = QNetworkReply.HostNotFoundError
210 elif self.__ftp.error() == QFtp.ConnectionRefused: 212 elif self.__ftp.error() == QFtp.ConnectionRefused:
211 err = QNetworkReply.ConnectionRefusedError 213 err = QNetworkReply.ConnectionRefusedError
212 else: 214 else:
213 if self.__ftp.state() != QFtp.LoggedIn and \ 215 if self.__loggingIn and \
214 self.__ftp.state() == QFtp.Connected: 216 self.__ftp.state() == QFtp.Connected:
215 # authentication is required 217 # authentication is required
218 if "anonymous" in self.__ftp.errorString():
219 self.__ftp.login()
220 return
221
216 newUrl = self.url() 222 newUrl = self.url()
217 auth = QAuthenticator() 223 auth = QAuthenticator()
218 self.__manager.authenticationRequired.emit(self, auth) 224 self.__manager.authenticationRequired.emit(self, auth)
219 if not auth.isNull(): 225 if not auth.isNull():
220 newUrl.setUserName(auth.user()) 226 if auth.user():
221 newUrl.setPassword(auth.password()) 227 newUrl.setUserName(auth.user())
222 self.setUrl(newUrl) 228 newUrl.setPassword(auth.password())
223 self.__ftp.login(auth.user(), auth.password()) 229 self.setUrl(newUrl)
224 return 230 else:
231 auth.setUser("anonymous")
232 auth.setPassword("anonymous")
233 if self.__ftp.state() == QFtp.Connected:
234 self.__ftp.login(auth.user(), auth.password())
235 return
225 236
226 err = QNetworkReply.ProtocolFailure 237 err = QNetworkReply.ProtocolFailure
227 self.setError(err, self.__ftp.errorString()) 238 self.setError(err, self.__ftp.errorString())
228 self.error.emit(err) 239 self.error.emit(err)
229 self.finished.emit() 240 self.finished.emit()
230 if self.__ftp.state() != QFtp.Unconnected: 241 if self.__ftp.state() not in [QFtp.Unconnected, QFtp.Closing]:
231 self.__ftp.close() 242 self.__ftp.close()
232 return 243 return
233 244
234 cmd = self.__ftp.currentCommand() 245 cmd = self.__ftp.currentCommand()
235 if cmd == QFtp.ConnectToHost: 246 if cmd == QFtp.ConnectToHost:
247 self.__loggingIn = True
236 self.__ftp.login(self.url().userName(), self.url().password()) 248 self.__ftp.login(self.url().userName(), self.url().password())
237 elif cmd == QFtp.Login: 249 elif cmd == QFtp.Login:
250 self.__loggingIn = False
238 self.__ftp.list(self.url().path()) 251 self.__ftp.list(self.url().path())
239 elif cmd == QFtp.List: 252 elif cmd == QFtp.List:
240 if len(self.__items) == 1 and \ 253 if len(self.__items) == 1 and \
241 self.__items[0].isFile(): 254 self.__items[0].isFile():
242 self.__ftp.get(self.url().path()) 255 self.__ftp.get(self.url().path())

eric ide

mercurial