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.8
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.8.tar.gz | 7.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| k3httpmultipart-0.1.8-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 13.6 kB
Release files / k3httpmultipart-0.1.8.tar.gz
| Download URL | k3httpmultipart-0.1.8.tar.gz |
|---|---|
| Size | 7.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6bb793f84adb4538abbcf57865484dbacfa3185bcc079c10c6d4468d21e78871
|
|
BLAKE2b-256 checksum How to use checksums |
7911edb8f50056faded7fb626be65f10d15867f129f97764f26786d7a323f188
|
| 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.8-py3-none-any.whl
| Download URL | k3httpmultipart-0.1.8-py3-none-any.whl |
|---|---|
| Size | 6.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7b3353b95a38b72e36e2f09e60d19a8e36f84042d865eb7487e1feafe657d00e
|
|
BLAKE2b-256 checksum How to use checksums |
08ec3802c7dab64e6ec6173ae078e3b3ea6f39f8ff19a1e31ad4c3a001bdf36e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.8
|