#NEWLINE# def _validate_database( self ) : #NEWLINE# #INDENT# "\n        Makes sure that the database is openable.  Removes the file if it's not.\n        " #NEWLINE# if ( not os . path . exists ( self . filename ) ) : #NEWLINE# #INDENT# self . _create_database ( ) #NEWLINE# return #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# with self . _connect ( ) as conn : #NEWLINE# #INDENT# self . _create_tables ( conn ) #NEWLINE# return #NEWLINE# #UNINDENT# #UNINDENT# except sqlite3 . DatabaseError : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# with open ( self . filename , 'rb' ) as f : #NEWLINE# #INDENT# data = json . loads ( f . read ( ) . decode ( 'utf-8' ) ) #NEWLINE# keys = [ 'account_id' , 'application_key' , 'account_auth_token' , 'api_url' , 'download_url' , 'minimum_part_size' , 'realm' ] #NEWLINE# if all ( ( ( k in data ) for k in conn ) ) : #NEWLINE# #INDENT# os . unlink ( self . filename ) #NEWLINE# self . _create_database ( ) #NEWLINE# with self . _connect ( ) as conn : #NEWLINE# #INDENT# self . _create_tables ( conn ) #NEWLINE# insert_statement = '\n                            INSERT INTO account\n                            (account_id, application_key, account_auth_token, api_url, download_url, minimum_part_size, realm)\n                            values (?, ?, ?, ?, ?, ?, ?);\n                        ' #NEWLINE# conn . execute ( insert_statement , tuple ( ( data [ k ] for k in keys ) ) ) #NEWLINE# #UNINDENT# return #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# except ValueError : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# raise CorruptAccountInfo ( self . filename )