Skip to main content

k3httpmultipart

Action-CI Documentation Status Package

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

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.4.tar.gz (6.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

k3httpmultipart-0.1.4-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

Details for the file k3httpmultipart-0.1.4.tar.gz.

File metadata

  • Download URL: k3httpmultipart-0.1.4.tar.gz
  • Upload date:
  • Size: 6.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for k3httpmultipart-0.1.4.tar.gz
Algorithm Hash digest
SHA256 52ee293b78299442fe92c60f0f76557fcbbbc3817011dd65d5eabe8cc64019ac
MD5 018ac7de738aa8e17b0cc655949c7cd2
BLAKE2b-256 cbaa8057a3e11e5d319fe140ebb7dc260fc0253537670cbf140dfc87693cedb7

See more details on using hashes here.

File details

Details for the file k3httpmultipart-0.1.4-py3-none-any.whl.

File metadata

File hashes

Hashes for k3httpmultipart-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 48161185503b8f172dd99fa74d6d54cd9f5fdb869188f960ce09d0e4a5b3270e
MD5 35706c01e917af056f412dc66cf96a54
BLAKE2b-256 c448d76c64b98bd5752e006feb32d2232ffdfb089bc66af44260b25d5ec1201c

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.4 This release

2 files

0.1.3

2 files

0.1.2

2 files

0.1.1

2 files

0.1.0

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page