| | 67 | class _StatParser: |
|---|
| | 68 | """ |
|---|
| | 69 | Provide parsing of directory lines and full directory listings. |
|---|
| | 70 | """ |
|---|
| | 71 | def parse_line(self, line): |
|---|
| | 72 | """ |
|---|
| | 73 | Return a `_Stat` object as derived from the string `line`. |
|---|
| | 74 | The parser code to use depends on the directory format the |
|---|
| | 75 | FTP server delivers. |
|---|
| | 76 | """ |
|---|
| | 77 | raise NotImplementedError("must be defined by subclass") |
|---|
| | 78 | |
|---|
| | 79 | def parse_directory_listing(self, listing): |
|---|
| | 80 | """ |
|---|
| | 81 | Return a list of `_Stat` objects with one `_Stat` object per |
|---|
| | 82 | line in the listing. The order of the entries is kept. |
|---|
| | 83 | """ |
|---|
| | 84 | lines = listing.splitlines() |
|---|
| | 85 | stat_results = [ self.parse_line( line.strip() ) |
|---|
| | 86 | for line in lines ] |
|---|
| | 87 | return stat_results |
|---|
| | 88 | |
|---|
| | 89 | |
|---|
| | 90 | |
|---|