diff options
author | Jay Weisskopf <jay@jayschwa.net> | 2012-05-03 01:24:25 -0500 |
---|---|---|
committer | Jay Weisskopf <jay@jayschwa.net> | 2012-05-03 01:24:25 -0500 |
commit | 39b877258ba96c5cf147694ac905fc43bbeb1206 (patch) | |
tree | a2c01d7fac1d33d4491f3988bcec51c00105b977 /tftpy/TftpClient.py | |
parent | 05e56b66a4600a5b9194f47b7f348e3278da69b6 (diff) | |
download | tftpy-39b877258ba96c5cf147694ac905fc43bbeb1206.tar.gz |
Allow file objects to be used for download output or upload input.
Objects are considered file-like if they have read() or write()
functions. If they do not, they are assumed to be strings to a local
path (existing behavior).
Diffstat (limited to 'tftpy/TftpClient.py')
-rw-r--r-- | tftpy/TftpClient.py | 34 |
1 files changed, 16 insertions, 18 deletions
diff --git a/tftpy/TftpClient.py b/tftpy/TftpClient.py index 9ea905f..f84d801 100644 --- a/tftpy/TftpClient.py +++ b/tftpy/TftpClient.py @@ -27,15 +27,15 @@ class TftpClient(TftpSession): def download(self, filename, output, packethook=None, timeout=SOCK_TIMEOUT): """This method initiates a tftp download from the configured remote - host, requesting the filename passed. It saves the file to a local - file specified in the output parameter. If a packethook is provided, - it must be a function that takes a single parameter, which will be a - copy of each DAT packet received in the form of a TftpPacketDAT - object. The timeout parameter may be used to override the default - SOCK_TIMEOUT setting, which is the amount of time that the client will - wait for a receive packet to arrive. + host, requesting the filename passed. It writes the file to output, + which can be a file-like object or a path to a local file. If a + packethook is provided, it must be a function that takes a single + parameter, which will be a copy of each DAT packet received in the + form of a TftpPacketDAT object. The timeout parameter may be used to + override the default SOCK_TIMEOUT setting, which is the amount of time + that the client will wait for a receive packet to arrive. - Note: If output is a hyphen then stdout is used.""" + Note: If output is a hyphen, stdout is used.""" # We're downloading. log.debug("Creating download context with the following params:") log.debug("host = %s, port = %s, filename = %s, output = %s" @@ -67,17 +67,15 @@ class TftpClient(TftpSession): def upload(self, filename, input, packethook=None, timeout=SOCK_TIMEOUT): """This method initiates a tftp upload to the configured remote host, - uploading the filename passed. If a packethook is provided, it must - be a function that takes a single parameter, which will be a copy of - each DAT packet sent in the form of a TftpPacketDAT object. The - timeout parameter may be used to override the default SOCK_TIMEOUT - setting, which is the amount of time that the client will wait for a - DAT packet to be ACKd by the server. + uploading the filename passed. It reads the file from input, which + can be a file-like object or a path to a local file. If a packethook + is provided, it must be a function that takes a single parameter, + which will be a copy of each DAT packet sent in the form of a + TftpPacketDAT object. The timeout parameter may be used to override + the default SOCK_TIMEOUT setting, which is the amount of time that + the client will wait for a DAT packet to be ACKd by the server. - The input option is the full path to the file to upload, which can - optionally be '-' to read from stdin. - - Note: If output is a hyphen then stdout is used.""" + Note: If input is a hyphen, stdin is used.""" self.context = TftpContextClientUpload(self.host, self.iport, filename, |