summaryrefslogtreecommitdiff
path: root/tftpy/TftpContexts.py
diff options
context:
space:
mode:
Diffstat (limited to 'tftpy/TftpContexts.py')
-rw-r--r--tftpy/TftpContexts.py16
1 files changed, 11 insertions, 5 deletions
diff --git a/tftpy/TftpContexts.py b/tftpy/TftpContexts.py
index 78bf34e..264c4c1 100644
--- a/tftpy/TftpContexts.py
+++ b/tftpy/TftpContexts.py
@@ -254,7 +254,11 @@ class TftpContextClientUpload(TftpContext):
self.file_to_transfer = filename
self.options = options
self.packethook = packethook
- if input == '-':
+ # If the input object has a read() function,
+ # assume it is file-like.
+ if hasattr(input, 'read'):
+ self.fileobj = input
+ elif input == '-':
self.fileobj = sys.stdin
else:
self.fileobj = open(input, "rb")
@@ -327,10 +331,12 @@ class TftpContextClientDownload(TftpContext):
self.file_to_transfer = filename
self.options = options
self.packethook = packethook
- # FIXME - need to support alternate return formats than files?
- # File-like objects would be ideal, ala duck-typing.
- # If the filename is -, then use stdout
- if output == '-':
+ # If the output object has a write() function,
+ # assume it is file-like.
+ if hasattr(output, 'write'):
+ self.fileobj = output
+ # If the output filename is -, then use stdout
+ elif output == '-':
self.fileobj = sys.stdout
else:
self.fileobj = open(output, "wb")