k3httpmultipart
This module provides some util methods to get multipart headers and body.
k3httpmultipart is a component of pykit3 project: a python3 toolkit set.
Install
pip install k3httpmultipart
Synopsis
import os
import k3fs
import k3httpmultipart
# http request fields
file_path = "/tmp/abc.txt"
k3fs.fwrite(file_path, "123456789")
with open(file_path) as f:
fields = [
{
"name": "aaa",
"value": "abcde",
},
{"name": "bbb", "value": [f, os.path.getsize(file_path), "abc.txt"]},
]
# get http request headers; make_headers() computes Content-Length
multipart = k3httpmultipart.Multipart()
res_headers = multipart.make_headers(fields)
print(res_headers)
# output:
# {
# 'Content-Type': 'multipart/form-data; boundary=75d42525e65d4cf3ba7e1fdbc9ec9787',
# 'Content-Length': 258,
# }
# get http request body reader, from the same object so that the body
# uses the boundary in the headers
body_reader = multipart.make_body_reader(fields)
data = list(body_reader)
print(b"".join(data).decode("utf-8"))
# output:
# --75d42525e65d4cf3ba7e1fdbc9ec9787
# Content-Disposition: form-data; name=aaa
#
# abcde
# --75d42525e65d4cf3ba7e1fdbc9ec9787
# Content-Disposition: form-data; name=bbb; filename=abc.txt
# Content-Type: text/plain
#
# 123456789
# --75d42525e65d4cf3ba7e1fdbc9ec9787--
Author
Zhang Yanpo (张炎泼) drdr.xp@gmail.com
Copyright and License
The MIT License (MIT)
Copyright (c) 2015 Zhang Yanpo (张炎泼) drdr.xp@gmail.com
Metadata
Release files for k3httpmultipart 0.1.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 | Provenance | Actions |
|---|---|---|---|---|
| k3httpmultipart-0.1.9.tar.gz | 8.1 kB | Without provenance | Details for k3httpmultipart-0.1.9.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| k3httpmultipart-0.1.9-py3-none-any.whl | Python 3 | none | any | Details for k3httpmultipart-0.1.9-py3-none-any.whl |
Total release size: 14.6 kB
Release files / k3httpmultipart-0.1.9.tar.gz
| Download URL | k3httpmultipart-0.1.9.tar.gz |
|---|---|
| Size | 8.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ca6d9b461cb98214c5526443578f15d2e78337630e7045edf039a8dd3605814e
|
|
BLAKE2b-256 checksum How to use checksums |
f924ff4e9ada35b46a32d6267f9f8c5b6705875db21926a30d9cb3d00e150c4c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.8
|
Release files / k3httpmultipart-0.1.9-py3-none-any.whl
| Download URL | k3httpmultipart-0.1.9-py3-none-any.whl |
|---|---|
| Size | 6.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5a45f8c2793a45a7ab54537cad64fa5f182b7a067ef8da804d570ea9ca7eaa49
|
|
BLAKE2b-256 checksum How to use checksums |
a9c8ae933fe6e78d53d8841dd71dfd0c41900543576fe6495a4185a43f54e9d4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.8
|
Security for k3httpmultipart 0.1.9
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.