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;
type="multipart/alternative";
boundary="-----------------------------164697015457031 3593966717980"
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:
-----------------------------164697015457031 3593966717980
Content-Disposition: form-data; name="xschemaCo ntent"
-----------------------------164697015457031 3593966717980
Content-Disposition: form-data; name="xschemaFi le"; filename="po.xs d"
Content-Type: application/octet-stream
<xs:schema targetNamespace ="http://openuri.org/easypo"
xmlns:po="http://openuri.org/easypo"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefa ult="qualified" >
<xs:element name="purchase-order">
<xs:complexType >
<xs:sequence>
<xs:element name="customer" type="po:custom er"/>
<xs:element name="date" type="xs:dateTi me"/>
<xs:element name="line-item" type="po:line-item"
minOccurs="0" maxOccurs="unbo unded"/>
<xs:element name="shipper" type="po:shippe r"
minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexTy pe name="customer" >
<xs:sequence>
<xs:element name="name" type="xs:string "/>
<xs:element name="address" type="xs:string "/>
</xs:sequence>
</xs:complexType>
<xs:complexTy pe name="line-item">
<xs:sequence>
<xs:element name="descripti on" type="xs:string "/>
<xs:element name="per-unit-ounces" type="xs:decima l"/>
<xs:element name="price" type="xs:double "/>
<xs:element name="quantity" type="xs:intege r"/>
</xs:sequence>
</xs:complexType>
<xs:complexTy pe name="shipper">
<xs:sequence>
<xs:element name="name" type="xs:string "/>
<xs:element name="per-ounce-rate" type="xs:decima l"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
-----------------------------164697015457031 3593966717980
Content-Disposition: form-data; name="which"
superclass
-----------------------------164697015457031 3593966717980
Content-Disposition: form-data; name="Submit"
Submit
-----------------------------164697015457031 3593966717980--
--
Dave Kuhlman
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;
type="multipart/alternative";
boundary="-----------------------------164697015457031 3593966717980"
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:
-----------------------------164697015457031 3593966717980
Content-Disposition: form-data; name="xschemaCo ntent"
-----------------------------164697015457031 3593966717980
Content-Disposition: form-data; name="xschemaFi le"; filename="po.xs d"
Content-Type: application/octet-stream
<xs:schema targetNamespace ="http://openuri.org/easypo"
xmlns:po="http://openuri.org/easypo"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefa ult="qualified" >
<xs:element name="purchase-order">
<xs:complexType >
<xs:sequence>
<xs:element name="customer" type="po:custom er"/>
<xs:element name="date" type="xs:dateTi me"/>
<xs:element name="line-item" type="po:line-item"
minOccurs="0" maxOccurs="unbo unded"/>
<xs:element name="shipper" type="po:shippe r"
minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexTy pe name="customer" >
<xs:sequence>
<xs:element name="name" type="xs:string "/>
<xs:element name="address" type="xs:string "/>
</xs:sequence>
</xs:complexType>
<xs:complexTy pe name="line-item">
<xs:sequence>
<xs:element name="descripti on" type="xs:string "/>
<xs:element name="per-unit-ounces" type="xs:decima l"/>
<xs:element name="price" type="xs:double "/>
<xs:element name="quantity" type="xs:intege r"/>
</xs:sequence>
</xs:complexType>
<xs:complexTy pe name="shipper">
<xs:sequence>
<xs:element name="name" type="xs:string "/>
<xs:element name="per-ounce-rate" type="xs:decima l"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
-----------------------------164697015457031 3593966717980
Content-Disposition: form-data; name="which"
superclass
-----------------------------164697015457031 3593966717980
Content-Disposition: form-data; name="Submit"
Submit
-----------------------------164697015457031 3593966717980--
--
Dave Kuhlman
Comment