How to parse multi-part content

Dave Kuhlman dkuhlman at
Fri Sep 24 21:32:43 CEST 2004

Suppose that I have content that looks like what I've included at
the end of this message.  Is there something in the standard
Python library that will help me parse it, break into the parts
separated by the boundary strings, extract headers from each
sub-part, etc?

Do I need to add something like the following to the beginning?

    Content-Type: multipart/related;

I've tried working with the email, mimetools, and multifile
modules in the standard library.  But my understanding of these
things is dim, and I have not had success.

Is there a beginner's guide somewhere that I should read?

In case you are curious, this is content posted to my Zope server
when I include an element '<input type="file" .../>' in my form.

Here is the content that I need to parse:

    Content-Disposition: form-data; name="xschemaContent"

    Content-Disposition: form-data; name="xschemaFile"; filename="po.xsd"
    Content-Type: application/octet-stream

    <xs:schema targetNamespace=""

        <xs:element name="purchase-order">
                    <xs:element name="customer" type="po:customer"/>
                    <xs:element name="date" type="xs:dateTime"/>
                    <xs:element name="line-item" type="po:line-item"
minOccurs="0" maxOccurs="unbounded"/>
                    <xs:element name="shipper" type="po:shipper"
        <xs:complexType name="customer">
                <xs:element name="name" type="xs:string"/>
                <xs:element name="address" type="xs:string"/>
        <xs:complexType name="line-item">
                <xs:element name="description" type="xs:string"/>
                <xs:element name="per-unit-ounces" type="xs:decimal"/>
                <xs:element name="price" type="xs:double"/>
                <xs:element name="quantity" type="xs:integer"/>
        <xs:complexType name="shipper">
                <xs:element name="name" type="xs:string"/>
                <xs:element name="per-ounce-rate" type="xs:decimal"/>

    Content-Disposition: form-data; name="which"

    Content-Disposition: form-data; name="Submit"


Dave Kuhlman

More information about the Python-list mailing list