Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow tftp client to be imported as a library #15

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

isaiahtaylor
Copy link

Client Usable as a Library

Allows the ptftpd client tool to be imported as a library and integrated into other Python libraries.

Usage

from ptftpd import tftpclient

client = tftpclient.client(host='tftpsite.com', exts={'windowsize': 4})

results = client.get(['-f', 'thefile.txt'])
### or
results = client.put(['thefile.txt'])

print(results[0] +  'kB')
# prints 55234 kB

print(results[1] + ' kB/s')
# prints 100 kB/s

README.rst Outdated

pTFTPd TFTP client can also be imported and used within a Python script.

```from ptftpd import tftpclient
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not how reStructuredText work for code blocks. See below in the "Installation" section for an example.

Copy link
Owner

@mpetazzoni mpetazzoni left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Last few nits. Thanks!

@@ -709,6 +709,11 @@ def usage():
print(' This will discard other TFTP option values.')
print()

def client(host=_PTFTP_DEFAULT_HOST, port=_PTFTP_DEFAULT_PORT,
mode=_PTFTP_DEFAULT_MODE, exts={}, rfc1350=False):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/exts/opts/


from ptftpd import tftpclient

client = tftpclient.client(host='tftpsite.com', exts={'windowsize': 4})
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/exts/opts/

.format(self.PTFTP_STATE.filesize,
self.__get_speed(self.PTFTP_STATE.filesize,
transfer_time)))
.format(self.PTFTP_STATE.filesize, transfer_speed))
self.PTFTP_STATE.file.close()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While you're in there, would you mind moving this and the line below (the close and the remove) in a finally block of the try/except above (line 567)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants