A command line client for the hobbyist Spartan protocol.
Björn Wärmedal 9420ff5c91 Fixed bug | 2 년 전 | |
---|---|---|
sparty | 2 년 전 | |
LICENSE | 3 년 전 | |
README.md | 2 년 전 | |
setup.cfg | 2 년 전 | |
setup.py | 3 년 전 |
Python module/CLI program for making network requests with the spartan protocol.
pip3 install git+https://notabug.org/tinyrabbit/sparty.git#egg=sparty
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.
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:
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.