This module provides some util methods to get multipart headers and body.
Project description
k3httpmultipart
This module provides some util methods to get multipart headers and body.
k3httpmultipart is a component of pykit3 project: a python3 toolkit set.
Name
k3httpmultipart
Status
The library is considered production ready.
Install
pip install k3httpmultipart
Synopsis
import os
import k3httpmultipart
import k3fs
# http request headers
headers = {'Content-Length': 1200}
# http request fields
file_path = '/tmp/abc.txt'
k3fs.fwrite(file_path, '123456789')
fields = [
{
'name': 'aaa',
'value': 'abcde',
},
{
'name': 'bbb',
'value': [open(file_path), 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 = []
for body in body_reader:
data.append(body)
print(''.join(data))
#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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
k3httpmultipart-0.1.0.tar.gz
(4.6 kB
view details)
Built Distribution
File details
Details for the file k3httpmultipart-0.1.0.tar.gz
.
File metadata
- Download URL: k3httpmultipart-0.1.0.tar.gz
- Upload date:
- Size: 4.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.9.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ca1c22a82840b5770f93fa509baf4c7a854acb4ec82b019d61207c102a9f5c42 |
|
MD5 | 17a3a2f342b29b6fc98827b12f7a718e |
|
BLAKE2b-256 | 470fff3d7f8455c15a49857bb1afc6cc19264d776f8a9c7456021df348827aca |
File details
Details for the file k3httpmultipart-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: k3httpmultipart-0.1.0-py3-none-any.whl
- Upload date:
- Size: 6.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.9.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5531a793ecf70d32564fed19a93cab318e00f231c4c48a42fa8add9c4a161c26 |
|
MD5 | 42fcfdac3bc41946ae1634cf7ae90e72 |
|
BLAKE2b-256 | fc920eab4e90733f53f03dd5e030787892b06ebb743f087f89da403be51d7aa4 |