A command line client for the hobbyist Spartan protocol.

Björn Wärmedal 9420ff5c91 Fixed bug 2 vuotta sitten
sparty 9420ff5c91 Fixed bug 2 vuotta sitten
LICENSE 949e3c4dc8 Initial commit 3 vuotta sitten
README.md 9dd6c7108e Updated README 2 vuotta sitten
setup.cfg 9420ff5c91 Fixed bug 2 vuotta sitten
setup.py 267a01dbe2 Modernize packaging -- setup.cfg instead of setup.py 3 vuotta sitten

README.md

sparty

Python module/CLI program for making network requests with the spartan protocol.

Installation

pip3 install git+https://notabug.org/tinyrabbit/sparty.git#egg=sparty

Command Line Usage

usage: sparty [-h] [-u URL] [-o OUTPUTFILE] [-q] [-n] [-m MESSAGE]
              [-i INPUTFILE]

Python module/CLI program for making network requests with the spartan protocol.

optional arguments:
  -h, --help            show this help message and exit
  -u URL, --url URL     Fully qualified URL to fetch.
  -o OUTPUTFILE, --outputfile OUTPUTFILE
                        File to output response body to.
  -q, --quiet           Don't print response header.
  -n, --nobody          Only print response header.
  -m MESSAGE, --message MESSAGE
                        A string message to send with the request.
  -i INPUTFILE, --inputfile INPUTFILE
                        A file to send with the request. Overrides
                        -m/--message. This can in turn be overriden by a QUERY
                        STRING in the supplied URL, which will be sent as a
                        message instead.

Library Usage

import sparty

response = sparty.request(url)

#OR

response = sparty.request(url, data) # where data is a bytes-like object

while True:
    buf = response.read()
    if len(buf):
        sys.stdout.buffer.write(buf)
    else:
        break

response.discard()

The sparty.Response object has the following values:

  • responsecode: the response code from the server.
  • meta: the rest of the header.

The method read() should be used to get content from the response object. It takes an argument bufsize, which is how many bytes it will read at most. This defaults to 4096.

When you are done reading the response you should use the discard() method to close all file handles and sockets the Response object is handling.

Features

  • Supports client to server data transmission from QUERY_STRING in the URL, string argument, or input file.
  • Supports streaming from server to client.

Todo

  • Error checking is pretty rudimentary.
  • Validation of response code and meta field.