Helpviewer/Network/FtpReply.py

Thu, 01 Jan 2015 13:11:59 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Thu, 01 Jan 2015 13:11:59 +0100
changeset 4021
195a471c327b
parent 3656
441956d8fce5
child 4631
5c1a96925da4
permissions
-rw-r--r--

Updated copyright for 2015.

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
4021
195a471c327b Updated copyright for 2015.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3656
diff changeset
3 # Copyright (c) 2010 - 2015 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 network reply class for FTP resources.
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: 3058
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 try:
3484
645c12de6b0c Merge with default branch.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3178 3190
diff changeset
12 str = unicode
645c12de6b0c Merge with default branch.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3178 3190
diff changeset
13 except NameError:
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
14 pass
8b507a9a2d40 Script changes: Future import added, super calls modified and unicode behavior for str.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2403
diff changeset
15
2044
9d229b584c49 Change the FtpReply class to use Python ftplib instead of QFtp because the later is not available in Qt5 anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1625
diff changeset
16 import ftplib
9d229b584c49 Change the FtpReply class to use Python ftplib instead of QFtp because the later is not available in Qt5 anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1625
diff changeset
17 import socket
9d229b584c49 Change the FtpReply class to use Python ftplib instead of QFtp because the later is not available in Qt5 anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1625
diff changeset
18 import errno
2047
739aa1717df5 Extended the new FtpReply class to handle various directory listing styles and to ask for a username and password, if the FTP login fails with an error code of 530.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2044
diff changeset
19 import mimetypes
2044
9d229b584c49 Change the FtpReply class to use Python ftplib instead of QFtp because the later is not available in Qt5 anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1625
diff changeset
20
3656
441956d8fce5 Started porting eric5 to PyQt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3591
diff changeset
21 from PyQt5.QtCore import QByteArray, QIODevice, Qt, QUrl, QTimer, QBuffer, \
2047
739aa1717df5 Extended the new FtpReply class to handle various directory listing styles and to ask for a username and password, if the FTP login fails with an error code of 530.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2044
diff changeset
22 QCoreApplication
3656
441956d8fce5 Started porting eric5 to PyQt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3591
diff changeset
23 from PyQt5.QtGui import QPixmap
441956d8fce5 Started porting eric5 to PyQt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3591
diff changeset
24 from PyQt5.QtWidgets import QDialog
441956d8fce5 Started porting eric5 to PyQt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3591
diff changeset
25 from PyQt5.QtNetwork import QNetworkReply, QNetworkRequest, QAuthenticator
441956d8fce5 Started porting eric5 to PyQt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3591
diff changeset
26 from PyQt5.QtWebKit import QWebSettings
278
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27
2074
5cb87968aad5 Reworked the FTP stuff to support a bunch of different FTP proxy types. Unfortunately FTP proxy support is not standardized.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2054
diff changeset
28 from E5Network.E5Ftp import E5Ftp, E5FtpProxyError, E5FtpProxyType
5cb87968aad5 Reworked the FTP stuff to support a bunch of different FTP proxy types. Unfortunately FTP proxy support is not standardized.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2054
diff changeset
29
278
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30 import UI.PixmapCache
2074
5cb87968aad5 Reworked the FTP stuff to support a bunch of different FTP proxy types. Unfortunately FTP proxy support is not standardized.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2054
diff changeset
31
2047
739aa1717df5 Extended the new FtpReply class to handle various directory listing styles and to ask for a username and password, if the FTP login fails with an error code of 530.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2044
diff changeset
32 from Utilities.FtpUtilities import FtpDirLineParser, FtpDirLineParserError
2080
4b33165dd55b Made the third set of Qt5 compatibility changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2074
diff changeset
33 import Utilities
278
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34
2074
5cb87968aad5 Reworked the FTP stuff to support a bunch of different FTP proxy types. Unfortunately FTP proxy support is not standardized.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2054
diff changeset
35 import Preferences
5cb87968aad5 Reworked the FTP stuff to support a bunch of different FTP proxy types. Unfortunately FTP proxy support is not standardized.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2054
diff changeset
36
278
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
37 ftpListPage_html = """\
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38 <?xml version="1.0" encoding="UTF-8" ?>
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
42 <head>
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
43 <title>{0}</title>
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
44 <style type="text/css">
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45 body {{
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
46 padding: 3em 0em;
3002
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
47 background: -webkit-gradient(linear, left top, left bottom, from(#85784A),
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
48 to(#FDFDFD), color-stop(0.5, #FDFDFD));
278
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
49 background-repeat: repeat-x;
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
50 }}
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
51 #box {{
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
52 background: white;
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53 border: 1px solid #85784A;
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54 width: 80%;
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55 padding: 30px;
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
56 margin: auto;
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
57 -webkit-border-radius: 0.8em;
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
58 }}
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
59 h1 {{
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60 font-size: 130%;
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
61 font-weight: bold;
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
62 border-bottom: 1px solid #85784A;
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
63 }}
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
64 th {{
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
65 background-color: #B8B096;
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
66 color: black;
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
67 }}
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
68 table {{
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
69 border: solid 1px #85784A;
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
70 margin: 5px 0;
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
71 width: 100%;
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
72 }}
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
73 tr.odd {{
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
74 background-color: white;
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
75 color: black;
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
76 }}
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
77 tr.even {{
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
78 background-color: #CEC9B8;
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
79 color: black;
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
80 }}
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
81 .modified {{
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
82 text-align: left;
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
83 vertical-align: top;
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
84 white-space: nowrap;
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
85 }}
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
86 .size {{
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
87 text-align: right;
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
88 vertical-align: top;
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
89 white-space: nowrap;
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
90 padding-right: 22px;
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
91 }}
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
92 .name {{
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
93 text-align: left;
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
94 vertical-align: top;
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
95 white-space: pre-wrap;
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
96 width: 100%
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
97 }}
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
98 {1}
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
99 </style>
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
100 </head>
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
101 <body>
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
102 <div id="box">
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
103 <h1>{2}</h1>
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
104 {3}
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
105 <table align="center" cellspacing="0" width="90%">
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
106 {4}
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
107 </table>
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
108 </div>
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
109 </body>
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
110 </html>
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
111 """
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
112
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 826
diff changeset
113
278
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
114 class FtpReply(QNetworkReply):
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
115 """
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
116 Class implementing a network reply for FTP resources.
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
117 """
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: 2047
diff changeset
118 def __init__(self, url, accessHandler, parent=None):
278
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
119 """
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
120 Constructor
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
121
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
122 @param url requested FTP URL (QUrl)
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: 2047
diff changeset
123 @param accessHandler reference to the access handler (FtpAccessHandler)
278
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
124 @param parent reference to the parent object (QObject)
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
125 """
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
126 super(FtpReply, self).__init__(parent)
278
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
127
304
98429932e0c9 Extended the fTP reply class to support authentication.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 287
diff changeset
128 self.__manager = 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: 2047
diff changeset
129 self.__handler = accessHandler
304
98429932e0c9 Extended the fTP reply class to support authentication.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 287
diff changeset
130
2074
5cb87968aad5 Reworked the FTP stuff to support a bunch of different FTP proxy types. Unfortunately FTP proxy support is not standardized.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2054
diff changeset
131 self.__ftp = E5Ftp()
278
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
132
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
133 self.__items = []
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
134 self.__content = QByteArray()
3002
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
135 self.__units = ["Bytes", "KB", "MB", "GB", "TB",
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
136 "PB", "EB", "ZB", "YB"]
2047
739aa1717df5 Extended the new FtpReply class to handle various directory listing styles and to ask for a username and password, if the FTP login fails with an error code of 530.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2044
diff changeset
137 self.__dirLineParser = FtpDirLineParser()
2053
ef81185e8b89 Improved the FtpReply a bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2050
diff changeset
138 self.__fileBytesReceived = 0
278
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
139
287
52b4c72080d2 Added proxy support to the FTP reply class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 278
diff changeset
140 if url.path() == "":
52b4c72080d2 Added proxy support to the FTP reply class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 278
diff changeset
141 url.setPath("/")
278
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
142 self.setUrl(url)
287
52b4c72080d2 Added proxy support to the FTP reply class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 278
diff changeset
143
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: 2047
diff changeset
144 # do proxy setup
2074
5cb87968aad5 Reworked the FTP stuff to support a bunch of different FTP proxy types. Unfortunately FTP proxy support is not standardized.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2054
diff changeset
145 if not Preferences.getUI("UseProxy"):
5cb87968aad5 Reworked the FTP stuff to support a bunch of different FTP proxy types. Unfortunately FTP proxy support is not standardized.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2054
diff changeset
146 proxyType = E5FtpProxyType.NoProxy
5cb87968aad5 Reworked the FTP stuff to support a bunch of different FTP proxy types. Unfortunately FTP proxy support is not standardized.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2054
diff changeset
147 else:
5cb87968aad5 Reworked the FTP stuff to support a bunch of different FTP proxy types. Unfortunately FTP proxy support is not standardized.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2054
diff changeset
148 proxyType = Preferences.getUI("ProxyType/Ftp")
5cb87968aad5 Reworked the FTP stuff to support a bunch of different FTP proxy types. Unfortunately FTP proxy support is not standardized.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2054
diff changeset
149 if proxyType != E5FtpProxyType.NoProxy:
3022
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3002
diff changeset
150 self.__ftp.setProxy(
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3002
diff changeset
151 proxyType,
2074
5cb87968aad5 Reworked the FTP stuff to support a bunch of different FTP proxy types. Unfortunately FTP proxy support is not standardized.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2054
diff changeset
152 Preferences.getUI("ProxyHost/Ftp"),
5cb87968aad5 Reworked the FTP stuff to support a bunch of different FTP proxy types. Unfortunately FTP proxy support is not standardized.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2054
diff changeset
153 Preferences.getUI("ProxyPort/Ftp"))
5cb87968aad5 Reworked the FTP stuff to support a bunch of different FTP proxy types. Unfortunately FTP proxy support is not standardized.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2054
diff changeset
154 if proxyType != E5FtpProxyType.NonAuthorizing:
5cb87968aad5 Reworked the FTP stuff to support a bunch of different FTP proxy types. Unfortunately FTP proxy support is not standardized.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2054
diff changeset
155 self.__ftp.setProxyAuthentication(
5cb87968aad5 Reworked the FTP stuff to support a bunch of different FTP proxy types. Unfortunately FTP proxy support is not standardized.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2054
diff changeset
156 Preferences.getUI("ProxyUser/Ftp"),
5cb87968aad5 Reworked the FTP stuff to support a bunch of different FTP proxy types. Unfortunately FTP proxy support is not standardized.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2054
diff changeset
157 Preferences.getUI("ProxyPassword/Ftp"),
5cb87968aad5 Reworked the FTP stuff to support a bunch of different FTP proxy types. Unfortunately FTP proxy support is not standardized.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2054
diff changeset
158 Preferences.getUI("ProxyAccount/Ftp"))
311
df292f01b392 Fixed lagging in to FTP sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 304
diff changeset
159
2044
9d229b584c49 Change the FtpReply class to use Python ftplib instead of QFtp because the later is not available in Qt5 anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1625
diff changeset
160 QTimer.singleShot(0, self.__doFtpCommands)
287
52b4c72080d2 Added proxy support to the FTP reply class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 278
diff changeset
161
278
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
162 def abort(self):
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
163 """
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
164 Public slot to abort the operation.
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
165 """
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
166 # do nothing
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
167 pass
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
168
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
169 def bytesAvailable(self):
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
170 """
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
171 Public method to determined the bytes available for being read.
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
172
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
173 @return bytes available (integer)
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
174 """
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
175 return self.__content.size()
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
176
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
177 def isSequential(self):
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
178 """
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
179 Public method to check for sequential access.
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
180
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
181 @return flag indicating sequential access (boolean)
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
182 """
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
183 return True
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
184
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
185 def readData(self, maxlen):
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
186 """
3591
2f2a4a76dd22 Corrected a bunch of source docu issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3484
diff changeset
187 Public method to retrieve data from the reply object.
278
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
188
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
189 @param maxlen maximum number of bytes to read (integer)
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
190 @return string containing the data (bytes)
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
191 """
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
192 if self.__content.size():
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
193 len_ = min(maxlen, self.__content.size())
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
194 buffer = bytes(self.__content[:len_])
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
195 self.__content.remove(0, len_)
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
196 return buffer
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
197
2044
9d229b584c49 Change the FtpReply class to use Python ftplib instead of QFtp because the later is not available in Qt5 anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1625
diff changeset
198 def __doFtpCommands(self):
278
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
199 """
3002
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
200 Private slot doing the sequence of FTP commands to get the requested
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
201 result.
278
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
202 """
2047
739aa1717df5 Extended the new FtpReply class to handle various directory listing styles and to ask for a username and password, if the FTP login fails with an error code of 530.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2044
diff changeset
203 retry = True
2044
9d229b584c49 Change the FtpReply class to use Python ftplib instead of QFtp because the later is not available in Qt5 anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1625
diff changeset
204 try:
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: 2047
diff changeset
205 username = self.url().userName()
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: 2047
diff changeset
206 password = self.url().password()
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: 2047
diff changeset
207 byAuth = False
2074
5cb87968aad5 Reworked the FTP stuff to support a bunch of different FTP proxy types. Unfortunately FTP proxy support is not standardized.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2054
diff changeset
208
2047
739aa1717df5 Extended the new FtpReply class to handle various directory listing styles and to ask for a username and password, if the FTP login fails with an error code of 530.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2044
diff changeset
209 while retry:
2074
5cb87968aad5 Reworked the FTP stuff to support a bunch of different FTP proxy types. Unfortunately FTP proxy support is not standardized.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2054
diff changeset
210 try:
5cb87968aad5 Reworked the FTP stuff to support a bunch of different FTP proxy types. Unfortunately FTP proxy support is not standardized.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2054
diff changeset
211 self.__ftp.connect(self.url().host(),
5cb87968aad5 Reworked the FTP stuff to support a bunch of different FTP proxy types. Unfortunately FTP proxy support is not standardized.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2054
diff changeset
212 self.url().port(ftplib.FTP_PORT),
2054
099993935e6d Added the forgotten timeout parameter when connecting to an FTP proxy.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2053
diff changeset
213 timeout=10)
2074
5cb87968aad5 Reworked the FTP stuff to support a bunch of different FTP proxy types. Unfortunately FTP proxy support is not standardized.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2054
diff changeset
214 except E5FtpProxyError as err:
5cb87968aad5 Reworked the FTP stuff to support a bunch of different FTP proxy types. Unfortunately FTP proxy support is not standardized.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2054
diff changeset
215 self.setError(QNetworkReply.ProxyNotFoundError, str(err))
5cb87968aad5 Reworked the FTP stuff to support a bunch of different FTP proxy types. Unfortunately FTP proxy support is not standardized.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2054
diff changeset
216 self.error.emit(QNetworkReply.ProxyNotFoundError)
5cb87968aad5 Reworked the FTP stuff to support a bunch of different FTP proxy types. Unfortunately FTP proxy support is not standardized.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2054
diff changeset
217 self.finished.emit()
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: 2047
diff changeset
218 ok, retry = self.__doFtpLogin(username, password, byAuth)
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: 2047
diff changeset
219 if not ok and retry:
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: 2047
diff changeset
220 auth = self.__handler.getAuthenticator(self.url().host())
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: 2047
diff changeset
221 if auth and not auth.isNull() and auth.user():
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: 2047
diff changeset
222 username = auth.user()
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: 2047
diff changeset
223 password = auth.password()
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: 2047
diff changeset
224 byAuth = True
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: 2047
diff changeset
225 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: 2047
diff changeset
226 retry = False
2047
739aa1717df5 Extended the new FtpReply class to handle various directory listing styles and to ask for a username and password, if the FTP login fails with an error code of 530.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2044
diff changeset
227 if ok:
3002
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
228 self.__ftp.retrlines("LIST " + self.url().path(),
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
229 self.__dirCallback)
2047
739aa1717df5 Extended the new FtpReply class to handle various directory listing styles and to ask for a username and password, if the FTP login fails with an error code of 530.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2044
diff changeset
230 if len(self.__items) == 1 and \
739aa1717df5 Extended the new FtpReply class to handle various directory listing styles and to ask for a username and password, if the FTP login fails with an error code of 530.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2044
diff changeset
231 self.__items[0].isFile():
2053
ef81185e8b89 Improved the FtpReply a bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2050
diff changeset
232 self.__fileBytesReceived = 0
2047
739aa1717df5 Extended the new FtpReply class to handle various directory listing styles and to ask for a username and password, if the FTP login fails with an error code of 530.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2044
diff changeset
233 self.__setContent()
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: 2047
diff changeset
234 self.__ftp.retrbinary(
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: 2047
diff changeset
235 "RETR " + self.url().path(), self.__retrCallback)
2047
739aa1717df5 Extended the new FtpReply class to handle various directory listing styles and to ask for a username and password, if the FTP login fails with an error code of 530.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2044
diff changeset
236 self.__content.append(512 * b' ')
739aa1717df5 Extended the new FtpReply class to handle various directory listing styles and to ask for a username and password, if the FTP login fails with an error code of 530.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2044
diff changeset
237 self.readyRead.emit()
739aa1717df5 Extended the new FtpReply class to handle various directory listing styles and to ask for a username and password, if the FTP login fails with an error code of 530.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2044
diff changeset
238 else:
739aa1717df5 Extended the new FtpReply class to handle various directory listing styles and to ask for a username and password, if the FTP login fails with an error code of 530.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2044
diff changeset
239 self.__setListContent()
739aa1717df5 Extended the new FtpReply class to handle various directory listing styles and to ask for a username and password, if the FTP login fails with an error code of 530.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2044
diff changeset
240 self.__ftp.quit()
2044
9d229b584c49 Change the FtpReply class to use Python ftplib instead of QFtp because the later is not available in Qt5 anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1625
diff changeset
241 except ftplib.all_errors as err:
9d229b584c49 Change the FtpReply class to use Python ftplib instead of QFtp because the later is not available in Qt5 anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1625
diff changeset
242 if isinstance(err, socket.gaierror):
9d229b584c49 Change the FtpReply class to use Python ftplib instead of QFtp because the later is not available in Qt5 anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1625
diff changeset
243 errCode = QNetworkReply.HostNotFoundError
3002
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
244 elif isinstance(err, socket.error) and \
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
245 err.errno == errno.ECONNREFUSED:
2044
9d229b584c49 Change the FtpReply class to use Python ftplib instead of QFtp because the later is not available in Qt5 anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1625
diff changeset
246 errCode = QNetworkReply.ConnectionRefusedError
9d229b584c49 Change the FtpReply class to use Python ftplib instead of QFtp because the later is not available in Qt5 anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1625
diff changeset
247 else:
9d229b584c49 Change the FtpReply class to use Python ftplib instead of QFtp because the later is not available in Qt5 anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1625
diff changeset
248 errCode = QNetworkReply.ProtocolFailure
9d229b584c49 Change the FtpReply class to use Python ftplib instead of QFtp because the later is not available in Qt5 anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1625
diff changeset
249 self.setError(errCode, str(err))
9d229b584c49 Change the FtpReply class to use Python ftplib instead of QFtp because the later is not available in Qt5 anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1625
diff changeset
250 self.error.emit(errCode)
9d229b584c49 Change the FtpReply class to use Python ftplib instead of QFtp because the later is not available in Qt5 anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1625
diff changeset
251 self.finished.emit()
278
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
252
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: 2047
diff changeset
253 def __doFtpLogin(self, username, password, byAuth=False):
2047
739aa1717df5 Extended the new FtpReply class to handle various directory listing styles and to ask for a username and password, if the FTP login fails with an error code of 530.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2044
diff changeset
254 """
3002
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
255 Private method to do the FTP login with asking for a username and
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
256 password, if the login fails with an error 530.
2047
739aa1717df5 Extended the new FtpReply class to handle various directory listing styles and to ask for a username and password, if the FTP login fails with an error code of 530.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2044
diff changeset
257
739aa1717df5 Extended the new FtpReply class to handle various directory listing styles and to ask for a username and password, if the FTP login fails with an error code of 530.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2044
diff changeset
258 @param username user name to use for the login (string)
739aa1717df5 Extended the new FtpReply class to handle various directory listing styles and to ask for a username and password, if the FTP login fails with an error code of 530.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2044
diff changeset
259 @param password password to use for the login (string)
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: 2047
diff changeset
260 @param byAuth flag indicating that the login data was provided by an
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: 2047
diff changeset
261 authenticator (boolean)
2047
739aa1717df5 Extended the new FtpReply class to handle various directory listing styles and to ask for a username and password, if the FTP login fails with an error code of 530.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2044
diff changeset
262 @return tuple of two flags indicating a successful login and
739aa1717df5 Extended the new FtpReply class to handle various directory listing styles and to ask for a username and password, if the FTP login fails with an error code of 530.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2044
diff changeset
263 if the login should be retried (boolean, boolean)
739aa1717df5 Extended the new FtpReply class to handle various directory listing styles and to ask for a username and password, if the FTP login fails with an error code of 530.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2044
diff changeset
264 """
739aa1717df5 Extended the new FtpReply class to handle various directory listing styles and to ask for a username and password, if the FTP login fails with an error code of 530.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2044
diff changeset
265 try:
2074
5cb87968aad5 Reworked the FTP stuff to support a bunch of different FTP proxy types. Unfortunately FTP proxy support is not standardized.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2054
diff changeset
266 self.__ftp.login(username, password)
2047
739aa1717df5 Extended the new FtpReply class to handle various directory listing styles and to ask for a username and password, if the FTP login fails with an error code of 530.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2044
diff changeset
267 return True, False
2074
5cb87968aad5 Reworked the FTP stuff to support a bunch of different FTP proxy types. Unfortunately FTP proxy support is not standardized.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2054
diff changeset
268 except E5FtpProxyError as err:
5cb87968aad5 Reworked the FTP stuff to support a bunch of different FTP proxy types. Unfortunately FTP proxy support is not standardized.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2054
diff changeset
269 code = str(err)[:3]
5cb87968aad5 Reworked the FTP stuff to support a bunch of different FTP proxy types. Unfortunately FTP proxy support is not standardized.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2054
diff changeset
270 if code[1] == "5":
5cb87968aad5 Reworked the FTP stuff to support a bunch of different FTP proxy types. Unfortunately FTP proxy support is not standardized.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2054
diff changeset
271 # could be a 530, check second line
5cb87968aad5 Reworked the FTP stuff to support a bunch of different FTP proxy types. Unfortunately FTP proxy support is not standardized.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2054
diff changeset
272 lines = str(err).splitlines()
5cb87968aad5 Reworked the FTP stuff to support a bunch of different FTP proxy types. Unfortunately FTP proxy support is not standardized.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2054
diff changeset
273 if lines[1][:3] == "530":
5cb87968aad5 Reworked the FTP stuff to support a bunch of different FTP proxy types. Unfortunately FTP proxy support is not standardized.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2054
diff changeset
274 if "usage" in "\n".join(lines[1:].lower()):
5cb87968aad5 Reworked the FTP stuff to support a bunch of different FTP proxy types. Unfortunately FTP proxy support is not standardized.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2054
diff changeset
275 # found a not supported proxy
3002
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
276 self.setError(
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
277 QNetworkReply.ProxyConnectionRefusedError,
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
278 self.tr("The proxy type seems to be wrong."
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
279 " If it is not in the list of"
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
280 " supported proxy types please report"
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
281 " it with the instructions given by"
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
282 " the proxy.\n{0}").format(
2074
5cb87968aad5 Reworked the FTP stuff to support a bunch of different FTP proxy types. Unfortunately FTP proxy support is not standardized.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2054
diff changeset
283 "\n".join(lines[1:])))
3002
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
284 self.error.emit(
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
285 QNetworkReply.ProxyConnectionRefusedError)
2074
5cb87968aad5 Reworked the FTP stuff to support a bunch of different FTP proxy types. Unfortunately FTP proxy support is not standardized.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2054
diff changeset
286 return False, False
5cb87968aad5 Reworked the FTP stuff to support a bunch of different FTP proxy types. Unfortunately FTP proxy support is not standardized.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2054
diff changeset
287 else:
3002
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
288 from UI.AuthenticationDialog import \
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
289 AuthenticationDialog
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
290 info = self.tr(
3002
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
291 "<b>Connect to proxy '{0}' using:</b>")\
2080
4b33165dd55b Made the third set of Qt5 compatibility changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2074
diff changeset
292 .format(Utilities.html_encode(
4b33165dd55b Made the third set of Qt5 compatibility changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2074
diff changeset
293 Preferences.getUI("ProxyHost/Ftp")))
3022
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3002
diff changeset
294 dlg = AuthenticationDialog(
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3002
diff changeset
295 info, Preferences.getUI("ProxyUser/Ftp"), True)
2074
5cb87968aad5 Reworked the FTP stuff to support a bunch of different FTP proxy types. Unfortunately FTP proxy support is not standardized.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2054
diff changeset
296 dlg.setData(Preferences.getUI("ProxyUser/Ftp"),
5cb87968aad5 Reworked the FTP stuff to support a bunch of different FTP proxy types. Unfortunately FTP proxy support is not standardized.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2054
diff changeset
297 Preferences.getUI("ProxyPassword/Ftp"))
5cb87968aad5 Reworked the FTP stuff to support a bunch of different FTP proxy types. Unfortunately FTP proxy support is not standardized.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2054
diff changeset
298 if dlg.exec_() == QDialog.Accepted:
5cb87968aad5 Reworked the FTP stuff to support a bunch of different FTP proxy types. Unfortunately FTP proxy support is not standardized.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2054
diff changeset
299 username, password = dlg.getData()
5cb87968aad5 Reworked the FTP stuff to support a bunch of different FTP proxy types. Unfortunately FTP proxy support is not standardized.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2054
diff changeset
300 if dlg.shallSave():
5cb87968aad5 Reworked the FTP stuff to support a bunch of different FTP proxy types. Unfortunately FTP proxy support is not standardized.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2054
diff changeset
301 Preferences.setUI("ProxyUser/Ftp", username)
3002
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
302 Preferences.setUI(
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
303 "ProxyPassword/Ftp", password)
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
304 self.__ftp.setProxyAuthentication(username,
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
305 password)
2074
5cb87968aad5 Reworked the FTP stuff to support a bunch of different FTP proxy types. Unfortunately FTP proxy support is not standardized.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2054
diff changeset
306 return False, True
5cb87968aad5 Reworked the FTP stuff to support a bunch of different FTP proxy types. Unfortunately FTP proxy support is not standardized.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2054
diff changeset
307 return False, False
2082
5d72ca2fbeab Fixed an issue in the FtpReply class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2080
diff changeset
308 except (ftplib.error_perm, ftplib.error_temp) as err:
2074
5cb87968aad5 Reworked the FTP stuff to support a bunch of different FTP proxy types. Unfortunately FTP proxy support is not standardized.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2054
diff changeset
309 code = err.args[0].strip()[:3]
5cb87968aad5 Reworked the FTP stuff to support a bunch of different FTP proxy types. Unfortunately FTP proxy support is not standardized.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2054
diff changeset
310 if code in ["530", "421"]:
2047
739aa1717df5 Extended the new FtpReply class to handle various directory listing styles and to ask for a username and password, if the FTP login fails with an error code of 530.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2044
diff changeset
311 # error 530 -> Login incorrect
3002
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
312 # error 421 -> Login may be incorrect (reported by some
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
313 # proxies)
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: 2047
diff changeset
314 if byAuth:
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: 2047
diff changeset
315 self.__handler.setAuthenticator(self.url().host(), 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: 2047
diff changeset
316 auth = 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: 2047
diff changeset
317 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: 2047
diff changeset
318 auth = self.__handler.getAuthenticator(self.url().host())
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: 2047
diff changeset
319 if not auth or auth.isNull() or not auth.user():
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: 2047
diff changeset
320 auth = 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: 2047
diff changeset
321 self.__manager.authenticationRequired.emit(self, auth)
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: 2047
diff changeset
322 if not auth.isNull():
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: 2047
diff changeset
323 if auth.user():
3002
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
324 self.__handler.setAuthenticator(self.url().host(),
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
325 auth)
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: 2047
diff changeset
326 return False, True
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: 2047
diff changeset
327 return False, False
2074
5cb87968aad5 Reworked the FTP stuff to support a bunch of different FTP proxy types. Unfortunately FTP proxy support is not standardized.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2054
diff changeset
328 return False, True
2047
739aa1717df5 Extended the new FtpReply class to handle various directory listing styles and to ask for a username and password, if the FTP login fails with an error code of 530.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2044
diff changeset
329 else:
739aa1717df5 Extended the new FtpReply class to handle various directory listing styles and to ask for a username and password, if the FTP login fails with an error code of 530.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2044
diff changeset
330 raise
739aa1717df5 Extended the new FtpReply class to handle various directory listing styles and to ask for a username and password, if the FTP login fails with an error code of 530.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2044
diff changeset
331
2044
9d229b584c49 Change the FtpReply class to use Python ftplib instead of QFtp because the later is not available in Qt5 anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1625
diff changeset
332 def __dirCallback(self, line):
9d229b584c49 Change the FtpReply class to use Python ftplib instead of QFtp because the later is not available in Qt5 anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1625
diff changeset
333 """
9d229b584c49 Change the FtpReply class to use Python ftplib instead of QFtp because the later is not available in Qt5 anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1625
diff changeset
334 Private slot handling the receipt of directory listings.
9d229b584c49 Change the FtpReply class to use Python ftplib instead of QFtp because the later is not available in Qt5 anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1625
diff changeset
335
9d229b584c49 Change the FtpReply class to use Python ftplib instead of QFtp because the later is not available in Qt5 anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1625
diff changeset
336 @param line the received line of the directory listing (string)
278
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
337 """
2047
739aa1717df5 Extended the new FtpReply class to handle various directory listing styles and to ask for a username and password, if the FTP login fails with an error code of 530.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2044
diff changeset
338 try:
739aa1717df5 Extended the new FtpReply class to handle various directory listing styles and to ask for a username and password, if the FTP login fails with an error code of 530.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2044
diff changeset
339 urlInfo = self.__dirLineParser.parseLine(line)
739aa1717df5 Extended the new FtpReply class to handle various directory listing styles and to ask for a username and password, if the FTP login fails with an error code of 530.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2044
diff changeset
340 except FtpDirLineParserError:
739aa1717df5 Extended the new FtpReply class to handle various directory listing styles and to ask for a username and password, if the FTP login fails with an error code of 530.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2044
diff changeset
341 # silently ignore parser errors
739aa1717df5 Extended the new FtpReply class to handle various directory listing styles and to ask for a username and password, if the FTP login fails with an error code of 530.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2044
diff changeset
342 urlInfo = None
278
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
343
2047
739aa1717df5 Extended the new FtpReply class to handle various directory listing styles and to ask for a username and password, if the FTP login fails with an error code of 530.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2044
diff changeset
344 if urlInfo:
739aa1717df5 Extended the new FtpReply class to handle various directory listing styles and to ask for a username and password, if the FTP login fails with an error code of 530.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2044
diff changeset
345 self.__items.append(urlInfo)
2044
9d229b584c49 Change the FtpReply class to use Python ftplib instead of QFtp because the later is not available in Qt5 anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1625
diff changeset
346
9d229b584c49 Change the FtpReply class to use Python ftplib instead of QFtp because the later is not available in Qt5 anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1625
diff changeset
347 QCoreApplication.processEvents()
278
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
348
2044
9d229b584c49 Change the FtpReply class to use Python ftplib instead of QFtp because the later is not available in Qt5 anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1625
diff changeset
349 def __retrCallback(self, data):
278
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
350 """
2044
9d229b584c49 Change the FtpReply class to use Python ftplib instead of QFtp because the later is not available in Qt5 anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1625
diff changeset
351 Private slot handling the reception of data.
9d229b584c49 Change the FtpReply class to use Python ftplib instead of QFtp because the later is not available in Qt5 anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1625
diff changeset
352
9d229b584c49 Change the FtpReply class to use Python ftplib instead of QFtp because the later is not available in Qt5 anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1625
diff changeset
353 @param data data received from the FTP server (bytes)
278
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
354 """
2044
9d229b584c49 Change the FtpReply class to use Python ftplib instead of QFtp because the later is not available in Qt5 anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1625
diff changeset
355 self.__content += QByteArray(data)
2053
ef81185e8b89 Improved the FtpReply a bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2050
diff changeset
356 self.__fileBytesReceived += len(data)
3002
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
357 self.downloadProgress.emit(
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
358 self.__fileBytesReceived, self.__items[0].size())
2053
ef81185e8b89 Improved the FtpReply a bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2050
diff changeset
359 self.readyRead.emit()
2044
9d229b584c49 Change the FtpReply class to use Python ftplib instead of QFtp because the later is not available in Qt5 anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1625
diff changeset
360
9d229b584c49 Change the FtpReply class to use Python ftplib instead of QFtp because the later is not available in Qt5 anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1625
diff changeset
361 QCoreApplication.processEvents()
278
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
362
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
363 def __setContent(self):
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
364 """
1625
4f03e45703e9 Corrected a source docu string in FtpReply.py.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
365 Private method to finish the setup of the data.
278
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
366 """
2047
739aa1717df5 Extended the new FtpReply class to handle various directory listing styles and to ask for a username and password, if the FTP login fails with an error code of 530.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2044
diff changeset
367 mtype, encoding = mimetypes.guess_type(self.url().toString())
278
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
368 self.open(QIODevice.ReadOnly | QIODevice.Unbuffered)
3002
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
369 self.setHeader(QNetworkRequest.ContentLengthHeader,
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
370 self.__items[0].size())
2047
739aa1717df5 Extended the new FtpReply class to handle various directory listing styles and to ask for a username and password, if the FTP login fails with an error code of 530.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2044
diff changeset
371 if mtype:
739aa1717df5 Extended the new FtpReply class to handle various directory listing styles and to ask for a username and password, if the FTP login fails with an error code of 530.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2044
diff changeset
372 self.setHeader(QNetworkRequest.ContentTypeHeader, mtype)
278
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
373 self.setAttribute(QNetworkRequest.HttpStatusCodeAttribute, 200)
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
374 self.setAttribute(QNetworkRequest.HttpReasonPhraseAttribute, "Ok")
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
375 self.metaDataChanged.emit()
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
376
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 826
diff changeset
377 def __cssLinkClass(self, icon, size=32):
278
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
378 """
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
379 Private method to generate a link class with an icon.
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
380
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
381 @param icon icon to be included (QIcon)
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
382 @param size size of the icon to be generated (integer)
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
383 @return CSS class string (string)
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
384 """
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
385 cssString = \
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
386 """a.{{0}} {{{{\n"""\
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
387 """ padding-left: {0}px;\n"""\
3002
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
388 """ background: transparent url(data:image/png;base64,{1})"""\
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
389 """ no-repeat center left;\n"""\
278
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
390 """ font-weight: bold;\n"""\
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
391 """}}}}\n"""
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
392 pixmap = icon.pixmap(size, size)
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
393 imageBuffer = QBuffer()
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
394 imageBuffer.open(QIODevice.ReadWrite)
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
395 if not pixmap.save(imageBuffer, "PNG"):
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
396 # write a blank pixmap on error
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
397 pixmap = QPixmap(size, size)
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
398 pixmap.fill(Qt.transparent)
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
399 imageBuffer.buffer().clear()
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
400 pixmap.save(imageBuffer, "PNG")
3022
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3002
diff changeset
401 return cssString.format(
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3002
diff changeset
402 size + 4,
278
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
403 str(imageBuffer.buffer().toBase64(), encoding="ascii"))
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
404
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
405 def __setListContent(self):
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
406 """
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
407 Private method to prepare the content for the reader.
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
408 """
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
409 u = self.url()
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
410 if not u.path().endswith("/"):
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
411 u.setPath(u.path() + "/")
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
412
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
413 baseUrl = self.url().toString()
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
414 basePath = u.path()
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
415
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
416 linkClasses = {}
3002
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
417 iconSize = QWebSettings.globalSettings().fontSize(
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
418 QWebSettings.DefaultFontSize)
278
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
419
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
420 parent = u.resolved(QUrl(".."))
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
421 if parent.isParentOf(u):
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
422 icon = UI.PixmapCache.getIcon("up.png")
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
423 linkClasses["link_parent"] = \
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
424 self.__cssLinkClass(icon, iconSize).format("link_parent")
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
425 parentStr = self.tr(
278
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
426 """ <p><a class="link_parent" href="{0}">"""
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
427 """Change to parent directory</a></p>"""
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
428 ).format(parent.toString())
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
429 else:
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
430 parentStr = ""
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
431
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
432 row = \
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
433 """ <tr class="{0}">"""\
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
434 """<td class="name"><a class="{1}" href="{2}">{3}</a></td>"""\
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
435 """<td class="size">{4}</td>"""\
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
436 """<td class="modified">{5}</td>"""\
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
437 """</tr>\n"""
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
438 table = self.tr(
278
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
439 """ <tr>"""
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
440 """<th align="left">Name</th>"""
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
441 """<th>Size</th>"""
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
442 """<th align="left">Last modified</th>"""
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
443 """</tr>\n"""
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
444 )
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
445
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
446 i = 0
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
447 for item in self.__items:
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
448 name = item.name()
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
449 if item.isDir() and not name.endswith("/"):
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
450 name += "/"
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
451 child = u.resolved(QUrl(name.replace(":", "%3A")))
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
452
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
453 if item.isFile():
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
454 size = item.size()
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
455 unit = 0
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
456 while size:
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
457 newSize = size // 1024
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
458 if newSize and unit < len(self.__units):
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
459 size = newSize
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
460 unit += 1
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
461 else:
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
462 break
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
463
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
464 sizeStr = self.tr("{0} {1}", "size unit")\
278
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
465 .format(size, self.__units[unit])
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
466 linkClass = "link_file"
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
467 if linkClass not in linkClasses:
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
468 icon = UI.PixmapCache.getIcon("fileMisc.png")
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
469 linkClasses[linkClass] = \
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
470 self.__cssLinkClass(icon, iconSize).format(linkClass)
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
471 else:
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
472 sizeStr = ""
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
473 linkClass = "link_dir"
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
474 if linkClass not in linkClasses:
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
475 icon = UI.PixmapCache.getIcon("dirClosed.png")
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
476 linkClasses[linkClass] = \
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
477 self.__cssLinkClass(icon, iconSize).format(linkClass)
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
478 table += row.format(
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
479 i == 0 and "odd" or "even",
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 826
diff changeset
480 linkClass,
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 826
diff changeset
481 child.toString(),
2080
4b33165dd55b Made the third set of Qt5 compatibility changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2074
diff changeset
482 Utilities.html_encode(item.name()),
278
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
483 sizeStr,
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 826
diff changeset
484 item.lastModified().toString("yyyy-MM-dd hh:mm"),
278
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
485 )
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
486 i = 1 - i
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
487
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
488 content = ftpListPage_html.format(
2080
4b33165dd55b Made the third set of Qt5 compatibility changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2074
diff changeset
489 Utilities.html_encode(baseUrl),
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 826
diff changeset
490 "".join(linkClasses.values()),
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
491 self.tr("Listing of {0}").format(basePath),
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 826
diff changeset
492 parentStr,
278
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
493 table
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
494 )
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
495 self.__content = QByteArray(content.encode("utf8"))
2044
9d229b584c49 Change the FtpReply class to use Python ftplib instead of QFtp because the later is not available in Qt5 anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1625
diff changeset
496 self.__content.append(512 * b' ')
278
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
497
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
498 self.open(QIODevice.ReadOnly | QIODevice.Unbuffered)
3002
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
499 self.setHeader(
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
500 QNetworkRequest.ContentTypeHeader, "text/html; charset=UTF-8")
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
501 self.setHeader(
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
502 QNetworkRequest.ContentLengthHeader, self.__content.size())
278
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
503 self.setAttribute(QNetworkRequest.HttpStatusCodeAttribute, 200)
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
504 self.setAttribute(QNetworkRequest.HttpReasonPhraseAttribute, "Ok")
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
505 self.metaDataChanged.emit()
3002
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
506 self.downloadProgress.emit(
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
507 self.__content.size(), self.__content.size())
278
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
508 self.readyRead.emit()

eric ide

mercurial