<s> import os <EOL> import json <EOL> import shutil <EOL> from tempfile import NamedTemporaryFile <EOL> ROOT = '<STR_LIT>' <EOL> def tempfile ( ) : <EOL> create ( '<STR_LIT>' ) <EOL> return NamedTemporaryFile ( delete = False , dir = path ( '<STR_LIT>' ) ) <EOL> def path ( id ) : <EOL> return ROOT % id <EOL> def create ( id ) : <EOL> if not os . path . exists ( path ( id ) ) : <EOL> os . makedirs ( path ( id ) ) <EOL> def destroy ( id ) : <EOL> shutil . rmtree ( path ( id ) ) <EOL> def put ( id , key , value ) : <EOL> value = json . dumps ( value ) <EOL> datapath = path ( id ) <EOL> datafile = os . path . join ( datapath , "<STR_LIT>" % ( key ) ) <EOL> try : <EOL> open ( datafile , '<STR_LIT:wb>' ) . write ( value ) <EOL> except : <EOL> raise KeyError ( "<STR_LIT>" % ( id , key , datafile ) ) <EOL> def get ( id , key ) : <EOL> datapath = path ( id ) <EOL> datafile = os . path . join ( datapath , "<STR_LIT>" % ( key ) ) <EOL> try : <EOL> value = open ( datafile , '<STR_LIT:rb>' ) . read ( ) <EOL> except : <EOL> raise KeyError ( "<STR_LIT>" % ( id , key ) ) <EOL> return json . loads ( value ) if value != "<STR_LIT>" else None <EOL> def contains ( id , key ) : <EOL> datapath = path ( id ) <EOL> datafile = os . path . join ( datapath , "<STR_LIT>" % ( key ) ) <EOL> return os . path . exists ( datafile ) <EOL> def delete ( id , key ) : <EOL> datapath = path ( id ) <EOL> datafile = os . path . join ( datapath , "<STR_LIT>" % ( key ) ) <EOL> try : <EOL> os . unlink ( datafile ) <EOL> except : <EOL> raise KeyError ( "<STR_LIT>" % ( id , key ) ) </s>
