Skip to main content
Join the official Python Developers Survey 2018 and win valuable prizes: Start the survey!

Tasty multipart form data parser built with cython.

Project description

# Multifruits

Tasty multipart form data parser built with cython.

## Install

pip install multifruits

## Usage

`multifruits` has one `Parser` class and two helpers: `extract_filename` and

#### `Parser`

`Parser` needs the `Content-Type` header value and a handler, which could
define one or more of these methods:

on_header(name: bytes, value: bytes)
on_data(data: bytes)


from multifruits import Parser

class MyHandler:

def on_part_begin(self):
self.part = MyPart()

def on_header(self, name, value):
self.part.headers[name] = value

def on_data(self, data):

handler = MyHandler()
parser = Parser(handler, request.headers['Content-Type'])
parser.feed_data(request.body) # You can pass chunks

#### Helpers

##### `parse_content_disposition`

Takes raw `Content-Disposition` header value and returns the disposition type
(`attachment`, `form-data`, `inline` and so on) and the parameters parsed as a


dtype, params = parse_content_disposition(b'inline; filename="foo.html"')
assert dtype == b'inline'
assert params == {b'filename': b'foo.html'}

##### `extract_filename`

Takes parameters from `parse_content_disposition` as a dict and tries to
return the appropriated `str` filename (like `filename*`).


assert extract_filename({
b'filename*': "UTF-8''foo-ä-€.html".encode()
}) == 'foo-ä-€.html'

## Build from source

You need a virtualenv with cython installed, then:

git clone
cd multifruits
make compile
python develop

## Tests

To run tests:

make test

## Acknowledgements


Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
multifruits-0.1.1.tar.gz (58.6 kB) Copy SHA256 hash SHA256 Source None Mar 23, 2018

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page