nobodd.tftp
Defines the data structures used by the Trivial File Transfer Protocol
(TFTP). You should never need these directly; use the classes in
nobodd.tftpd to construct a TFTP server instead.
Enumerations
- class nobodd.tftp.OpCode(*values)[source]
Enumeration of op-codes for the Trivial File Transfer Protocol (TFTP). These appear at the start of any TFTP packet to indicate what sort of packet it is.
- class nobodd.tftp.Error(*values)[source]
Enumeration of error status for the Trivial File Transfer Protocol (TFTP). These are used in packets with
OpCodeERRORto indicate the sort of error that has occurred.
Constants
- nobodd.tftp.TFTP_BLKSIZE
- nobodd.tftp.TFTP_MIN_BLKSIZE
- nobodd.tftp.TFTP_DEF_BLKSIZE
- nobodd.tftp.TFTP_MAX_BLKSIZE
Constants defining the
blksizeTFTP option; the name of the option, its minimum, default, and maximum values.
- nobodd.tftp.TFTP_TIMEOUT
- nobodd.tftp.TFTP_UTIMEOUT
- nobodd.tftp.TFTP_MIN_TIMEOUT_NS
- nobodd.tftp.TFTP_DEF_TIMEOUT_NS
- nobodd.tftp.TFTP_MAX_TIMEOUT_NS
Constants defining the
timeoutandutimeoutTFTP options; the name of the options, the minimum, default, and maximum values, in units of nano-seconds.
- nobodd.tftp.TFTP_BINARY
- nobodd.tftp.TFTP_NETASCII
- nobodd.tftp.TFTP_MODES
Constants defining the available transfer modes.
- nobodd.tftp.TFTP_TSIZE
Constant defining the name of the
tsizeTFTP option.
- nobodd.tftp.TFTP_OPTIONS
Constant defining the TFTP options available for negotiation.
Packets
- class nobodd.tftp.Packet[source]
Abstract base class for all TFTP packets. This provides the class method
Packet.from_bytes()which constructs and returns the appropriate concrete sub-class for theOpCodefound at the beginning of the packet’s data.Instances of the concrete classes may be converted back to
bytessimply by callingbyteson them:>>> b = b'\x00\x01config.txt\0octet\0' >>> r = Packet.from_bytes(b) >>> r RRQPacket(filename='config.txt', mode='octet', options=FrozenDict({})) >>> bytes(r) b'\x00\x01config.txt\x00octet\x00'
Concrete classes can also be constructed directly, for conversion into
bytesduring transfer:>>> bytes(ACKPacket(block=10)) b'\x00\x04\x00\n' >>> bytes(RRQPacket('foo', 'netascii', {'tsize': 0})) b'\x00\x01foo.txt\x00netascii\x00tsize\x000\x00'
- classmethod from_bytes(s)[source]
Given a
bytes-string s, checks theOpCodeat the front, and constructs one of the concrete packet types defined below, returning (instead ofPacketwhich is abstract):>>> Packet.from_bytes(b'\x00\x01config.txt\0octet\0') RRQPacket(filename='config.txt', mode='octet', options=FrozenDict({}))
- classmethod from_data(data)[source]
Constructs an instance of the packet class with the specified data (which is everything in the
bytes-string passed tofrom_bytes()minus the header). This method is not implemented inPacketbut is expected to be implemented in any concrete descendant.
- class nobodd.tftp.RRQPacket(filename, mode, options=None)[source]
Concrete type for
RRQ(read request) packets.These packets are sent by a client to initiate a transfer. They include the filename to be sent, the mode to send it (one of the strings “octet” or “netascii”), and any options the client wishes to negotiate.
- class nobodd.tftp.WRQPacket(filename, mode, options=None)[source]
Concrete type for
WRQ(write request) packets.These packets are sent by a client to initiate a transfer to the server. They include the filename to be sent, the mode to send it (one of the strings “octet” or “netascii”), and any options the client wishes to negotiate.
- class nobodd.tftp.DATAPacket(block, data)[source]
Concrete type for
DATApackets.These are sent in response to
RRQ,WRQ, orACKpackets and each contains a block of the file to transfer, data (by default, 512 bytes long unless this is the finalDATApacket), and the block number.
- class nobodd.tftp.ACKPacket(block)[source]
Concrete type for
ACKpackets.These are sent in response to
DATApackets, and acknowledge the successful receipt of the specified block.
- class nobodd.tftp.ERRORPacket(error, message=None)[source]
Concrete type for
ERRORpackets.These are sent by either end of a transfer to indicate a fatal error condition. Receipt of an
ERRORpacket immediately terminates a transfer without further acknowledgment.The
ERRORpacket contains the error code (anErrorvalue) and a descriptive message.