Ñò ›ˆQc @sõdZddkZddkZddkZddkZddkZddklZddkl Z ddkl Z ddk l Z eieƒZhZeiƒZdefd„ƒYZd efd „ƒYZed „Zd efd „ƒYZdS(sNMulti-credential file store with lock support. This module implements a JSON credential store where multiple credentials can be stored in one file. That file supports locking both in a single process and across processes. The credential themselves are keyed off of: * client_id * user_agent * scope The format of the stored data is like so: { 'file_version': 1, 'data': [ { 'key': { 'clientId': '', 'userAgent': '', 'scope': '' }, 'credential': { # JSON serialized Credentials. } } ] } iÿÿÿÿN(t simplejson(tStorage(t Credentials(t LockedFiletErrorcBseZdZRS(sBase error for this module.(t__name__t __module__t__doc__(((sm/Users/riccardo/git/gcloud/packages/gcutil-1.7.1/lib/google_api_python_client/oauth2client/multistore_file.pyR4stNewerCredentialStoreErrorcBseZdZRS(s7The credential store is a newer version that supported.(RRR(((sm/Users/riccardo/git/gcloud/packages/gcutil-1.7.1/lib/google_api_python_client/oauth2client/multistore_file.pyR9scCsŽtiitii|ƒƒ}tiƒzti|t||ƒƒ}Wdti ƒXt |ƒt jodi |ƒ}n|i |||ƒS(s²Get a Storage instance for a credential. Args: filename: The JSON file storing a set of credentials client_id: The client_id for the credential user_agent: The user agent for the credential scope: string or list of strings, Scope(s) being requested warn_on_readonly: if True, log a warning if the store is readonly Returns: An object derived from client.Storage for getting/setting the credential. Nt (tostpathtrealpatht expandusert_multistores_locktacquiret _multistorest setdefaultt _MultiStoretreleasettypetlisttjoint _get_storage(tfilenamet client_idt user_agenttscopetwarn_on_readonlyt multistore((sm/Users/riccardo/git/gcloud/packages/gcutil-1.7.1/lib/google_api_python_client/oauth2client/multistore_file.pytget_credential_storage>s  RcBsœeZdZed„Zdefd„ƒYZd„Zd„Zd„Z d„Z d„Z d „Z d „Z d „Zd „Zd „Zd„Zd„ZRS(s-A file backed store for multiple credentials.cCsMt|ddƒ|_tiƒ|_t|_||_|iƒd|_ dS(sGInitialize the class. This will create the file if necessary. sr+btrbN( Rt_filet threadingtLockt _thread_locktFalset _read_onlyt_warn_on_readonlyt_create_file_if_neededtNonet_data(tselfRR((sm/Users/riccardo/git/gcloud/packages/gcutil-1.7.1/lib/google_api_python_client/oauth2client/multistore_file.pyt__init__\s    t_StoragecBsDeZdZd„Zd„Zd„Zd„Zd„Zd„ZRS(sBA Storage object that knows how to read/write a single credential.cCs(||_||_||_||_dS(N(t _multistoret _client_idt _user_agentt_scope(R*RRRR((sm/Users/riccardo/git/gcloud/packages/gcutil-1.7.1/lib/google_api_python_client/oauth2client/multistore_file.pyR+ts   cCs|iiƒdS(s]Acquires any lock necessary to access this Storage. This lock is not reentrant. N(R-t_lock(R*((sm/Users/riccardo/git/gcloud/packages/gcutil-1.7.1/lib/google_api_python_client/oauth2client/multistore_file.pyt acquire_lockzscCs|iiƒdS(suRelease the Storage lock. Trying to release a lock that isn't held will result in a RuntimeError. N(R-t_unlock(R*((sm/Users/riccardo/git/gcloud/packages/gcutil-1.7.1/lib/google_api_python_client/oauth2client/multistore_file.pyt release_lockscCs=|ii|i|i|iƒ}|o|i|ƒn|S(sRetrieve credential. The Storage lock must be held when this is called. Returns: oauth2client.client.Credentials (R-t_get_credentialR.R/R0t set_store(R*t credential((sm/Users/riccardo/git/gcloud/packages/gcutil-1.7.1/lib/google_api_python_client/oauth2client/multistore_file.pyt locked_get‰s  cCs|ii||iƒdS(sWrite a credential. The Storage lock must be held when this is called. Args: credentials: Credentials, the credentials to store. N(R-t_update_credentialR0(R*t credentials((sm/Users/riccardo/git/gcloud/packages/gcutil-1.7.1/lib/google_api_python_client/oauth2client/multistore_file.pyt locked_put—scCs#|ii|i|i|iƒdS(sžDelete a credential. The Storage lock must be held when this is called. Args: credentials: Credentials, the credentials to store. N(R-t_delete_credentialR.R/R0(R*((sm/Users/riccardo/git/gcloud/packages/gcutil-1.7.1/lib/google_api_python_client/oauth2client/multistore_file.pyt locked_delete¡s( RRRR+R2R4R8R;R=(((sm/Users/riccardo/git/gcloud/packages/gcutil-1.7.1/lib/google_api_python_client/oauth2client/multistore_file.pyR,qs     cCsdtii|iiƒƒpDtidƒ}z t|iiƒdƒiƒWdti|ƒXndS(s±Create an empty file if necessary. This method will not initialize the file. Instead it implements a simple version of "touch" to ensure the file has been created. isa+bN(R R texistsR Rtumasktopentclose(R*t old_umask((sm/Users/riccardo/git/gcloud/packages/gcutil-1.7.1/lib/google_api_python_client/oauth2client/multistore_file.pyR'¬s  cCsÒ|iiƒ|iiƒ|iiƒp5t|_|ioti d|ii ƒƒq_nt i i |ii ƒƒdjo$tidƒh|_|iƒn*|i p|idjo|iƒndS(sLock the entire multistore.s€The credentials file (%s) is not writable. Opening in read-only mode. Any refreshed credentials will only be valid for this run.is"Initializing empty multistore fileN(R#RR t open_and_lockt is_lockedtTrueR%R&tloggertwarnRR R tgetsizetdebugR)t_writeR(t_refresh_data_cache(R*((sm/Users/riccardo/git/gcloud/packages/gcutil-1.7.1/lib/google_api_python_client/oauth2client/multistore_file.pyR1¹s     "  cCs|iiƒ|iiƒdS(s#Release the lock on the multistore.N(R tunlock_and_closeR#R(R*((sm/Users/riccardo/git/gcloud/packages/gcutil-1.7.1/lib/google_api_python_client/oauth2client/multistore_file.pyR3Ðs cCsC|iiƒpt‚|iiƒidƒti|iiƒƒS(s¬Get the raw content of the multistore file. The multistore must be locked when this is called. Returns: The contents of the multistore decoded as JSON. i(R#tlockedtAssertionErrorR t file_handletseekRtload(R*((sm/Users/riccardo/git/gcloud/packages/gcutil-1.7.1/lib/google_api_python_client/oauth2client/multistore_file.pyt_locked_json_readÕscCsx|iiƒpt‚|iodS|iiƒidƒti||iiƒdt ddƒ|iiƒi ƒdS(s¶Write a JSON serializable data structure to the multistore. The multistore must be locked when this is called. Args: data: The data to be serialized and written. Nit sort_keystindenti( R#RMRNR%R RORPRtdumpREttruncate(R*tdata((sm/Users/riccardo/git/gcloud/packages/gcutil-1.7.1/lib/google_api_python_client/oauth2client/multistore_file.pyt_locked_json_writeás  %cCsh|_y|iƒ}Wn!tj otidƒdSXd}y|d}Wn tj otidƒnX|djotd|ƒ‚ng}y|d}Wnttfj onXxQ|D]I}y&|i|ƒ\}}||i|s