#NEWLINE# def multipart_environ( fields , files ) : #NEWLINE# #INDENT# boundary = str ( uuid . uuid1 ( ) ) #NEWLINE# env = { #NEWLINE# #INDENT# 'REQUEST_METHOD' : 'POST' , #NEWLINE# 'CONTENT_TYPE' : ( 'multipart/form-data; boundary=' + boundary ) , #NEWLINE# #UNINDENT# } #NEWLINE# wsgiref . util . setup_testing_defaults ( env ) #NEWLINE# boundary = ( '--' + boundary ) #NEWLINE# body = '' #NEWLINE# for ( name , value ) in fields : #NEWLINE# #INDENT# body += ( boundary + '\n' ) #NEWLINE# body += ( 'Content-Disposition: form-data; name="%s"\n\n' % name ) #NEWLINE# body += ( value + '\n' ) #NEWLINE# #UNINDENT# for ( name , filename , content ) in files : #NEWLINE# #INDENT# mimetype = ( str ( mimetypes . guess_type ( filename ) [ 0 ] ) or 'application/octet-stream' ) #NEWLINE# body += ( boundary + '\n' ) #NEWLINE# body += ( 'Content-Disposition: file; name="%s"; filename="%s"\n' % ( name , filename ) ) #NEWLINE# body += ( 'Content-Type: %s\n\n' % mimetype ) #NEWLINE# body += ( content + '\n' ) #NEWLINE# #UNINDENT# body += ( boundary + '--\n' ) #NEWLINE# if isinstance ( body , unicode ) : #NEWLINE# #INDENT# body = body . encode ( 'utf8' ) #NEWLINE# #UNINDENT# env [ 'CONTENT_LENGTH' ] = str ( len ( body ) ) #NEWLINE# env [ 'wsgi.input' ] . write ( body ) #NEWLINE# env [ 'wsgi.input' ] . seek ( 0 ) #NEWLINE# return env