summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael P. Soulier <msoulier@digitaltorque.ca>2011-07-23 20:29:06 -0400
committerMichael P. Soulier <msoulier@digitaltorque.ca>2011-07-23 20:29:06 -0400
commit949c998648a9e3e1b00a7cb218d8f8093a48ac48 (patch)
tree7cf9ea4fe1690e5404494132f725d69a579f1ae5
parenta43773e26cb056bc1db6392f2ffa9dedcabd4548 (diff)
downloadtftpy-949c998648a9e3e1b00a7cb218d8f8093a48ac48.tar.gz
Fixing issue #9, removing blksize option from client if not supplied.
-rwxr-xr-xbin/tftpy_client.py3
-rw-r--r--tftpy/TftpClient.py4
-rw-r--r--tftpy/TftpStates.py8
3 files changed, 7 insertions, 8 deletions
diff --git a/bin/tftpy_client.py b/bin/tftpy_client.py
index 53ad5f9..1a50b56 100755
--- a/bin/tftpy_client.py
+++ b/bin/tftpy_client.py
@@ -25,8 +25,7 @@ def main():
help='filename to upload')
parser.add_option('-b',
'--blksize',
- help='udp packet size to use (default: 512)',
- default=512)
+ help='udp packet size to use (default: 512)')
parser.add_option('-o',
'--output',
help='output file, - for stdout (default: same as download)')
diff --git a/tftpy/TftpClient.py b/tftpy/TftpClient.py
index 5fbe733..f9250bf 100644
--- a/tftpy/TftpClient.py
+++ b/tftpy/TftpClient.py
@@ -19,15 +19,11 @@ class TftpClient(TftpSession):
self.iport = port
self.filename = None
self.options = options
- # FIXME: If the blksize is DEF_BLKSIZE, we should just skip sending
- # it.
if self.options.has_key('blksize'):
size = self.options['blksize']
tftpassert(types.IntType == type(size), "blksize must be an int")
if size < MIN_BLKSIZE or size > MAX_BLKSIZE:
raise TftpException, "Invalid blksize: %d" % size
- else:
- self.options['blksize'] = DEF_BLKSIZE
def download(self, filename, output, packethook=None, timeout=SOCK_TIMEOUT):
"""This method initiates a tftp download from the configured remote
diff --git a/tftpy/TftpStates.py b/tftpy/TftpStates.py
index 6e6a84c..f3467f8 100644
--- a/tftpy/TftpStates.py
+++ b/tftpy/TftpStates.py
@@ -98,6 +98,10 @@ class TftpContext(object):
# Count the number of retry attempts.
self.retry_count = 0
+ def getBlocksize(self):
+ """Fetch the current blocksize for this session."""
+ return int(self.options.get('blksize', 512))
+
def __del__(self):
"""Simple destructor to try to call housekeeping in the end method if
not called explicitely. Leaking file descriptors is not a good
@@ -506,7 +510,7 @@ class TftpState(object):
self.context.metrics.resent_bytes += len(dat.data)
self.context.metrics.add_dup(dat)
else:
- blksize = int(self.context.options['blksize'])
+ blksize = self.context.getBlocksize()
buffer = self.context.fileobj.read(blksize)
log.debug("Read %d bytes into buffer" % len(buffer))
if len(buffer) < blksize:
@@ -590,7 +594,7 @@ class TftpState(object):
self.context.fileobj.write(pkt.data)
self.context.metrics.bytes += len(pkt.data)
# Check for end-of-file, any less than full data packet.
- if len(pkt.data) < int(self.context.options['blksize']):
+ if len(pkt.data) < self.context.getBlocksize():
log.info("End of file detected")
return None