Multipart Reader
Permits to read a multipart content like, mixed, related, etc.
Thanks to the aiohttp project for the implementation, cf.: http://aiohttp.readthedocs.org/en/stable/multipart.html. Unfortunately lot of people have not yet moved to asyncio, or do not want the full aiohttp stack to read the multipart content.
Here we tried to keep all the aiohttp logic and coverage but the coroutines mechanism.
What it does
It reads the same way multpart/x contents. Lets say we have the following multipart/related content:
>>> import json
>>> from email.mime.multipart import MIMEMultipart
>>> from email.mime.base import MIMEBase
>>> multipart = MIMEMultipart('related')
>>> part = MIMEBase('application', 'json')
>>> part.set_payload(json.dumps({'foo': 'bar'}))
>>> multipart.attach(part)
>>> part = MIMEBase('application', 'octet-stream')
>>> part.set_payload(b"Python will save the world. I don't know how. But it will.")
>>> part.add_header('Content-Disposition', 'attachment', filename='python-save-the-world.txt')
>>> multipart.attach(part)
Here is how we can read it:
>>> import io
>>> from multipart_reader import MultipartReader
>>> content = multipart.as_string().split('\n\n', 1)[1]
>>> headers = dict(multipart.items())
>>> stream = io.BytesIO()
>>> stream.write(content)
>>> stream.seek(0)
>>> reader = MultipartReader(headers, stream)
>>> json_part = reader.next()
>>> json_part.json()
{'foo': 'bar'}
>>> file_part = reader.next()
>>> file_part.read()
"Python will save the world. I don't know how. But it will."
>>> file_part.filename
'python-save-the-world.txt'
That’s it …
Metadata
Release files for multipart-reader 0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| multipart-reader-0.2.tar.gz | 15.3 kB | Without provenance | Details for multipart-reader-0.2.tar.gz |
Built distributions (wheels)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| multipart_reader-0.2-py3-none-any.whl | Python 3 | none | any | Details for multipart_reader-0.2-py3-none-any.whl |
| multipart_reader-0.2-py2-none-any.whl | Python 2 | none | any | Details for multipart_reader-0.2-py2-none-any.whl |
Total release size: 42.6 kB
Release files / multipart-reader-0.2.tar.gz
| Download URL | multipart-reader-0.2.tar.gz |
|---|---|
| Size | 15.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6f93a9962a53c690f1cd991e54e1cbc86cddc5702dbeade475d34a2b2c7a8536
|
|
BLAKE2b-256 checksum How to use checksums |
161f49063205de98aacf13c9f4bb10dbdb9cf2cb38f460b045b328dc8dc32956
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / multipart_reader-0.2-py3-none-any.whl
| Download URL | multipart_reader-0.2-py3-none-any.whl |
|---|---|
| Size | 13.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7f3a73e82eb7b39d805a5aeb6267d23aa30689ec7212baa9ea70aa2fe0d04a9f
|
|
BLAKE2b-256 checksum How to use checksums |
d576af80dfa29ea3ce68f4ced4de6544e4cf47595de55c1f1f6693ca3717a28e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / multipart_reader-0.2-py2-none-any.whl
| Download URL | multipart_reader-0.2-py2-none-any.whl |
|---|---|
| Size | 13.6 kB |
| Tags | Python 2 |
|
SHA-256 checksum How to use checksums |
87a0a9c31d24200f013059d31cea4768cc07f882c8e9289ef68c382e092e52fc
|
|
BLAKE2b-256 checksum How to use checksums |
c32f13ed19fddf0873d6b71d641202868e2ff9194bde48e64e5b91193c9378dc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for multipart-reader 0.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.