Thu, 20 Sep 2012 20:09:51 +0200
Fixed an error in the FTP utilities.
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 | |
739aa1717df5
Extended the new FtpReply class to handle various directory listing styles and to ask for a username and password, if the FTP login fails with an error code of 530.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
3 | # Copyright (c) 2012 Detlev Offenbach <detlev@die-offenbachs.de> |
739aa1717df5
Extended the new FtpReply class to handle various directory listing styles and to ask for 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 |
739aa1717df5
Extended the new FtpReply class to handle various directory listing styles and to ask for a username and password, if the FTP login fails with an error code of 530.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
13 | from PyQt4.QtNetwork import QUrlInfo |
739aa1717df5
Extended the new FtpReply class to handle various directory listing styles and to ask for a username and password, if the FTP login fails with an error code of 530.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
14 | |
739aa1717df5
Extended the new FtpReply class to handle various directory listing styles and to ask for 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 | 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
|
17 | """ |
739aa1717df5
Extended the new FtpReply class to handle various directory listing styles and to ask for 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 | 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
|
19 | """ |
739aa1717df5
Extended the new FtpReply class to handle various directory listing styles and to ask for 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 | |
739aa1717df5
Extended the new FtpReply class to handle various directory listing styles and to ask for a username and password, if the FTP login fails with an error code of 530.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
21 | |
739aa1717df5
Extended the new FtpReply class to handle various directory listing styles and to ask for 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 | 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
|
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 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
|
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 | 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
|
27 | "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
|
28 | "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
|
29 | "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
|
30 | "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
|
31 | "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
|
32 | "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
|
33 | "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
|
34 | "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
|
35 | "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
|
36 | "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
|
37 | "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
|
38 | "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
|
39 | } |
739aa1717df5
Extended the new FtpReply class to handle various directory listing styles and to ask for 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 | |
739aa1717df5
Extended the new FtpReply class to handle various directory listing styles and to ask for 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 | 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
|
42 | 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
|
43 | 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
|
44 | |
739aa1717df5
Extended the new FtpReply class to handle various directory listing styles and to ask for 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 | 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
|
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 | 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
|
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 | @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
|
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 | 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
|
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 | 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
|
54 | 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
|
55 | |
739aa1717df5
Extended the new FtpReply class to handle various directory listing styles and to ask for 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 | 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
|
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 | 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
|
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 | @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
|
61 | @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
|
62 | """ |
739aa1717df5
Extended the new FtpReply class to handle various directory listing styles and to ask for 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 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
|
64 | 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
|
65 | |
739aa1717df5
Extended the new FtpReply class to handle various directory listing styles and to ask for 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 | 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
|
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 | 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
|
69 | 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
|
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
|
71 | @param modeString mode string to be parsed (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
|
72 | @param urlInfo reference to the URL info object (QUrlInfo) |
739aa1717df5
Extended the new FtpReply class to handle various directory listing styles and to ask for 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 | @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
|
74 | """ |
739aa1717df5
Extended the new FtpReply class to handle various directory listing styles and to ask for 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 | if len(modeString) != 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
|
76 | raise FtpDirLineParserError("invalid mode string '{0}'".format(modeString)) |
739aa1717df5
Extended the new FtpReply class to handle various directory listing styles and to ask for 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 | |
739aa1717df5
Extended the new FtpReply class to handle various directory listing styles and to ask for a username and password, if the FTP login fails with an error code of 530.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
78 | 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
|
79 | |
739aa1717df5
Extended the new FtpReply class to handle various directory listing styles and to ask for 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 | 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
|
81 | if modeString[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
|
82 | permission |= QUrlInfo.ReadOwner |
739aa1717df5
Extended the new FtpReply class to handle various directory listing styles and to ask for 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 | if modeString[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
|
84 | permission |= QUrlInfo.WriteOwner |
739aa1717df5
Extended the new FtpReply class to handle various directory listing styles and to ask for a username and password, if the FTP login fails with an error code of 530.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
85 | if modeString[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
|
86 | permission |= QUrlInfo.ExeOwner |
739aa1717df5
Extended the new FtpReply class to handle various directory listing styles and to ask for a username and password, if the FTP login fails with an error code of 530.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
87 | if modeString[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
|
88 | permission |= QUrlInfo.ReadGroup |
739aa1717df5
Extended the new FtpReply class to handle various directory listing styles and to ask for a username and password, if the FTP login fails with an error code of 530.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
89 | if modeString[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
|
90 | permission |= QUrlInfo.WriteGroup |
739aa1717df5
Extended the new FtpReply class to handle various directory listing styles and to ask for a username and password, if the FTP login fails with an error code of 530.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
91 | if modeString[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
|
92 | permission |= QUrlInfo.ExeGroup |
739aa1717df5
Extended the new FtpReply class to handle various directory listing styles and to ask for a username and password, if the FTP login fails with an error code of 530.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
93 | if modeString[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
|
94 | permission |= QUrlInfo.ReadOther |
739aa1717df5
Extended the new FtpReply class to handle various directory listing styles and to ask for a username and password, if the FTP login fails with an error code of 530.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
95 | if modeString[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
|
96 | permission |= QUrlInfo.WriteOther |
739aa1717df5
Extended the new FtpReply class to handle various directory listing styles and to ask for a username and password, if the FTP login fails with an error code of 530.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
97 | if modeString[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
|
98 | permission |= QUrlInfo.ExeOther |
739aa1717df5
Extended the new FtpReply class to handle various directory listing styles and to ask for a username and password, if the FTP login fails with an error code of 530.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
99 | 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
|
100 | |
739aa1717df5
Extended the new FtpReply class to handle various directory listing styles and to ask for a username and password, if the FTP login fails with an error code of 530.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
101 | 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
|
102 | 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
|
103 | 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
|
104 | 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
|
105 | elif modeString[0] == "l": |
2052
b89c21c96127
Fixed an error in the FTP utilities.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2051
diff
changeset
|
106 | 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
|
107 | 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
|
108 | 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
|
109 | elif modeString[0] == "-": |
2052
b89c21c96127
Fixed an error in the FTP utilities.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2051
diff
changeset
|
110 | 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
|
111 | 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
|
112 | 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
|
113 | |
739aa1717df5
Extended the new FtpReply class to handle various directory listing styles and to ask for 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 | 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
|
115 | """ |
739aa1717df5
Extended the new FtpReply class to handle various directory listing styles and to ask for 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 | 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
|
117 | 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
|
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 | |
739aa1717df5
Extended the new FtpReply class to handle various directory listing styles and to ask for 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 | 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
|
121 | 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
|
122 | <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
|
123 | <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
|
124 | <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
|
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 | |
739aa1717df5
Extended the new FtpReply class to handle various directory listing styles and to ask for 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 | @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
|
128 | @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
|
129 | @param yearOrTime string giving the year or a time (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
|
130 | @param urlInfo reference to the URL info object (QUrlInfo) |
739aa1717df5
Extended the new FtpReply class to handle various directory listing styles and to ask for 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 | @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
|
132 | 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
|
133 | """ |
739aa1717df5
Extended the new FtpReply class to handle various directory listing styles and to ask for 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 | 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
|
135 | month = FtpDirLineParser.MonthnamesNumbers[monthAbbreviation.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
|
136 | except KeyError: |
739aa1717df5
Extended the new FtpReply class to handle various directory listing styles and to ask for 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 | raise FtpDirLineParserError("illegal month abbreviation '{0}'".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
|
138 | monthAbbreviation)) |
739aa1717df5
Extended the new FtpReply class to handle various directory listing styles and to ask for a username and password, if the FTP login fails with an error code of 530.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
139 | 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
|
140 | 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
|
141 | 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
|
142 | 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
|
143 | 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
|
144 | 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
|
145 | 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
|
146 | 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
|
147 | 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
|
148 | 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
|
149 | |
739aa1717df5
Extended the new FtpReply class to handle various directory listing styles and to ask for 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 | 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
|
151 | 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
|
152 | |
739aa1717df5
Extended the new FtpReply class to handle various directory listing styles and to ask for 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 | 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
|
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 | Split a line of a Unix like directory listing into 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
|
156 | 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
|
157 | 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
|
158 | |
739aa1717df5
Extended the new FtpReply class to handle various directory listing styles and to ask for 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 | @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
|
160 | 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
|
161 | 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
|
162 | @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
|
163 | 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
|
164 | """ |
739aa1717df5
Extended the new FtpReply class to handle various directory listing styles and to ask for a username and password, if the FTP login fails with an error code of 530.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
165 | # 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
|
166 | # 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
|
167 | 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
|
168 | 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
|
169 | 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
|
170 | if len(lineParts) < fieldCountWithoutUserID: |
739aa1717df5
Extended the new FtpReply class to handle various directory listing styles and to ask for 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 | raise FtpDirLineParserError("line '{0}' cannot be parsed".format(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
|
172 | |
739aa1717df5
Extended the new FtpReply class to handle various directory listing styles and to ask for 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 | # 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
|
174 | # 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
|
175 | 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
|
176 | 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
|
177 | 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
|
178 | # 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
|
179 | 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
|
180 | 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
|
181 | # 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
|
182 | 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
|
183 | 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
|
184 | 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
|
185 | |
739aa1717df5
Extended the new FtpReply class to handle various directory listing styles and to ask for 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 | 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
|
187 | |
739aa1717df5
Extended the new FtpReply class to handle various directory listing styles and to ask for 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 | 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
|
189 | """ |
739aa1717df5
Extended the new FtpReply class to handle various directory listing styles and to ask for 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 | 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
|
191 | |
739aa1717df5
Extended the new FtpReply class to handle various directory listing styles and to ask for 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 | @param line directory line to be parsed (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
|
193 | @return URL info object containing the valid data (QUrlInfo) |
739aa1717df5
Extended the new FtpReply class to handle various directory listing styles and to ask for 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 | @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
|
195 | 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
|
196 | """ |
739aa1717df5
Extended the new FtpReply class to handle various directory listing styles and to ask for 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 | 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
|
198 | 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
|
199 | |
2051
644d5a2585a8
Changed the FTP directory parser to omit the '.' and '..' directories.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2050
diff
changeset
|
200 | if name in [".", ".."]: |
644d5a2585a8
Changed the FTP directory parser to omit the '.' and '..' directories.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2050
diff
changeset
|
201 | return None |
644d5a2585a8
Changed the FTP directory parser to omit the '.' and '..' directories.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2050
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:
diff
changeset
|
203 | urlInfo = QUrlInfo() |
739aa1717df5
Extended the new FtpReply class to handle various directory listing styles and to ask for 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 | 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
|
205 | 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
|
206 | 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
|
207 | 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
|
208 | 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
|
209 | 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
|
210 | 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
|
211 | 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
|
212 | 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
|
213 | 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
|
214 | |
739aa1717df5
Extended the new FtpReply class to handle various directory listing styles and to ask for 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 | 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
|
216 | |
739aa1717df5
Extended the new FtpReply class to handle various directory listing styles and to ask for 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 | 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
|
218 | """ |
739aa1717df5
Extended the new FtpReply class to handle various directory listing styles and to ask for 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 | 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
|
220 | 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
|
221 | |
739aa1717df5
Extended the new FtpReply class to handle various directory listing styles and to ask for 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 | 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
|
223 | 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
|
224 | 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
|
225 | |
739aa1717df5
Extended the new FtpReply class to handle various directory listing styles and to ask for 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 | @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
|
227 | @param time time 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
|
228 | @param urlInfo reference to the URL info object (QUrlInfo) |
739aa1717df5
Extended the new FtpReply class to handle various directory listing styles and to ask for 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 | @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
|
230 | 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
|
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 | 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
|
233 | 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
|
234 | 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
|
235 | 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
|
236 | 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
|
237 | 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
|
238 | except (ValueError, IndexError): |
739aa1717df5
Extended the new FtpReply class to handle various directory listing styles and to ask for 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 | raise FtpDirLineParserError("illegal date string '{0}'".format(month)) |
739aa1717df5
Extended the new FtpReply class to handle various directory listing styles and to ask for 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 | 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
|
241 | 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
|
242 | 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
|
243 | 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
|
244 | except (ValueError, IndexError): |
739aa1717df5
Extended the new FtpReply class to handle various directory listing styles and to ask for a username and password, if the FTP login fails with an error code of 530.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
245 | raise FtpDirLineParserError("illegal time string '{0}'".format(month)) |
739aa1717df5
Extended the new FtpReply class to handle various directory listing styles and to ask for a username and password, if the FTP login fails with an error code of 530.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
246 | 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
|
247 | 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
|
248 | 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
|
249 | 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
|
250 | |
739aa1717df5
Extended the new FtpReply class to handle various directory listing styles and to ask for 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 | 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
|
252 | 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
|
253 | |
739aa1717df5
Extended the new FtpReply class to handle various directory listing styles and to ask for 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 | 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
|
255 | """ |
739aa1717df5
Extended the new FtpReply class to handle various directory listing styles and to ask for 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 | 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
|
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:
diff
changeset
|
258 | @param line directory line to be parsed (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
|
259 | @return URL info object containing the valid data (QUrlInfo) |
739aa1717df5
Extended the new FtpReply class to handle various directory listing styles and to ask for 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 | @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
|
261 | 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
|
262 | """ |
739aa1717df5
Extended the new FtpReply class to handle various directory listing styles and to ask for 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 | 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
|
264 | 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
|
265 | 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
|
266 | # "unpack list of wrong 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
|
267 | raise FtpDirLineParserError("line '{0}' cannot be parsed".format(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
|
268 | |
2051
644d5a2585a8
Changed the FTP directory parser to omit the '.' and '..' directories.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2050
diff
changeset
|
269 | if name in [".", ".."]: |
644d5a2585a8
Changed the FTP directory parser to omit the '.' and '..' directories.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2050
diff
changeset
|
270 | return None |
644d5a2585a8
Changed the FTP directory parser to omit the '.' and '..' directories.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2050
diff
changeset
|
271 | |
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
|
272 | urlInfo = QUrlInfo() |
739aa1717df5
Extended the new FtpReply class to handle various directory listing styles and to ask for 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 | 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
|
274 | 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
|
275 | 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
|
276 | 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
|
277 | 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
|
278 | 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
|
279 | 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
|
280 | 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
|
281 | 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
|
282 | 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
|
283 | raise FtpDirLineParserError("illegal size '{0}'".format(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
|
284 | 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
|
285 | |
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
|
286 | 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
|
287 | 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
|
288 | |
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
|
289 | permissions = (QUrlInfo.ReadOwner | QUrlInfo.WriteOwner |
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
|
290 | | QUrlInfo.ReadGroup | QUrlInfo.WriteGroup |
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
|
291 | | QUrlInfo.ReadOther | QUrlInfo.WriteOther) |
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
|
292 | if ext in [".exe", ".com", ".bat", ".cmd"]: |
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
|
293 | permissions |= QUrlInfo.ExeOwner | QUrlInfo.ExeGroup | QUrlInfo.ExeOther |
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
|
294 | 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
|
295 | |
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
|
296 | 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
|
297 | |
739aa1717df5
Extended the new FtpReply class to handle various directory listing styles and to ask for a username and password, if the FTP login fails with an error code of 530.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
298 | 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
|
299 | """ |
739aa1717df5
Extended the new FtpReply class to handle various directory listing styles and to ask for a username and password, if the FTP login fails with an error code of 530.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
300 | 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
|
301 | |
739aa1717df5
Extended the new FtpReply class to handle various directory listing styles and to ask for a username and password, if the FTP login fails with an error code of 530.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
302 | 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
|
303 | 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
|
304 | 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
|
305 | |
739aa1717df5
Extended the new FtpReply class to handle various directory listing styles and to ask for a username and password, if the FTP login fails with an error code of 530.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
306 | @param line directory line to be parsed (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
|
307 | @return URL info object containing the valid data (QUrlInfo) |
739aa1717df5
Extended the new FtpReply class to handle various directory listing styles and to ask for 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 | @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
|
309 | recognized 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
|
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 | 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
|
312 | 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
|
313 | |
739aa1717df5
Extended the new FtpReply class to handle various directory listing styles and to ask for 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 | 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
|
315 | 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
|
316 | 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
|
317 | 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
|
318 | 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
|
319 | 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
|
320 | 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
|
321 | 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
|
322 | raise |