<s> """<STR_LIT>""" <EOL> import os <EOL> import sys <EOL> import six <EOL> import tempfile <EOL> import mimetypes <EOL> from os import SEEK_END <EOL> if six . PY3 : <EOL> import io <EOL> import urllib . parse <EOL> import urllib . request <EOL> from email . generator import _make_boundary as choose_boundary <EOL> else : <EOL> import cStringIO as io <EOL> from six . moves import urllib <EOL> from mimetools import choose_boundary <EOL> doseq = <NUM_LIT:1> <EOL> class PostHandler ( urllib . request . BaseHandler ) : <EOL> handler_order = urllib . request . HTTPHandler . handler_order - <NUM_LIT:10> <EOL> def http_request ( self , request ) : <EOL> try : <EOL> data = request . get_data ( ) <EOL> except AttributeError : <EOL> data = request . data <EOL> if data is not None and type ( data ) != str : <EOL> data = urllib . parse . urlencode ( data , doseq ) . encode ( "<STR_LIT:utf-8>" ) <EOL> try : <EOL> request . add_data ( data ) <EOL> except AttributeError : <EOL> request . data = data <EOL> return request <EOL> https_request = http_request <EOL> class MultipartPostHandler ( urllib . request . BaseHandler ) : <EOL> handler_order = urllib . request . HTTPHandler . handler_order - <NUM_LIT:10> <EOL> def http_request ( self , request ) : <EOL> try : <EOL> data = request . get_data ( ) <EOL> except AttributeError : <EOL> data = request . data <EOL> if data is not None and type ( data ) != str : <EOL> v_files = [ ] <EOL> v_vars = [ ] <EOL> try : <EOL> for ( key , value ) in list ( data . items ( ) ) : <EOL> if hasattr ( value , '<STR_LIT>' ) : <EOL> v_files . append ( ( key , value ) ) <EOL> else : <EOL> v_vars . append ( ( key , value ) ) <EOL> except TypeError : <EOL> raise TypeError <EOL> if len ( v_files ) == <NUM_LIT:0> : <EOL> data = urllib . parse . urlencode ( v_vars , doseq ) <EOL> else : <EOL> boundary , data = self . multipart_encode ( v_vars , v_files ) <EOL> contenttype = '<STR_LIT>' % boundary <EOL> if ( <EOL> request . has_header ( '<STR_LIT:Content-Type>' ) and <EOL> request . get_header ( '<STR_LIT:Content-Type>' ) . find ( <EOL> '<STR_LIT>' ) != <NUM_LIT:0> <EOL> ) : <EOL> six . print_ ( <EOL> "<STR_LIT>" % ( <EOL> request . get_header ( '<STR_LIT>' ) , <EOL> '<STR_LIT>' <EOL> ) <EOL> ) <EOL> request . add_unredirected_header ( '<STR_LIT:Content-Type>' , contenttype ) <EOL> try : <EOL> request . add_data ( data ) <EOL> except AttributeError : <EOL> request . data = data <EOL> return request <EOL> def multipart_encode ( self , v_vars , files , boundary = None , buf = None ) : <EOL> if six . PY3 : <EOL> if boundary is None : <EOL> boundary = choose_boundary ( ) <EOL> if buf is None : <EOL> buf = io . BytesIO ( ) <EOL> for ( key , value ) in v_vars : <EOL> buf . write ( b'<STR_LIT>' + boundary . encode ( "<STR_LIT:utf-8>" ) + b'<STR_LIT:\r\n>' ) <EOL> buf . write ( <EOL> b'<STR_LIT>' + <EOL> key . encode ( "<STR_LIT:utf-8>" ) + <EOL> b'<STR_LIT:">' <EOL> ) <EOL> buf . write ( b'<STR_LIT>' + value . encode ( "<STR_LIT:utf-8>" ) + b'<STR_LIT:\r\n>' ) <EOL> for ( key , fd ) in files : <EOL> try : <EOL> filename = fd . name . split ( '<STR_LIT:/>' ) [ - <NUM_LIT:1> ] <EOL> except AttributeError : <EOL> filename = '<STR_LIT>' <EOL> contenttype = mimetypes . guess_type ( filename ) [ <NUM_LIT:0> ] or b'<STR_LIT>' <EOL> buf . write ( b'<STR_LIT>' + boundary . encode ( "<STR_LIT:utf-8>" ) + b'<STR_LIT:\r\n>' ) <EOL> buf . write ( <EOL> b'<STR_LIT>' + <EOL> b'<STR_LIT>' + key . encode ( "<STR_LIT:utf-8>" ) + b'<STR_LIT>' + <EOL> b'<STR_LIT>' + filename . encode ( "<STR_LIT:utf-8>" ) + b'<STR_LIT>' <EOL> ) <EOL> buf . write ( <EOL> b'<STR_LIT>' + <EOL> contenttype . encode ( "<STR_LIT:utf-8>" ) + <EOL> b'<STR_LIT:\r\n>' <EOL> ) <EOL> fd . seek ( <NUM_LIT:0> ) <EOL> buf . write ( <EOL> b'<STR_LIT:\r\n>' + fd . read ( ) + b'<STR_LIT:\r\n>' <EOL> ) <EOL> buf . write ( b'<STR_LIT>' ) <EOL> buf . write ( boundary . encode ( "<STR_LIT:utf-8>" ) ) <EOL> buf . write ( b'<STR_LIT>' ) <EOL> buf = buf . getvalue ( ) <EOL> return boundary , buf <EOL> else : <EOL> if boundary is None : <EOL> boundary = choose_boundary ( ) <EOL> if buf is None : <EOL> buf = io . StringIO ( ) <EOL> for ( key , value ) in v_vars : <EOL> buf . write ( '<STR_LIT>' % boundary ) <EOL> buf . write ( '<STR_LIT>' % key ) <EOL> buf . write ( '<STR_LIT>' + value + '<STR_LIT:\r\n>' ) <EOL> for ( key , fd ) in files : <EOL> try : <EOL> filename = fd . name . split ( '<STR_LIT:/>' ) [ - <NUM_LIT:1> ] <EOL> except AttributeError : <EOL> filename = '<STR_LIT>' <EOL> contenttype = mimetypes . guess_type ( filename ) [ <NUM_LIT:0> ] or '<STR_LIT>' <EOL> buf . write ( '<STR_LIT>' % boundary ) <EOL> buf . write ( '<STR_LIT>' % ( key , filename ) ) <EOL> buf . write ( '<STR_LIT>' % contenttype ) <EOL> fd . seek ( <NUM_LIT:0> ) <EOL> buf . write ( '<STR_LIT:\r\n>' + fd . read ( ) + '<STR_LIT:\r\n>' ) <EOL> buf . write ( '<STR_LIT>' + boundary + '<STR_LIT>' ) <EOL> buf = buf . getvalue ( ) <EOL> return boundary , buf <EOL> https_request = http_request <EOL> def getsize ( o_file ) : <EOL> """<STR_LIT>""" <EOL> startpos = o_file . tell ( ) <EOL> o_file . seek ( <NUM_LIT:0> ) <EOL> o_file . seek ( <NUM_LIT:0> , SEEK_END ) <EOL> size = o_file . tell ( ) <EOL> o_file . seek ( startpos ) <EOL> return size <EOL> def main ( ) : <EOL> opener = urllib . request . build_opener ( MultipartPostHandler ) <EOL> def validateFile ( url ) : <EOL> temp = tempfile . mkstemp ( suffix = "<STR_LIT>" ) <EOL> os . write ( temp [ <NUM_LIT:0> ] , opener . open ( url ) . read ( ) ) <EOL> os . remove ( temp [ <NUM_LIT:1> ] ) <EOL> if len ( sys . argv [ <NUM_LIT:1> : ] ) > <NUM_LIT:0> : <EOL> for arg in sys . argv [ <NUM_LIT:1> : ] : <EOL> validateFile ( arg ) <EOL> else : <EOL> validateFile ( "<STR_LIT>" ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> main ( ) </s>
