diff --git a/tftpy/TftpPacketTypes.py b/tftpy/TftpPacketTypes.py index ccb7f11..85c6384 100644 --- a/tftpy/TftpPacketTypes.py +++ b/tftpy/TftpPacketTypes.py @@ -321,8 +321,11 @@ ERROR | 05 | ErrorCode | ErrMsg | 0 | def decode(self): "Decode self.buffer, populating instance variables and return self." - tftpassert(len(self.buffer) >= 5, "malformed ERR packet") + tftpassert(len(self.buffer) > 4, "malformed ERR packet, too short") + logger.debug("Decoding ERR packet, length %s bytes" % + len(self.buffer)) format = "!HH%dsx" % (len(self.buffer) - 5) + logger.debug("Decoding ERR packet with format: %s" % format) self.opcode, self.errorcode, self.errmsg = struct.unpack(format, self.buffer) logger.error("ERR packet - errorcode: %d, message: %s" diff --git a/tftpy/TftpServer.py b/tftpy/TftpServer.py index fef2be1..cb5d613 100644 --- a/tftpy/TftpServer.py +++ b/tftpy/TftpServer.py @@ -46,8 +46,11 @@ class TftpServer(TftpSession): tftp_factory = TftpPacketFactory() + # Don't use new 2.5 ternary operator yet + # listenip = listenip if listenip else '0.0.0.0' + if not listenip: listenip = '0.0.0.0' logger.info("Server requested on ip %s, port %s" - % (listenip if listenip else '0.0.0.0', listenport)) + % (listenip, listenport)) try: # FIXME - sockets should be non-blocking? self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) diff --git a/tftpy/TftpShared.py b/tftpy/TftpShared.py index 71a4ec2..c4d4a1c 100644 --- a/tftpy/TftpShared.py +++ b/tftpy/TftpShared.py @@ -10,10 +10,11 @@ TIMEOUT_RETRIES = 5 DEF_TFTP_PORT = 69 # Initialize the logger. -logging.basicConfig( - level=LOG_LEVEL, - format='%(asctime)s %(name)-12s %(levelname)-8s %(message)s', - datefmt='%m-%d %H:%M:%S') +#logging.basicConfig( +# level=LOG_LEVEL, +# format='%(asctime)s %(name)-12s %(levelname)-8s %(message)s', +# datefmt='%m-%d %H:%M:%S') +logging.basicConfig() # The logger used by this library. Feel free to clobber it with your own, if you like, as # long as it conforms to Python's logging. logger = logging.getLogger('tftpy') diff --git a/tftpy/__init__.py b/tftpy/__init__.py index d35306d..94335fe 100644 --- a/tftpy/__init__.py +++ b/tftpy/__init__.py @@ -6,10 +6,10 @@ with support for variable block sizes. import sys -# Make sure that this is at least Python 2.4 +# Make sure that this is at least Python 2.3 verlist = sys.version_info -if not verlist[0] >= 2 or not verlist[1] >= 4: - raise AssertionError, "Requires at least Python 2.4" +if not verlist[0] >= 2 or not verlist[1] >= 3: + raise AssertionError, "Requires at least Python 2.3" from TftpShared import * from TftpPacketTypes import *