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 headers
headers = {"Content-Length": 1200}
# 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
multipart = k3httpmultipart.Multipart()
res_headers = multipart.make_headers(fields, headers=headers)
print(res_headers)
# output:
# {
# 'Content-Type': 'multipart/form-data; boundary=FormBoundaryrGKCBY7',
# 'Conetnt-Length': 1200,
# }
# get http request body reader
multipart = k3httpmultipart.Multipart()
body_reader = multipart.make_body_reader(fields)
data = list(body_reader)
print(b"".join(data).decode("utf-8"))
# output:
# --FormBoundaryrGKCBY7
# Content-Disposition: form-data; name=aaa
#
# abcde
# --FormBoundaryrGKCBY7
# Content-Disposition: form-data; name=bbb; filename=abc.txt
# Content-Type: text/plain
#
# 123456789
# --FormBoundaryrGKCBY7--
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.5
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.5.tar.gz | 7.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| k3httpmultipart-0.1.5-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 13.3 kB
Release files / k3httpmultipart-0.1.5.tar.gz
| Download URL | k3httpmultipart-0.1.5.tar.gz |
|---|---|
| Size | 7.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
95acd0913f9f3c55403ee93901298c5a59422f44b734a6c3d78e0587d05b0817
|
|
BLAKE2b-256 checksum How to use checksums |
fba527fe0888f538af8e97f2c53905c88521580ed4358297e19b6b238f915999
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.7
|
Release files / k3httpmultipart-0.1.5-py3-none-any.whl
| Download URL | k3httpmultipart-0.1.5-py3-none-any.whl |
|---|---|
| Size | 6.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
95902fa24a59c843ef656cec1d8c3b3232408d906b088cca38faae6655612b20
|
|
BLAKE2b-256 checksum How to use checksums |
bc68e6e03fa3bb9646c2969150988d450ae0bc0a0231208f13e8db7bb1092a7f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.7
|