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(value, names=None, *values, module=None, qualname=None, type=None, start=1, boundary=None)[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(value, names=None, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]
Enumeration of error status for the Trivial File Transfer Protocol (TFTP). These are used in packets with
OpCode
ERROR
to 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
blksize
TFTP 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
timeout
andutimeout
TFTP 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
tsize
TFTP 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 theOpCode
found at the beginning of the packet’s data.Instances of the concrete classes may be converted back to
bytes
simply by callingbytes
on 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
bytes
during 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 theOpCode
at the front, and constructs one of the concrete packet types defined below, returning (instead ofPacket
which 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 inPacket
but 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
DATA
packets.These are sent in response to
RRQ
,WRQ
, orACK
packets and each contains a block of the file to transfer, data (by default, 512 bytes long unless this is the finalDATA
packet), and the block number.
- class nobodd.tftp.ACKPacket(block)[source]
Concrete type for
ACK
packets.These are sent in response to
DATA
packets, and acknowledge the successful receipt of the specified block.
- class nobodd.tftp.ERRORPacket(error, message=None)[source]
Concrete type for
ERROR
packets.These are sent by either end of a transfer to indicate a fatal error condition. Receipt of an
ERROR
packet immediately terminates a transfer without further acknowledgment.The
ERROR
packet contains the error code (anError
value) and a descriptive message.