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.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| k3httpmultipart-0.1.6.tar.gz | 7.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| k3httpmultipart-0.1.6-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 13.4 kB
Release files / k3httpmultipart-0.1.6.tar.gz
| Download URL | k3httpmultipart-0.1.6.tar.gz |
|---|---|
| Size | 7.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ca5e4a62d8816c1f5fed140204df612be1a74a65aa208ba82b706c4a1bc7050a
|
|
BLAKE2b-256 checksum How to use checksums |
e064bc05c64c27340a95f81a1075db34e179c420ebac4d27bb8bc83312b35af3
|
| 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.6-py3-none-any.whl
| Download URL | k3httpmultipart-0.1.6-py3-none-any.whl |
|---|---|
| Size | 6.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
838cf4f5209dae8a8cc86b2e7d64335ac4077880e4eea3a3c12a3c5b7c441504
|
|
BLAKE2b-256 checksum How to use checksums |
7dae8618a22e6b524e2eb6876cb1512a50f1c115d57bd6a20b0e095d986654b6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.8
|