From 2b879b34d6cbd8539c785eec8ef415f60b928f86 Mon Sep 17 00:00:00 2001 From: Michael Farrell Date: Wed, 11 Apr 2012 17:22:03 +0930 Subject: [PATCH 1/5] allow running the script on python 3.0 - 3.2 (though unsure of compatibility) --- tftpy/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tftpy/__init__.py b/tftpy/__init__.py index e8ef87f..3060ed6 100644 --- a/tftpy/__init__.py +++ b/tftpy/__init__.py @@ -12,7 +12,7 @@ import sys # Make sure that this is at least Python 2.3 verlist = sys.version_info -if not verlist[0] >= 2 or not verlist[1] >= 3: +if not (verlist[0] > 2 or (verlist[0] == 2 and verlist[1] >= 3)): raise AssertionError, "Requires at least Python 2.3" from TftpShared import * From 9cba3b98d8c43739833413d612f40b5a2b98b92f Mon Sep 17 00:00:00 2001 From: Michael Farrell Date: Wed, 11 Apr 2012 17:25:56 +0930 Subject: [PATCH 2/5] allow TftpServer.root not to exist if a dyn_file_func is provided --- tftpy/TftpServer.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tftpy/TftpServer.py b/tftpy/TftpServer.py index 364227c..02b20dc 100644 --- a/tftpy/TftpServer.py +++ b/tftpy/TftpServer.py @@ -28,8 +28,11 @@ class TftpServer(TftpSession): # A dict of sessions, where each session is keyed by a string like # ip:tid for the remote end. self.sessions = {} - - if os.path.exists(self.root): + + if callable(self.dyn_file_func): + # don't check the tftproot + pass + elif os.path.exists(self.root): log.debug("tftproot %s does exist" % self.root) if not os.path.isdir(self.root): raise TftpException, "The tftproot must be a directory." From e8039dd715242d6830ff1005085fec5bb89b300c Mon Sep 17 00:00:00 2001 From: Michael Farrell Date: Thu, 12 Apr 2012 10:34:35 +0930 Subject: [PATCH 3/5] improve the check on dyn_file_func of TftpServer --- tftpy/TftpServer.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tftpy/TftpServer.py b/tftpy/TftpServer.py index 02b20dc..0f15fc0 100644 --- a/tftpy/TftpServer.py +++ b/tftpy/TftpServer.py @@ -29,9 +29,9 @@ class TftpServer(TftpSession): # ip:tid for the remote end. self.sessions = {} - if callable(self.dyn_file_func): - # don't check the tftproot - pass + if self.dyn_file_func: + if not callable(self.dyn_file_func): + raise TftpException, "A dyn_file_func supplied, but it is not callable." elif os.path.exists(self.root): log.debug("tftproot %s does exist" % self.root) if not os.path.isdir(self.root): From fed8461e4bff9bb90abfd850676b4078a8dcf4cb Mon Sep 17 00:00:00 2001 From: Michael Farrell Date: Tue, 7 Aug 2012 14:10:37 +0930 Subject: [PATCH 4/5] Improved version check so it is much cleaner, fix relative import issue with Python 2.5 not working --- tftpy/__init__.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/tftpy/__init__.py b/tftpy/__init__.py index 3060ed6..9149761 100644 --- a/tftpy/__init__.py +++ b/tftpy/__init__.py @@ -11,14 +11,15 @@ directly. The TftpClient and TftpServer classes can be reached through it. import sys # Make sure that this is at least Python 2.3 -verlist = sys.version_info -if not (verlist[0] > 2 or (verlist[0] == 2 and verlist[1] >= 3)): +required_version = (2, 3) +if sys.version_info < required_version: raise AssertionError, "Requires at least Python 2.3" -from TftpShared import * -from TftpPacketTypes import * -from TftpPacketFactory import * -from TftpClient import * -from TftpServer import * -from TftpContexts import * -from TftpStates import * +from tftpy.TftpShared import * +from tftpy.TftpPacketTypes import * +from tftpy.TftpPacketFactory import * +from tftpy.TftpClient import * +from tftpy.TftpServer import * +from tftpy.TftpContexts import * +from tftpy.TftpStates import * + From a78f0a6b2968a86e5aadf48a5b3df3cf729c9622 Mon Sep 17 00:00:00 2001 From: Michael Farrell Date: Tue, 7 Aug 2012 14:19:15 +0930 Subject: [PATCH 5/5] raise ImportError when Python version is wrong instead of AssertionError --- tftpy/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tftpy/__init__.py b/tftpy/__init__.py index 9149761..fba9a9f 100644 --- a/tftpy/__init__.py +++ b/tftpy/__init__.py @@ -13,7 +13,7 @@ import sys # Make sure that this is at least Python 2.3 required_version = (2, 3) if sys.version_info < required_version: - raise AssertionError, "Requires at least Python 2.3" + raise ImportError, "Requires at least Python 2.3" from tftpy.TftpShared import * from tftpy.TftpPacketTypes import *