diff options
author | Alexey Loshkarev <elf2001@gmail.com> | 2010-02-18 12:01:45 +0200 |
---|---|---|
committer | Alexey Loshkarev <elf2001@gmail.com> | 2010-02-18 12:01:45 +0200 |
commit | 72c47698eb7a8fda3d3082e2c5e5438e2a437eda (patch) | |
tree | 1845f256bb967cc3c418ef2684b74d04bd6003c0 | |
parent | badf18f2a4ffd7fa31f73767a8898bfc809b7e5e (diff) | |
download | tftpy-72c47698eb7a8fda3d3082e2c5e5438e2a437eda.tar.gz |
Fix dyn_file_func (was broken?)
Fix error message (filename was not displayed)
-rw-r--r-- | tftpy/TftpStates.py | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/tftpy/TftpStates.py b/tftpy/TftpStates.py index fc36a9b..d664eee 100644 --- a/tftpy/TftpStates.py +++ b/tftpy/TftpStates.py @@ -54,7 +54,7 @@ class TftpMetrics(object): class TftpContext(object): """The base class of the contexts.""" - def __init__(self, host, port, timeout): + def __init__(self, host, port, timeout, dyn_file_func): """Constructor for the base context, setting shared instance variables.""" self.file_to_transfer = None @@ -80,6 +80,7 @@ class TftpContext(object): self.last_update = 0 # The last DAT packet we sent, if applicable, to make resending easy. self.last_dat_pkt = None + self.dyn_file_func = dyn_file_func def checkTimeout(self, now): """Compare current time with last_update time, and raise an exception @@ -168,7 +169,9 @@ class TftpContextServer(TftpContext): TftpContext.__init__(self, host, port, - timeout) + timeout, + dyn_file_func + ) # At this point we have no idea if this is a download or an upload. We # need to let the start state determine that. self.state = TftpStateServerStart(self) @@ -549,10 +552,10 @@ class TftpStateServerRecvRRQ(TftpState): # Note: Open in binary mode for win32 portability, since win32 # blows. self.context.fileobj = open(path, "rb") - elif self.dyn_file_func: + elif self.context.dyn_file_func: log.debug("No such file %s but using dyn_file_func" % path) self.context.fileobj = \ - self.dyn_file_func(self.context.file_to_transfer) + self.context.dyn_file_func(self.context.file_to_transfer) else: send.sendError(TftpErrors.FileNotFound) raise TftpException, "File not found: %s" % path @@ -585,7 +588,7 @@ class TftpStateServerRecvWRQ(TftpState): log.info("Opening file %s for writing" % path) if os.path.exists(path): # FIXME: correct behavior? - log.warn("File %s exists already, overwriting...") + log.warn("File %s exists already, overwriting..." % self.context.file_to_transfer) # FIXME: I think we should upload to a temp file and not overwrite the # existing file until the file is successfully uploaded. self.context.fileobj = open(path, "wb") |