<s> '''<STR_LIT>''' <EOL> from const import Constant <EOL> from singleton import Singleton <EOL> import json <EOL> class Storage ( Singleton ) : <EOL> def __init__ ( self ) : <EOL> """<STR_LIT>""" <EOL> if hasattr ( self , '<STR_LIT>' ) : <EOL> return <EOL> self . _init = True <EOL> self . version = <NUM_LIT:4> <EOL> self . database = { <EOL> "<STR_LIT:version>" : <NUM_LIT:4> , <EOL> "<STR_LIT:user>" : { <EOL> "<STR_LIT:username>" : "<STR_LIT>" , <EOL> "<STR_LIT:password>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> } , <EOL> "<STR_LIT>" : [ [ ] ] , <EOL> "<STR_LIT>" : { } , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : [ ] , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : [ ] , <EOL> "<STR_LIT>" : <NUM_LIT:0> , <EOL> "<STR_LIT>" : <NUM_LIT:0> , <EOL> "<STR_LIT>" : <NUM_LIT:0> , <EOL> "<STR_LIT>" : <NUM_LIT> , <EOL> } <EOL> } <EOL> self . storage_path = Constant . conf_dir + "<STR_LIT>" <EOL> self . cookie_path = Constant . conf_dir + "<STR_LIT>" <EOL> self . file = None <EOL> def load ( self ) : <EOL> try : <EOL> self . file = file ( self . storage_path , '<STR_LIT:r>' ) <EOL> self . database = json . loads ( self . file . read ( ) ) <EOL> self . file . close ( ) <EOL> except : <EOL> self . __init__ ( ) <EOL> if not self . check_version ( ) : <EOL> self . save ( ) <EOL> def check_version ( self ) : <EOL> if self . database [ "<STR_LIT:version>" ] == self . version : <EOL> return True <EOL> else : <EOL> if self . database [ "<STR_LIT:version>" ] == <NUM_LIT:1> : <EOL> self . database [ "<STR_LIT:version>" ] = <NUM_LIT:2> <EOL> self . database [ "<STR_LIT>" ] = False <EOL> elif self . database [ "<STR_LIT:version>" ] == <NUM_LIT:2> : <EOL> self . database [ "<STR_LIT:version>" ] = <NUM_LIT:3> <EOL> self . database . pop ( "<STR_LIT>" ) <EOL> elif self . database [ "<STR_LIT:version>" ] == <NUM_LIT:3> : <EOL> self . database [ "<STR_LIT:version>" ] = <NUM_LIT:4> <EOL> self . database [ "<STR_LIT:user>" ] = { '<STR_LIT:username>' : '<STR_LIT>' , '<STR_LIT:password>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } <EOL> self . check_version ( ) <EOL> return False <EOL> def save ( self ) : <EOL> self . file = file ( self . storage_path , '<STR_LIT:w>' ) <EOL> self . file . write ( json . dumps ( self . database ) ) <EOL> self . file . close ( ) </s>
