Updating docs for epydoc.

git-svn-id: https://tftpy.svn.sourceforge.net/svnroot/tftpy/trunk@67 63283fd4-ec1e-0410-9879-cb7f675518da
master
msoulier 2007-03-31 02:03:36 +00:00
parent b68ceca9d8
commit d9665e19fc
3 changed files with 22 additions and 14 deletions

View File

@ -3,7 +3,8 @@ from TftpShared import *
from TftpPacketFactory import *
class TftpClient(TftpSession):
"""This class is an implementation of a tftp client."""
"""This class is an implementation of a tftp client. Once instantiated, a
download can be initiated via the download() method."""
def __init__(self, host, port, options={}):
"""This constructor returns an instance of TftpClient, taking the
remote host, the remote port, and the filename to fetch."""
@ -25,7 +26,7 @@ class TftpClient(TftpSession):
self.sock = None
def gethost(self):
"Simple getter method."
"Simple getter method for use in a property."
return self.__host
def sethost(self, host):
@ -47,6 +48,7 @@ class TftpClient(TftpSession):
wait for a receive packet to arrive."""
# Open the output file.
# FIXME - need to support alternate return formats than files?
# File-like objects would be ideal, ala duck-typing.
outputfile = open(output, "wb")
recvpkt = None
curblock = 0

View File

@ -2,7 +2,9 @@ from TftpShared import *
from TftpPacketTypes import *
class TftpPacketFactory(object):
"""This class generates TftpPacket objects."""
"""This class generates TftpPacket objects. It is responsible for parsing
raw buffers off of the wire and returning objects representing them, via
the parse() method."""
def __init__(self):
self.classes = {
1: TftpPacketRRQ,
@ -13,7 +15,20 @@ class TftpPacketFactory(object):
6: TftpPacketOACK
}
def create(self, opcode):
def parse(self, buffer):
"""This method is used to parse an existing datagram into its
corresponding TftpPacket object. The buffer is the raw bytes off of
the network."""
logger.debug("parsing a %d byte packet" % len(buffer))
(opcode,) = struct.unpack("!H", buffer[:2])
logger.debug("opcode is %d" % opcode)
packet = self.__create(opcode)
packet.buffer = buffer
return packet.decode()
def __create(self, opcode):
"""This method returns the appropriate class object corresponding to
the passed opcode."""
tftpassert(self.classes.has_key(opcode),
"Unsupported opcode: %d" % opcode)
@ -21,13 +36,3 @@ class TftpPacketFactory(object):
logger.debug("packet is %s" % packet)
return packet
def parse(self, buffer):
"""This method is used to parse an existing datagram into its
corresponding TftpPacket object."""
logger.debug("parsing a %d byte packet" % len(buffer))
(opcode,) = struct.unpack("!H", buffer[:2])
logger.debug("opcode is %d" % opcode)
packet = self.create(opcode)
packet.buffer = buffer
return packet.decode()

View File

@ -26,6 +26,7 @@ class TftpPacketWithOptions(object):
"""This class exists to permit some TftpPacket subclasses to share code
regarding options handling. It does not inherit from TftpPacket, as the
goal is just to share code here, and not cause diamond inheritance."""
def __init__(self):
self.options = None