<s> """<STR_LIT>""" <EOL> import mimetypes <EOL> import urlparse <EOL> import httplib <EOL> def post_multipart ( host , selector , fields , files ) : <EOL> """<STR_LIT>""" <EOL> content_type , body = encode_multipart_formdata ( fields , files ) <EOL> h = httplib . HTTPConnection ( host ) <EOL> h . putrequest ( '<STR_LIT:POST>' , selector ) <EOL> h . putheader ( '<STR_LIT>' , content_type ) <EOL> h . putheader ( '<STR_LIT>' , str ( len ( body ) ) ) <EOL> h . endheaders ( ) <EOL> h . send ( body ) <EOL> response = h . getresponse ( ) <EOL> return response . read ( ) <EOL> def encode_multipart_formdata ( fields , files ) : <EOL> """<STR_LIT>""" <EOL> BOUNDARY = '<STR_LIT>' <EOL> CRLF = '<STR_LIT:\r\n>' <EOL> L = [ ] <EOL> for ( key , value ) in fields : <EOL> L . append ( '<STR_LIT>' + BOUNDARY ) <EOL> L . append ( '<STR_LIT>' % key ) <EOL> L . append ( '<STR_LIT>' ) <EOL> L . append ( str ( value ) ) <EOL> for ( key , filename , value ) in files : <EOL> L . append ( '<STR_LIT>' + BOUNDARY ) <EOL> L . append ( '<STR_LIT>' % ( key , filename ) ) <EOL> L . append ( '<STR_LIT>' % get_content_type ( filename ) ) <EOL> L . append ( '<STR_LIT>' ) <EOL> L . append ( value . read ( ) ) <EOL> L . append ( '<STR_LIT>' + BOUNDARY + '<STR_LIT>' ) <EOL> L . append ( '<STR_LIT>' ) <EOL> body = CRLF . join ( L ) <EOL> content_type = '<STR_LIT>' % BOUNDARY <EOL> return content_type , body <EOL> def posturl ( url , fields , files ) : <EOL> urlparts = urlparse . urlsplit ( url ) <EOL> return post_multipart ( urlparts [ <NUM_LIT:1> ] , urlparts [ <NUM_LIT:2> ] , fields , files ) <EOL> def get_content_type ( filename ) : <EOL> return mimetypes . guess_type ( filename ) [ <NUM_LIT:0> ] or '<STR_LIT>' <EOL> def extract_django_error ( html ) : <EOL> from BeautifulSoup import BeautifulSoup as BS <EOL> soup = BS ( html ) <EOL> return str ( soup . find ( id = "<STR_LIT>" ) ) </s>
