Package grizzled :: Package net :: Package ftp :: Module parse
[hide private]
[frames] | no frames]

Module parse

source code

Module for parsing FTP data.

Currently, this module contains classes for parsing FTP LIST command output from a variety of FTP servers. In the future, this module may be extended to handle other FTP parsing chores. (Or not.)

The FTP LIST parsing logic was adapted for Python from D. J. Bernstein's ftpparse.c library. See http://cr.yp.to/ftpparse.html. The logic in this module is functionally similar to Bernstein's parser, with the following differences:

Currently covered formats:

Definitely not covered:

Classes [hide private]
  FTPListData
The FTPListDataParser class's parse_line() method returns an instance of this class, capturing the parsed data.
  FTPListDataParser
An FTPListDataParser object can be used to parse one or more lines that were retrieved by an FTP LIST command that was sent to a remote server.
  FTPMlstDataParser
An FTPMlstDataParser object can be used to parse one or more lines that were retrieved by an FTP MLST or MLSD command that was sent to a remote server.
Functions [hide private]
FTPListData
parse_ftp_list_line(ftp_list_line, is_mlst=False)
Convenience function that instantiates an FTPListDataParser object or FTPMlstDataParser (depending on the setting of is_mlst) and and passes ftp_list_line to the object's parse_line() method, returning the result.
source code
dict
ftp_FEAT(ftp)
Issue the FTP FEAT command to an FTP server, and return the resulting feature list as a dictionary.
source code
bool
supports_mlst(ftp)
Convenience function to determine whether a remote FTP server supports the MLST command or not.
source code
 
_skip(s, i, c) source code
Variables [hide private]
  MONTHS = ('jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'au...
  MTIME_TYPE = Enum('UNKNOWN', 'LOCAL', 'REMOTE_MINUTE', 'REMOTE...
MTIME_TYPE identifies how a modification time ought to be interpreted (assuming the caller cares).
  ID_TYPE = Enum('UNKNOWN', 'FULL')
ID_TYPE identifies how a file's identifier should be interpreted.
  now = 1457968860.25
  current_year = 2016
  __package__ = 'grizzled.net.ftp'
Function Details [hide private]

parse_ftp_list_line(ftp_list_line, is_mlst=False)

source code 
Convenience function that instantiates an FTPListDataParser object or FTPMlstDataParser (depending on the setting of is_mlst) and and passes ftp_list_line to the object's parse_line() method, returning the result.
Parameters:
  • ftp_list_line (str) - The line of output
  • is_mlst (bool) - true if the server is known to support the FTP MLST command; false, otherwise.
Returns: FTPListData
An FTPListData object describing the parsed line, or None if the line could not be parsed. Note that it's possible for this method to return a partially-filled FTPListData object (e.g., one without a name).

ftp_FEAT(ftp)

source code 

Issue the FTP FEAT command to an FTP server, and return the resulting feature list as a dictionary.

Adapted from code by Andrew Scheller <gcode@loowis.durge.org>.

Returns: dict
A dict of features, or an empty dict if either (a) the remote server supports no extra features, or (b) doesn't support the FTP FEAT command.

Parameters: ftp : open FTP object from Python's ftplib.

supports_mlst(ftp)

source code 

Convenience function to determine whether a remote FTP server supports the MLST command or not. This method uses the FTP "FEAT" command to query the capabilities of the server.

Adapted from code by Andrew Scheller <gcode@loowis.durge.org>.

Returns: bool
true if the server supports MLST; false, otherwise.

Parameters: ftp : open FTP object from Python's ftplib.


Variables Details [hide private]

MONTHS

Value:
('jan',
 'feb',
 'mar',
 'apr',
 'may',
 'jun',
 'jul',
 'aug',
...

MTIME_TYPE

MTIME_TYPE identifies how a modification time ought to be interpreted (assuming the caller cares).

  • LOCAL: Time is local to the client, granular to (at least) the minute
  • REMOTE_MINUTE: Time is local to the server and granular to the minute
  • REMOTE_DAY: Time is local to the server and granular to the day.
  • UNKNOWN: Time's locale is unknown.
Value:
Enum('UNKNOWN', 'LOCAL', 'REMOTE_MINUTE', 'REMOTE_DAY')

ID_TYPE

ID_TYPE identifies how a file's identifier should be interpreted.

  • FULL: The ID is known to be complete.
  • UNKNOWN: The ID is not set or its type is unknown.
Value:
Enum('UNKNOWN', 'FULL')