def parse_file_upload(header_dict, post_data):
 import email, email.Message
 from cgi import parse_header
 raw_message = '\r\n'.join([('%s:%s' % pair) for pair in header_dict.items()])
 raw_message += ('\r\n\r\n' + post_data)
 msg = email.message_from_string(raw_message)
 POST = MultiValueDict()
 FILES = MultiValueDict()
 for submessage in msg.get_payload():
  if (submessage and isinstance(submessage, email.Message.Message)):
   name_dict = parse_header(submessage['Content-Disposition'])[1]
   if name_dict.has_key('filename'):
    assert (type([]) != type(submessage.get_payload())), 'Nested MIME messages are not supported'
    if (not name_dict['filename'].strip()):
     continue
    filename = name_dict['filename'][(name_dict['filename'].rfind('\\') + 1):]
    FILES.appendlist(name_dict['name'], {'filename': filename, 'content-type': ((submessage.has_key('Content-Type') and submessage['Content-Type']) or None), 'content': submessage.get_payload()})
   else:
    POST.appendlist(name_dict['name'], submessage.get_payload())
 return (POST, FILES)

def parse_file_upload ( header_dict , post_data ) : import email , email . Message from cgi import parse_header raw_message = '\r\n' . join ( [ ( '%s:%s' % pair ) for pair in header_dict . items ( ) ] ) raw_message += ( '\r\n\r\n' + post_data ) msg = email . message_from_string ( raw_message ) POST = MultiValueDict ( ) FILES = MultiValueDict ( ) for submessage in msg . get_payload ( ) : if ( submessage and isinstance ( submessage , email . Message . Message ) ) : name_dict = parse_header ( submessage [ 'Content-Disposition' ] ) [ 1 ] if name_dict . has_key ( 'filename' ) : assert ( type ( [ ] ) != type ( submessage . get_payload ( ) ) ) , 'Nested MIME messages are not supported' if ( not name_dict [ 'filename' ] . strip ( ) ) : continue filename = name_dict [ 'filename' ] [ ( name_dict [ 'filename' ] . rfind ( '\\' ) + 1 ) : ] FILES . appendlist ( name_dict [ 'name' ] , { 'filename' : filename , 'content-type' : ( ( submessage . has_key ( 'Content-Type' ) and submessage [ 'Content-Type' ] ) or None ) , 'content' : submessage . get_payload ( ) } ) else : POST . appendlist ( name_dict [ 'name' ] , submessage . get_payload ( ) ) return ( POST , FILES )
returns a tuple of .