<s> """<STR_LIT>""" <EOL> import exceptions <EOL> import urlparse <EOL> import _winreg <EOL> import logging <EOL> from grr . lib import config_lib <EOL> from grr . lib import utils <EOL> class RegistryConfigParser ( config_lib . GRRConfigParser ) : <EOL> """<STR_LIT>""" <EOL> name = "<STR_LIT>" <EOL> root_key = None <EOL> def __init__ ( self , filename = None ) : <EOL> """<STR_LIT>""" <EOL> url = urlparse . urlparse ( filename , scheme = "<STR_LIT:file>" ) <EOL> self . filename = url . path . replace ( "<STR_LIT:/>" , "<STR_LIT:\\>" ) <EOL> self . hive = url . netloc <EOL> self . path = self . filename . lstrip ( "<STR_LIT:\\>" ) <EOL> try : <EOL> self . root_key = _winreg . CreateKeyEx ( getattr ( _winreg , self . hive ) , <EOL> self . path , <NUM_LIT:0> , <EOL> _winreg . KEY_ALL_ACCESS ) <EOL> self . parsed = self . path <EOL> except exceptions . WindowsError as e : <EOL> logging . debug ( "<STR_LIT>" , e ) <EOL> return <EOL> def RawData ( self ) : <EOL> """<STR_LIT>""" <EOL> result = config_lib . OrderedYamlDict ( ) <EOL> i = <NUM_LIT:0> <EOL> while True : <EOL> try : <EOL> name , value , value_type = _winreg . EnumValue ( self . root_key , i ) <EOL> if value_type == _winreg . REG_SZ : <EOL> result [ name ] = utils . SmartStr ( value ) <EOL> except ( exceptions . WindowsError , TypeError ) : <EOL> break <EOL> i += <NUM_LIT:1> <EOL> return result <EOL> def SaveData ( self , raw_data ) : <EOL> logging . info ( "<STR_LIT>" , self . filename ) <EOL> try : <EOL> for key , value in raw_data . items ( ) : <EOL> _winreg . SetValueEx ( self . root_key , key , <NUM_LIT:0> , _winreg . REG_SZ , <EOL> utils . SmartStr ( value ) ) <EOL> finally : <EOL> _winreg . FlushKey ( self . root_key ) </s>
