<s> """<STR_LIT>""" <EOL> __author__ = '<STR_LIT>' <EOL> import threading <EOL> try : <EOL> import simplejson <EOL> except ImportError : <EOL> try : <EOL> from django . utils import simplejson <EOL> except ImportError : <EOL> import json as simplejson <EOL> from client import Storage as BaseStorage <EOL> from client import Credentials <EOL> class Storage ( BaseStorage ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , filename ) : <EOL> self . _filename = filename <EOL> self . _lock = threading . Lock ( ) <EOL> def acquire_lock ( self ) : <EOL> """<STR_LIT>""" <EOL> self . _lock . acquire ( ) <EOL> def release_lock ( self ) : <EOL> """<STR_LIT>""" <EOL> self . _lock . release ( ) <EOL> def locked_get ( self ) : <EOL> """<STR_LIT>""" <EOL> credentials = None <EOL> try : <EOL> f = open ( self . _filename , '<STR_LIT:r>' ) <EOL> content = f . read ( ) <EOL> f . close ( ) <EOL> except IOError : <EOL> return credentials <EOL> try : <EOL> credentials = Credentials . new_from_json ( content ) <EOL> credentials . set_store ( self ) <EOL> except ValueError : <EOL> pass <EOL> return credentials <EOL> def locked_put ( self , credentials ) : <EOL> """<STR_LIT>""" <EOL> f = open ( self . _filename , '<STR_LIT:w>' ) <EOL> f . write ( credentials . to_json ( ) ) <EOL> f . close ( ) </s>
