#NEWLINE# def _upload( self , filename ) : #NEWLINE# #INDENT# fp = IOStream ( ) #NEWLINE# zipped = zipfile . ZipFile ( fp , 'w' , zipfile . ZIP_DEFLATED ) #NEWLINE# zipped . write ( filename , os . path . split ( filename ) [ 1 ] ) #NEWLINE# zipped . close ( ) #NEWLINE# content = base64 . encodestring ( fp . getvalue ( ) ) #NEWLINE# if ( not isinstance ( content , str ) ) : #NEWLINE# #INDENT# content = content . decode ( 'utf-8' ) #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# return self . _execute ( Command . UPLOAD_FILE , { #NEWLINE# #INDENT# 'file' : fp , #NEWLINE# #UNINDENT# } ) [ 'value' ] #NEWLINE# #UNINDENT# except WebDriverException as e : #NEWLINE# #INDENT# if ( 'Unrecognized command: POST' in e . __str__ ( ) ) : #NEWLINE# #INDENT# return filename #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( 'Command not found: POST ' in e . __str__ ( ) ) : #NEWLINE# #INDENT# return filename #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( '{"status":405,"value":["GET","HEAD","DELETE"]}' in e . __str__ ( ) ) : #NEWLINE# #INDENT# return filename #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise e