Wed, 09 Oct 2013 18:34:30 +0200
Continued to shorten the code lines to max. 79 characters.
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:
diff
changeset
|
1 | # -*- coding: utf-8 -*- |
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:
diff
changeset
|
2 | |
2302
f29e9405c851
Updated copyright for 2013.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2077
diff
changeset
|
3 | # Copyright (c) 2012 - 2013 Detlev Offenbach <detlev@die-offenbachs.de> |
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:
diff
changeset
|
4 | # |
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:
diff
changeset
|
5 | |
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:
diff
changeset
|
6 | """ |
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:
diff
changeset
|
7 | Module implementing some FTP related utilities. |
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:
diff
changeset
|
8 | """ |
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:
diff
changeset
|
9 | |
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
|
10 | import os |
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
|
11 | |
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:
diff
changeset
|
12 | from PyQt4.QtCore import QObject, QDate, QDateTime, QTime |
2077
68a34718a0ce
Made the first set of Qt5 compatibility changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2052
diff
changeset
|
13 | |
68a34718a0ce
Made the first set of Qt5 compatibility changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2052
diff
changeset
|
14 | from E5Network.E5UrlInfo import E5UrlInfo |
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:
diff
changeset
|
15 | |
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:
diff
changeset
|
16 | |
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:
diff
changeset
|
17 | class FtpDirLineParserError(Exception): |
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:
diff
changeset
|
18 | """ |
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:
diff
changeset
|
19 | Exception class raised, if a parser issue was detected. |
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:
diff
changeset
|
20 | """ |
2965
d133c7edd88a
Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2302
diff
changeset
|
21 | pass |
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:
diff
changeset
|
22 | |
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:
diff
changeset
|
23 | |
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:
diff
changeset
|
24 | class FtpDirLineParser(QObject): |
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:
diff
changeset
|
25 | """ |
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:
diff
changeset
|
26 | Class to parse lines returned by a FTP LIST command. |
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:
diff
changeset
|
27 | """ |
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:
diff
changeset
|
28 | MonthnamesNumbers = { |
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:
diff
changeset
|
29 | "jan": 1, |
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:
diff
changeset
|
30 | "feb": 2, |
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:
diff
changeset
|
31 | "mar": 3, |
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:
diff
changeset
|
32 | "apr": 4, |
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:
diff
changeset
|
33 | "may": 5, |
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:
diff
changeset
|
34 | "jun": 6, |
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:
diff
changeset
|
35 | "jul": 7, |
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:
diff
changeset
|
36 | "aug": 8, |
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:
diff
changeset
|
37 | "sep": 9, |
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:
diff
changeset
|
38 | "oct": 10, |
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:
diff
changeset
|
39 | "nov": 11, |
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:
diff
changeset
|
40 | "dec": 12, |
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:
diff
changeset
|
41 | } |
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:
diff
changeset
|
42 | |
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:
diff
changeset
|
43 | UnixMode = 0 |
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:
diff
changeset
|
44 | WindowsMode = 1 |
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:
diff
changeset
|
45 | MacMode = 2 |
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:
diff
changeset
|
46 | |
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:
diff
changeset
|
47 | def __init__(self, parent=None): |
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:
diff
changeset
|
48 | """ |
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:
diff
changeset
|
49 | Constructor |
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:
diff
changeset
|
50 | |
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:
diff
changeset
|
51 | @param parent reference to the parent object (QObject) |
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:
diff
changeset
|
52 | """ |
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:
diff
changeset
|
53 | super().__init__(parent) |
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:
diff
changeset
|
54 | |
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:
diff
changeset
|
55 | self.__parseLine = self.__parseUnixLine |
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:
diff
changeset
|
56 | self.__modeSwitchAllowed = True |
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:
diff
changeset
|
57 | |
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:
diff
changeset
|
58 | def __ignoreLine(self, 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:
diff
changeset
|
59 | """ |
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:
diff
changeset
|
60 | Private method to check, if the line should be ignored. |
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:
diff
changeset
|
61 | |
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:
diff
changeset
|
62 | @param line to check (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:
diff
changeset
|
63 | @return flag indicating to ignore the line (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:
diff
changeset
|
64 | """ |
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:
diff
changeset
|
65 | return line.strip() == "" or \ |
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:
diff
changeset
|
66 | line.strip().lower().startswith("total ") |
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:
diff
changeset
|
67 | |
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:
diff
changeset
|
68 | def __parseUnixMode(self, modeString, 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:
diff
changeset
|
69 | """ |
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:
diff
changeset
|
70 | Private method to parse a Unix mode string modifying the |
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:
diff
changeset
|
71 | given URL info object. |
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:
diff
changeset
|
72 | |
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:
diff
changeset
|
73 | @param modeString mode string to be parsed (string) |
2077
68a34718a0ce
Made the first set of Qt5 compatibility changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2052
diff
changeset
|
74 | @param urlInfo reference to the URL info object (E5UrlInfo) |
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:
diff
changeset
|
75 | @exception FtpDirLineParserError Raised if the mode cannot be parsed. |
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:
diff
changeset
|
76 | """ |
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:
diff
changeset
|
77 | if len(modeString) != 10: |
2997
7f0ef975da9e
Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2965
diff
changeset
|
78 | raise FtpDirLineParserError( |
7f0ef975da9e
Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2965
diff
changeset
|
79 | "invalid mode string '{0}'".format(modeString)) |
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:
diff
changeset
|
80 | |
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:
diff
changeset
|
81 | modeString = modeString.lower() |
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:
diff
changeset
|
82 | |
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:
diff
changeset
|
83 | permission = 0 |
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:
diff
changeset
|
84 | if modeString[1] != '-': |
2077
68a34718a0ce
Made the first set of Qt5 compatibility changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2052
diff
changeset
|
85 | permission |= E5UrlInfo.ReadOwner |
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:
diff
changeset
|
86 | if modeString[2] != '-': |
2077
68a34718a0ce
Made the first set of Qt5 compatibility changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2052
diff
changeset
|
87 | permission |= E5UrlInfo.WriteOwner |
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:
diff
changeset
|
88 | if modeString[3] != '-': |
2077
68a34718a0ce
Made the first set of Qt5 compatibility changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2052
diff
changeset
|
89 | permission |= E5UrlInfo.ExeOwner |
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:
diff
changeset
|
90 | if modeString[4] != '-': |
2077
68a34718a0ce
Made the first set of Qt5 compatibility changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2052
diff
changeset
|
91 | permission |= E5UrlInfo.ReadGroup |
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:
diff
changeset
|
92 | if modeString[5] != '-': |
2077
68a34718a0ce
Made the first set of Qt5 compatibility changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2052
diff
changeset
|
93 | permission |= E5UrlInfo.WriteGroup |
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:
diff
changeset
|
94 | if modeString[6] != '-': |
2077
68a34718a0ce
Made the first set of Qt5 compatibility changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2052
diff
changeset
|
95 | permission |= E5UrlInfo.ExeGroup |
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:
diff
changeset
|
96 | if modeString[7] != '-': |
2077
68a34718a0ce
Made the first set of Qt5 compatibility changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2052
diff
changeset
|
97 | permission |= E5UrlInfo.ReadOther |
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:
diff
changeset
|
98 | if modeString[8] != '-': |
2077
68a34718a0ce
Made the first set of Qt5 compatibility changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2052
diff
changeset
|
99 | permission |= E5UrlInfo.WriteOther |
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:
diff
changeset
|
100 | if modeString[9] != '-': |
2077
68a34718a0ce
Made the first set of Qt5 compatibility changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2052
diff
changeset
|
101 | permission |= E5UrlInfo.ExeOther |
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:
diff
changeset
|
102 | urlInfo.setPermissions(permission) |
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:
diff
changeset
|
103 | |
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:
diff
changeset
|
104 | if modeString[0] == "d": |
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:
diff
changeset
|
105 | urlInfo.setDir(True) |
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:
diff
changeset
|
106 | urlInfo.setFile(False) |
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
|
107 | urlInfo.setSymLink(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:
diff
changeset
|
108 | elif modeString[0] == "l": |
2052
b89c21c96127
Fixed an error in the FTP utilities.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2051
diff
changeset
|
109 | urlInfo.setDir(True) |
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
|
110 | urlInfo.setFile(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:
diff
changeset
|
111 | urlInfo.setSymLink(True) |
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:
diff
changeset
|
112 | elif modeString[0] == "-": |
2052
b89c21c96127
Fixed an error in the FTP utilities.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2051
diff
changeset
|
113 | urlInfo.setDir(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:
diff
changeset
|
114 | urlInfo.setFile(True) |
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
|
115 | urlInfo.setSymLink(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:
diff
changeset
|
116 | |
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:
diff
changeset
|
117 | def __parseUnixTime(self, monthAbbreviation, day, yearOrTime, 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:
diff
changeset
|
118 | """ |
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:
diff
changeset
|
119 | Private method to parse a Unix date and time indication modifying |
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:
diff
changeset
|
120 | the given URL info object. |
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:
diff
changeset
|
121 | |
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:
diff
changeset
|
122 | |
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:
diff
changeset
|
123 | Date time strings in Unix-style directory listings typically |
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:
diff
changeset
|
124 | have one of these formats: |
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:
diff
changeset
|
125 | <ul> |
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:
diff
changeset
|
126 | <li>"Nov 23 02:33" (month name, day of month, time)</li> |
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:
diff
changeset
|
127 | <li>"May 26 2005" (month name, day of month, year)</li> |
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:
diff
changeset
|
128 | </ul> |
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:
diff
changeset
|
129 | |
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:
diff
changeset
|
130 | @param monthAbbreviation abbreviation of the month name (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:
diff
changeset
|
131 | @param day day of the month (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:
diff
changeset
|
132 | @param yearOrTime string giving the year or a time (string) |
2077
68a34718a0ce
Made the first set of Qt5 compatibility changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2052
diff
changeset
|
133 | @param urlInfo reference to the URL info object (E5UrlInfo) |
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:
diff
changeset
|
134 | @exception FtpDirLineParserError Raised if the month abbreviation is |
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:
diff
changeset
|
135 | not recognized. |
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:
diff
changeset
|
136 | """ |
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:
diff
changeset
|
137 | try: |
2997
7f0ef975da9e
Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2965
diff
changeset
|
138 | month = FtpDirLineParser.MonthnamesNumbers[ |
7f0ef975da9e
Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2965
diff
changeset
|
139 | monthAbbreviation.lower()] |
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:
diff
changeset
|
140 | except KeyError: |
2997
7f0ef975da9e
Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2965
diff
changeset
|
141 | raise FtpDirLineParserError( |
7f0ef975da9e
Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2965
diff
changeset
|
142 | "illegal month abbreviation '{0}'".format( |
7f0ef975da9e
Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2965
diff
changeset
|
143 | monthAbbreviation)) |
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:
diff
changeset
|
144 | day = int(day) |
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:
diff
changeset
|
145 | if ':' in yearOrTime: |
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:
diff
changeset
|
146 | year = QDate.currentDate().year() |
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:
diff
changeset
|
147 | hour, minute = yearOrTime.split(':') |
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:
diff
changeset
|
148 | hour = int(hour) |
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:
diff
changeset
|
149 | minute = int(minute) |
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:
diff
changeset
|
150 | 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:
diff
changeset
|
151 | year = int(yearOrTime) |
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:
diff
changeset
|
152 | hour = 0 |
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:
diff
changeset
|
153 | minute = 0 |
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:
diff
changeset
|
154 | |
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:
diff
changeset
|
155 | lastModified = QDateTime(QDate(year, month, day), QTime(hour, minute)) |
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:
diff
changeset
|
156 | urlInfo.setLastModified(lastModified) |
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:
diff
changeset
|
157 | |
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:
diff
changeset
|
158 | def __splitUnixLine(self, 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:
diff
changeset
|
159 | """ |
2965
d133c7edd88a
Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2302
diff
changeset
|
160 | Private method to split a line of a Unix like directory listing. |
d133c7edd88a
Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2302
diff
changeset
|
161 | |
d133c7edd88a
Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2302
diff
changeset
|
162 | It splits the line into meta data, number of links, user, group, size, |
d133c7edd88a
Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2302
diff
changeset
|
163 | month, day, year or time and name. |
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:
diff
changeset
|
164 | |
2965
d133c7edd88a
Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2302
diff
changeset
|
165 | @param line directory line to split (string) |
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:
diff
changeset
|
166 | @return tuple of nine strings giving the meta data, |
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:
diff
changeset
|
167 | number of links, user, group, size, month, day, year or time |
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:
diff
changeset
|
168 | and name |
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:
diff
changeset
|
169 | @exception FtpDirLineParserError Raised if the line is not of a |
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:
diff
changeset
|
170 | recognized Unix format. |
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:
diff
changeset
|
171 | """ |
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:
diff
changeset
|
172 | # This method encapsulates the recognition of an unusual |
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:
diff
changeset
|
173 | # Unix format variant. |
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:
diff
changeset
|
174 | lineParts = line.split() |
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:
diff
changeset
|
175 | fieldCountWithoutUserID = 8 |
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:
diff
changeset
|
176 | fieldCountWithUserID = fieldCountWithoutUserID + 1 |
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:
diff
changeset
|
177 | if len(lineParts) < fieldCountWithoutUserID: |
2997
7f0ef975da9e
Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2965
diff
changeset
|
178 | raise FtpDirLineParserError( |
7f0ef975da9e
Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2965
diff
changeset
|
179 | "line '{0}' cannot be parsed".format(line)) |
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:
diff
changeset
|
180 | |
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:
diff
changeset
|
181 | # If we have a valid format (either with or without user id field), |
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:
diff
changeset
|
182 | # the field with index 5 is either the month abbreviation or a day. |
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:
diff
changeset
|
183 | 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:
diff
changeset
|
184 | int(lineParts[5]) |
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:
diff
changeset
|
185 | except ValueError: |
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:
diff
changeset
|
186 | # Month abbreviation, "invalid literal for int" |
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:
diff
changeset
|
187 | lineParts = line.split(None, fieldCountWithUserID - 1) |
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:
diff
changeset
|
188 | 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:
diff
changeset
|
189 | # Day |
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:
diff
changeset
|
190 | lineParts = line.split(None, fieldCountWithoutUserID - 1) |
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:
diff
changeset
|
191 | userFieldIndex = 2 |
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:
diff
changeset
|
192 | lineParts.insert(userFieldIndex, "") |
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:
diff
changeset
|
193 | |
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:
diff
changeset
|
194 | return lineParts |
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:
diff
changeset
|
195 | |
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:
diff
changeset
|
196 | def __parseUnixLine(self, 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:
diff
changeset
|
197 | """ |
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:
diff
changeset
|
198 | Private method to parse a Unix style directory listing 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:
diff
changeset
|
199 | |
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:
diff
changeset
|
200 | @param line directory line to be parsed (string) |
2077
68a34718a0ce
Made the first set of Qt5 compatibility changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2052
diff
changeset
|
201 | @return URL info object containing the valid data (E5UrlInfo) |
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:
diff
changeset
|
202 | """ |
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:
diff
changeset
|
203 | modeString, nlink, user, group, size, month, day, \ |
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:
diff
changeset
|
204 | yearOrTime, name = self.__splitUnixLine(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:
diff
changeset
|
205 | |
2051
644d5a2585a8
Changed the FTP directory parser to omit the '.' and '..' directories.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2050
diff
changeset
|
206 | if name in [".", ".."]: |
644d5a2585a8
Changed the FTP directory parser to omit the '.' and '..' directories.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2050
diff
changeset
|
207 | return None |
644d5a2585a8
Changed the FTP directory parser to omit the '.' and '..' directories.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2050
diff
changeset
|
208 | |
2077
68a34718a0ce
Made the first set of Qt5 compatibility changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2052
diff
changeset
|
209 | urlInfo = E5UrlInfo() |
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:
diff
changeset
|
210 | self.__parseUnixMode(modeString, 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:
diff
changeset
|
211 | self.__parseUnixTime(month, day, yearOrTime, 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:
diff
changeset
|
212 | urlInfo.setOwner(user) |
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:
diff
changeset
|
213 | urlInfo.setGroup(group) |
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:
diff
changeset
|
214 | urlInfo.setSize(int(size)) |
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:
diff
changeset
|
215 | name = name.strip() |
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:
diff
changeset
|
216 | i = name.find(" -> ") |
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:
diff
changeset
|
217 | if i >= 0: |
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:
diff
changeset
|
218 | name = name[:i] |
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:
diff
changeset
|
219 | urlInfo.setName(name) |
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:
diff
changeset
|
220 | |
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:
diff
changeset
|
221 | return 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:
diff
changeset
|
222 | |
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:
diff
changeset
|
223 | def __parseWindowsTime(self, date, time, 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:
diff
changeset
|
224 | """ |
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:
diff
changeset
|
225 | Private method to parse a Windows date and time indication modifying |
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:
diff
changeset
|
226 | the given URL info object. |
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:
diff
changeset
|
227 | |
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:
diff
changeset
|
228 | Date time strings in Windows-style directory listings typically |
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:
diff
changeset
|
229 | have the format "10-23-12 03:25PM" (month-day_of_month-two_digit_year, |
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:
diff
changeset
|
230 | hour:minute, am/pm). |
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:
diff
changeset
|
231 | |
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:
diff
changeset
|
232 | @param date date string (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:
diff
changeset
|
233 | @param time time string (string) |
2077
68a34718a0ce
Made the first set of Qt5 compatibility changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2052
diff
changeset
|
234 | @param urlInfo reference to the URL info object (E5UrlInfo) |
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:
diff
changeset
|
235 | @exception FtpDirLineParserError Raised if either of the strings is not |
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:
diff
changeset
|
236 | recognized. |
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:
diff
changeset
|
237 | """ |
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:
diff
changeset
|
238 | 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:
diff
changeset
|
239 | month, day, year = [int(part) for part in date.split('-')] |
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:
diff
changeset
|
240 | if year >= 70: |
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:
diff
changeset
|
241 | year = 1900 + year |
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:
diff
changeset
|
242 | 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:
diff
changeset
|
243 | year = 2000 + year |
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:
diff
changeset
|
244 | except (ValueError, IndexError): |
2997
7f0ef975da9e
Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2965
diff
changeset
|
245 | raise FtpDirLineParserError( |
7f0ef975da9e
Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2965
diff
changeset
|
246 | "illegal date string '{0}'".format(month)) |
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:
diff
changeset
|
247 | 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:
diff
changeset
|
248 | hour, minute, am_pm = time[0:2], time[3:5], time[5] |
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:
diff
changeset
|
249 | hour = int(hour) |
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:
diff
changeset
|
250 | minute = int(minute) |
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:
diff
changeset
|
251 | except (ValueError, IndexError): |
2997
7f0ef975da9e
Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2965
diff
changeset
|
252 | raise FtpDirLineParserError( |
7f0ef975da9e
Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2965
diff
changeset
|
253 | "illegal time string '{0}'".format(month)) |
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:
diff
changeset
|
254 | if hour == 12 and am_pm == 'A': |
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:
diff
changeset
|
255 | hour = 0 |
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:
diff
changeset
|
256 | if hour != 12 and am_pm == 'P': |
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:
diff
changeset
|
257 | hour = hour + 12 |
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:
diff
changeset
|
258 | |
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:
diff
changeset
|
259 | lastModified = QDateTime(QDate(year, month, day), QTime(hour, minute)) |
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:
diff
changeset
|
260 | urlInfo.setLastModified(lastModified) |
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:
diff
changeset
|
261 | |
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:
diff
changeset
|
262 | def __parseWindowsLine(self, 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:
diff
changeset
|
263 | """ |
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:
diff
changeset
|
264 | Private method to parse a Windows style directory listing 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:
diff
changeset
|
265 | |
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:
diff
changeset
|
266 | @param line directory line to be parsed (string) |
2077
68a34718a0ce
Made the first set of Qt5 compatibility changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2052
diff
changeset
|
267 | @return URL info object containing the valid data (E5UrlInfo) |
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:
diff
changeset
|
268 | @exception FtpDirLineParserError Raised if the line is not of a |
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:
diff
changeset
|
269 | recognized Windows format. |
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:
diff
changeset
|
270 | """ |
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:
diff
changeset
|
271 | 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:
diff
changeset
|
272 | date, time, dirOrSize, name = line.split(None, 3) |
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:
diff
changeset
|
273 | except ValueError: |
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:
diff
changeset
|
274 | # "unpack list of wrong size" |
2997
7f0ef975da9e
Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2965
diff
changeset
|
275 | raise FtpDirLineParserError( |
7f0ef975da9e
Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2965
diff
changeset
|
276 | "line '{0}' cannot be parsed".format(line)) |
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:
diff
changeset
|
277 | |
2051
644d5a2585a8
Changed the FTP directory parser to omit the '.' and '..' directories.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2050
diff
changeset
|
278 | if name in [".", ".."]: |
644d5a2585a8
Changed the FTP directory parser to omit the '.' and '..' directories.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2050
diff
changeset
|
279 | return None |
644d5a2585a8
Changed the FTP directory parser to omit the '.' and '..' directories.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2050
diff
changeset
|
280 | |
2077
68a34718a0ce
Made the first set of Qt5 compatibility changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2052
diff
changeset
|
281 | urlInfo = E5UrlInfo() |
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:
diff
changeset
|
282 | self.__parseWindowsTime(date, time, 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:
diff
changeset
|
283 | if dirOrSize.lower() == "<dir>": |
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:
diff
changeset
|
284 | urlInfo.setDir(True) |
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:
diff
changeset
|
285 | urlInfo.setFile(False) |
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:
diff
changeset
|
286 | 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:
diff
changeset
|
287 | urlInfo.setDir(False) |
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:
diff
changeset
|
288 | urlInfo.setFile(True) |
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:
diff
changeset
|
289 | 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:
diff
changeset
|
290 | urlInfo.setSize(int(dirOrSize)) |
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:
diff
changeset
|
291 | except ValueError: |
2997
7f0ef975da9e
Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2965
diff
changeset
|
292 | raise FtpDirLineParserError( |
7f0ef975da9e
Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2965
diff
changeset
|
293 | "illegal size '{0}'".format(dirOrSize)) |
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:
diff
changeset
|
294 | urlInfo.setName(name) |
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:
diff
changeset
|
295 | |
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
|
296 | ext = os.path.splitext(name.lower())[1] |
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
|
297 | urlInfo.setSymLink(ext == ".lnk") |
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
|
298 | |
2077
68a34718a0ce
Made the first set of Qt5 compatibility changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2052
diff
changeset
|
299 | permissions = (E5UrlInfo.ReadOwner | E5UrlInfo.WriteOwner |
68a34718a0ce
Made the first set of Qt5 compatibility changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2052
diff
changeset
|
300 | | E5UrlInfo.ReadGroup | E5UrlInfo.WriteGroup |
68a34718a0ce
Made the first set of Qt5 compatibility changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2052
diff
changeset
|
301 | | E5UrlInfo.ReadOther | E5UrlInfo.WriteOther) |
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
|
302 | if ext in [".exe", ".com", ".bat", ".cmd"]: |
2997
7f0ef975da9e
Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2965
diff
changeset
|
303 | permissions |= E5UrlInfo.ExeOwner | E5UrlInfo.ExeGroup | \ |
7f0ef975da9e
Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2965
diff
changeset
|
304 | E5UrlInfo.ExeOther |
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
|
305 | urlInfo.setPermissions(permissions) |
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
|
306 | |
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:
diff
changeset
|
307 | return 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:
diff
changeset
|
308 | |
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:
diff
changeset
|
309 | def parseLine(self, 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:
diff
changeset
|
310 | """ |
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:
diff
changeset
|
311 | Private method to parse a directory listing 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:
diff
changeset
|
312 | |
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:
diff
changeset
|
313 | This implementation support Unix and Windows style directory |
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:
diff
changeset
|
314 | listings. It tries Unix style first and if that fails switches |
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:
diff
changeset
|
315 | to Windows style. If that fails as well, an exception is raised. |
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:
diff
changeset
|
316 | |
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:
diff
changeset
|
317 | @param line directory line to be parsed (string) |
2077
68a34718a0ce
Made the first set of Qt5 compatibility changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2052
diff
changeset
|
318 | @return URL info object containing the valid data (E5UrlInfo) |
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:
diff
changeset
|
319 | """ |
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:
diff
changeset
|
320 | if self.__ignoreLine(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:
diff
changeset
|
321 | return None |
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:
diff
changeset
|
322 | |
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:
diff
changeset
|
323 | 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:
diff
changeset
|
324 | return self.__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:
diff
changeset
|
325 | 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:
diff
changeset
|
326 | if self.__modeSwitchAllowed: |
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:
diff
changeset
|
327 | self.__parseLine = self.__parseWindowsLine |
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:
diff
changeset
|
328 | self.__modeSwitchAllowed = False |
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:
diff
changeset
|
329 | return self.__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:
diff
changeset
|
330 | 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:
diff
changeset
|
331 | raise |