http-parser
HTTP request/response parser for Python compatible with Python 2.x (>=2.6), Python 3 and Pypy. If possible a C parser based on http-parser from Ryan Dahl will be used.
http-parser is under the MIT license.
Project url: https://github.com/benoitc/http-parser/
Requirements:
Python 2.6 or sup. Pypy latest version.
Cython if you need to rebuild the C code (Not needed for Pypy)
Installation
$ pip install http-parser
Or install from source:
$ git clone git://github.com/benoitc/http-parser.git $ cd http-parser && python setup.py install
Note: if you get an error on MacOSX try to install with the following arguments:
$ env ARCHFLAGS=”-arch i386 -arch x86_64” python setup.py install
Usage
http-parser provide you parser.HttpParser low-level parser in C that you can access in your python program and http.HttpStream providing higher-level access to a readable,sequential io.RawIOBase object.
To help you in your day work, http-parser provides you 3 kind of readers in the reader module: IterReader to read iterables, StringReader to reads strings and StringIO objects, SocketReader to read sockets or objects with the same api (recv_into needed). You can of course use any io.RawIOBase object.
Example of HttpStream
ex:
#!/usr/bin/env python
import socket
from toil_http_parser.http import HttpStream
from toil_http_parser.reader import SocketReader
def main():
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
s.connect(('gunicorn.org', 80))
s.send("GET / HTTP/1.1\r\nHost: gunicorn.org\r\n\r\n")
r = SocketReader(s)
p = HttpStream(r)
print p.headers()
print p.body_file().read()
finally:
s.close()
if __name__ == "__main__":
main()
Example of HttpParser:
#!/usr/bin/env python
import socket
# try to import C parser then fallback in pure python parser.
try:
from toil_http_parser.parser import HttpParser
except ImportError:
from toil_http_parser.pyparser import HttpParser
def main():
p = HttpParser()
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
body = []
try:
s.connect(('gunicorn.org', 80))
s.send("GET / HTTP/1.1\r\nHost: gunicorn.org\r\n\r\n")
while True:
data = s.recv(1024)
if not data:
break
recved = len(data)
nparsed = p.execute(data, recved)
assert nparsed == recved
if p.is_headers_complete():
print p.get_headers()
if p.is_partial_body():
body.append(p.recv_body())
if p.is_message_complete():
break
print "".join(body)
finally:
s.close()
if __name__ == "__main__":
main()
You can find more docs in the code (or use a doc generator).
Copyright
2011-2013 (c) Benoît Chesneau <benoitc@e-engura.org>
Metadata
Release files for toil-http-parser 0.8.9
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| toil-http-parser-0.8.9.tar.gz | 99.3 kB | Details |
Built distributions (wheels)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| toil_http_parser-0.8.9-py3.8-linux-x86_64.egg | Legacy Egg format | - | - | Details |
| toil_http_parser-0.8.9-py3.7-linux-x86_64.egg | Legacy Egg format | - | - | Details |
| toil_http_parser-0.8.9-py3.6-linux-x86_64.egg | Legacy Egg format | - | - | Details |
Total release size: 814.9 kB
Release files / toil-http-parser-0.8.9.tar.gz
| Download URL | toil-http-parser-0.8.9.tar.gz |
|---|---|
| Size | 99.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9b96a47134d33197ac1fa174efddd7080a8644f170fc2afa47638a2fb79747ec
|
|
BLAKE2b-256 checksum How to use checksums |
22397092cab7865fab772cabfcab9814a4acc13d8d04be732a44d6a3a360f88a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
Python-urllib/3.7
|
Release files / toil_http_parser-0.8.9-py3.8-linux-x86_64.egg
| Download URL | toil_http_parser-0.8.9-py3.8-linux-x86_64.egg |
|---|---|
| Size | 258.3 kB |
| Tags | Egg |
|
SHA-256 checksum How to use checksums |
9e9f030c96703dfea4c77dc430e6841d48df0134894fdd00ccde989f447927e2
|
|
BLAKE2b-256 checksum How to use checksums |
2132ac74b76e1f3e9c51068e50e76ada0707bf4421c2397116bd0c217c55bedd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
Python-urllib/3.8
|
Release files / toil_http_parser-0.8.9-py3.7-linux-x86_64.egg
| Download URL | toil_http_parser-0.8.9-py3.7-linux-x86_64.egg |
|---|---|
| Size | 228.7 kB |
| Tags | Egg |
|
SHA-256 checksum How to use checksums |
6792c5d363a3db56d1f284d18c4b45fbd0653fdde0c5dfe5244ab3905960a4af
|
|
BLAKE2b-256 checksum How to use checksums |
6ce4fb2713c88e3f783392a9f2161de8ebf09d504a8337576279eb425fe4771c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
Python-urllib/3.7
|
Release files / toil_http_parser-0.8.9-py3.6-linux-x86_64.egg
| Download URL | toil_http_parser-0.8.9-py3.6-linux-x86_64.egg |
|---|---|
| Size | 228.6 kB |
| Tags | Egg |
|
SHA-256 checksum How to use checksums |
900b4ad3305bc130c60642ba2b299801b5c609011b28a55eef3682989b91399f
|
|
BLAKE2b-256 checksum How to use checksums |
2201cc08bb01c82636c391d6468428b984dc0c16ab60d46014517eac56a5e204
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
Python-urllib/3.6
|