class documentation

class FTPFileListProtocol(basic.LineReceiver): (source)

View In Hierarchy

Parser for standard FTP file listings

This is the evil required to match:

    -rw-r--r--   1 root     other        531 Jan 29 03:26 README

If you need different evil for a wacky FTP server, you can override either fileLinePattern or parseDirectoryLine().

It populates the instance attribute self.files, which is a list containing dicts with the following keys (examples from the above line):

  • filetype: e.g. 'd' for directories, or '-' for an ordinary file
  • perms: e.g. 'rw-r--r--'
  • nlinks: e.g. 1
  • owner: e.g. 'root'
  • group: e.g. 'other'
  • size: e.g. 531
  • date: e.g. 'Jan 29 03:26'
  • filename: e.g. 'README'
  • linktarget: e.g. 'some/file'

Note that the 'date' value will be formatted differently depending on the date. Check http://cr.yp.to/ftp.html if you really want to try to parse it.

It also matches the following:

    -rw-r--r--   1 root     other        531 Jan 29 03:26 I HAVE\ SPACE
       - filename:   e.g. 'I HAVE SPACE'

    -rw-r--r--   1 root     other        531 Jan 29 03:26 LINK -> TARGET
       - filename:   e.g. 'LINK'
       - linktarget: e.g. 'TARGET'

    -rw-r--r--   1 root     other        531 Jan 29 03:26 N S -> L S
       - filename:   e.g. 'N S'
       - linktarget: e.g. 'L S'
Method __init__ Undocumented
Method addFile Append file information dictionary to the list of known files.
Method lineReceived Override this for when each line is received.
Method parseDirectoryLine Return a dictionary of fields, or None if line cannot be parsed.
Method unknownLine Deal with received lines which could not be parsed as file information.
Class Variable delimiter Undocumented
Class Variable fileLinePattern Undocumented
Instance Variable files list of dicts describing the files in this listing
Class Variable _encoding Undocumented

Inherited from LineReceiver:

Method clearLineBuffer Clear buffered data.
Method dataReceived Protocol.dataReceived. Translates bytes into lines, and calls lineReceived (or rawDataReceived, depending on mode.)
Method lineLengthExceeded Called when the maximum line length has been reached. Override if it needs to be dealt with in some special way.
Method rawDataReceived Override this for when raw data is received.
Method sendLine Sends a line to the other end of the connection.
Method setLineMode Sets the line-mode of this receiver.
Method setRawMode Sets the raw mode of this receiver. Further data received will be sent to rawDataReceived rather than lineReceived.
Constant MAX_LENGTH The maximum length of a line to allow (If a sent line is longer than this, the connection is dropped). Default is 16384.
Instance Variable line_mode Undocumented
Instance Variable _buffer Undocumented
Instance Variable _busyReceiving Undocumented

Inherited from Protocol (via LineReceiver):

Method connectionLost Called when the connection is shut down.
Method logPrefix Return a prefix matching the class name, to identify log messages related to this protocol instance.
Class Variable factory Undocumented

Inherited from BaseProtocol (via LineReceiver, Protocol):

Method connectionMade Called when a connection is made.
Method makeConnection Make a connection to a transport and a server.
Instance Variable connected Undocumented
Instance Variable transport Undocumented

Inherited from _PauseableMixin (via LineReceiver, Protocol, BaseProtocol):

Method pauseProducing Undocumented
Method resumeProducing Undocumented
Method stopProducing Undocumented
Instance Variable paused Undocumented
def __init__(self): (source)

Undocumented

def addFile(self, info): (source)

Append file information dictionary to the list of known files.

Subclasses can override or extend this method to handle file information differently without affecting the parsing of data from the server.

Parameters
info:dictdictionary containing the parsed representation of the file information
def lineReceived(self, line): (source)

Override this for when each line is received.

Parameters
line:bytesThe line which was received with the delimiter removed.
def parseDirectoryLine(self, line): (source)

Return a dictionary of fields, or None if line cannot be parsed.

Parameters
line:strline of text expected to contain a directory entry
Returns
dict
def unknownLine(self, line): (source)

Deal with received lines which could not be parsed as file information.

Subclasses can override this to perform any special processing needed.

Parameters
line:strunparsable line as received
fileLinePattern = (source)

Undocumented

list of dicts describing the files in this listing

_encoding: str = (source)

Undocumented