Coder Social home page Coder Social logo

aiotftp's Introduction

aiotftp

Travis status for master branch codecov.io status for master branch

Why?

Because what the world really needed was asynchronous, dynamically routable TFTP.

Seriously, though: it can be useful for testing, and the intended use-case is keeping track of the requests our devices make while under test, and be able to do such testing against potentially many devices simultaneously.

While it can be used for the usual use case of TFTP (moving files into or out of some directory) it’s also possible to provide arbitrary logic to operate on a per-request basis to either

  • provide a buffer to use as the response to a RRQ
  • recieve a buffer to do whatever you care to after a WRQ complete

Documentation?

Eventually. Hopefully.

TODO

Right now only OCTET mode is supported; should probably support ASCII as well.

Getting Started

Client example:

import aiotftp

async def main(loop):
    async with aiotftp.read('tftp://example.org/hello') as response:
        contents = await response.data()
        print(contents.decode())

loop = asyncio.get_event_loop()
loop.run_until_complete(main())
import aiotftp

async def main(loop):
    with open('example.txt', 'rb') as fobj:
        await aiotftp.write(args.url, data=fobj)

loop = asyncio.get_event_loop()
loop.run_until_complete(main())

Server example:

import aiotftp

async def read(request):
    if request.filename == 'hello':
        return aiotftp.Response(b'Hello World!\n')
    return aiotftp.FileResponse(request.filename)

async def write(request):
    with open(request.filename, 'wb') as fp:
        async for chunk in await request.accept():
            fp.write(chunk)

async def main(loop):
    server = aiotftp.Server(read, write)
    await loop.create_datagram_endpoint(server, local_addr=('::', 69))

loop = asyncio.get_event_loop()
loop.run_until_complete(main())
loop.run_forever()

aiotftp's People

Contributors

vodik avatar

Stargazers

Lennon Anderson avatar Pierre R. avatar

Watchers

Bryan Walters avatar Nenad Corbic avatar  avatar Rob Thomas avatar James Cloos avatar Lennon Anderson avatar

Forkers

jcollie tim---

aiotftp's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.