<s> import os <EOL> import subprocess <EOL> class PlistEditor : <EOL> '''<STR_LIT>''' <EOL> def __init__ ( self , path ) : <EOL> '''<STR_LIT>''' <EOL> if not path . endswith ( '<STR_LIT>' ) : <EOL> path = path + '<STR_LIT>' <EOL> if not os . path . isfile ( path ) : <EOL> raise IOError ( "<STR_LIT>" + str ( path ) + "<STR_LIT>" ) <EOL> if not os . access ( path , os . R_OK ) : <EOL> raise IOError ( "<STR_LIT>" + str ( path ) + "<STR_LIT>" ) <EOL> self . path = str ( path ) <EOL> self . list = str ( path [ : - <NUM_LIT:6> ] ) <EOL> def __repr__ ( self ) : <EOL> '''<STR_LIT>''' <EOL> return str ( self . path ) <EOL> def read ( self , key = None ) : <EOL> '''<STR_LIT>''' <EOL> result = '<STR_LIT>' <EOL> if not key : <EOL> try : <EOL> result = subprocess . check_output ( [ '<STR_LIT>' , '<STR_LIT>' , self . list ] , stderr = subprocess . STDOUT ) <EOL> except subprocess . CalledProcessError : <EOL> return '<STR_LIT>' <EOL> else : <EOL> try : <EOL> result = subprocess . check_output ( [ '<STR_LIT>' , '<STR_LIT>' , self . list , str ( key ) ] , stderr = subprocess . STDOUT ) <EOL> except subprocess . CalledProcessError : <EOL> return '<STR_LIT>' <EOL> if result . endswith ( '<STR_LIT:\n>' ) : <EOL> result = result [ : - <NUM_LIT:1> ] <EOL> return result <EOL> def type ( self , key ) : <EOL> '''<STR_LIT>''' <EOL> if not key : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> try : <EOL> result = subprocess . check_output ( [ '<STR_LIT>' , '<STR_LIT>' , self . list , str ( key ) ] ) <EOL> except subprocess . CalledProcessError : <EOL> raise ValueError ( "<STR_LIT>" + self . path + "<STR_LIT>" ) <EOL> return result . split ( ) [ - <NUM_LIT:1> ] <EOL> def write ( self , key , value , type = "<STR_LIT:string>" ) : <EOL> '''<STR_LIT>''' <EOL> if not os . access ( self . path , os . W_OK ) : <EOL> raise IOError ( "<STR_LIT>" + self . path + "<STR_LIT>" ) <EOL> if not key : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> valids = [ '<STR_LIT:string>' , '<STR_LIT:data>' , '<STR_LIT:int>' , '<STR_LIT>' , '<STR_LIT:float>' , '<STR_LIT:bool>' , '<STR_LIT>' , '<STR_LIT:data>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> if not type in valids : <EOL> raise ValueError ( "<STR_LIT>" + str ( valids ) ) <EOL> elif type == '<STR_LIT>' : <EOL> option = '<STR_LIT>' <EOL> elif type == '<STR_LIT>' : <EOL> option = '<STR_LIT>' <EOL> else : <EOL> option = '<STR_LIT:->' + type <EOL> return subprocess . call ( [ '<STR_LIT>' , '<STR_LIT>' , self . list , str ( key ) , option , str ( value ) ] ) <EOL> def dict_add ( self , key , nestedKey , value , type = "<STR_LIT:string>" ) : <EOL> '''<STR_LIT:U+0020>''' <EOL> if not os . access ( self . path , os . W_OK ) : <EOL> raise IOError ( "<STR_LIT>" + self . path + "<STR_LIT>" ) <EOL> if not key : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> if not nestedKey : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> valids = [ '<STR_LIT:string>' , '<STR_LIT:data>' , '<STR_LIT:int>' , '<STR_LIT>' , '<STR_LIT:float>' , '<STR_LIT:bool>' , '<STR_LIT>' , '<STR_LIT:data>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> if not type in valids : <EOL> raise ValueError ( "<STR_LIT>" + str ( valids ) ) <EOL> elif type == '<STR_LIT>' : <EOL> option = '<STR_LIT>' <EOL> elif type == '<STR_LIT>' : <EOL> option = '<STR_LIT>' <EOL> else : <EOL> option = '<STR_LIT:->' + type <EOL> return subprocess . call ( [ '<STR_LIT>' , '<STR_LIT>' , self . list , str ( key ) , '<STR_LIT>' , str ( nestedKey ) , option , str ( value ) ] ) <EOL> def delete ( self , key = None ) : <EOL> '''<STR_LIT>''' <EOL> if not os . access ( self . path , os . W_OK ) : <EOL> raise IOError ( "<STR_LIT>" + self . path + "<STR_LIT>" ) <EOL> if not key : <EOL> return subprocess . call ( [ '<STR_LIT>' , '<STR_LIT>' , self . list ] ) <EOL> else : <EOL> return subprocess . call ( [ '<STR_LIT>' , '<STR_LIT>' , self . list , str ( key ) ] ) </s>
