<s> """<STR_LIT>""" <EOL> __author__ = '<STR_LIT>' <EOL> import json <EOL> from keyczar import errors , readers , writers <EOL> class DictReader ( readers . Reader ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , keydata ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( keydata , basestring ) : <EOL> keydata = json . loads ( keydata ) <EOL> assert isinstance ( keydata , dict ) , keydata <EOL> self . dict = keydata <EOL> def GetMetadata ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . dict [ '<STR_LIT>' ] <EOL> def GetKey ( self , version_number ) : <EOL> """<STR_LIT>""" <EOL> return self . dict [ str ( version_number ) ] <EOL> def Close ( self ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class DictWriter ( writers . Writer ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , keydata = None ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( keydata , basestring ) : <EOL> keydata = json . loads ( keydata ) <EOL> assert keydata is None or isinstance ( keydata , dict ) , keydata <EOL> self . dict = keydata if keydata is not None else { } <EOL> def WriteMetadata ( self , metadata , overwrite = True ) : <EOL> """<STR_LIT>""" <EOL> if not overwrite and '<STR_LIT>' in metadata : <EOL> raise errors . KeyczarError ( '<STR_LIT>' ) <EOL> self . dict [ '<STR_LIT>' ] = str ( metadata ) <EOL> def WriteKey ( self , key , version_number , encrypter = None ) : <EOL> """<STR_LIT>""" <EOL> key = str ( key ) <EOL> if encrypter : <EOL> key = encrypter . Encrypt ( key ) <EOL> self . dict [ str ( version_number ) ] = key <EOL> def Remove ( self , version_number ) : <EOL> """<STR_LIT>""" <EOL> self . dict . pop ( str ( version_number ) ) <EOL> def Close ( self ) : <EOL> """<STR_LIT>""" <EOL> pass </s>
