
    i                         S r SSKrSSKrSSKrSSKJrJr  SSKJr  \R                  " \
5      r SS\S\S\S	\S
\\   SS4S jjr SS\S\\   S\\   4S jjrS\S\S\4S jrSS\S\SS4S jjrg)zCUtility functions related to storing account configuration on disk.    N)OptionalDict   )AccountAlreadyExistsErrorfilenamenameconfig	overwriteset_as_defaultreturnc                 8   [         R                  SX5        [        U 5        [        U SSS9 n[        R
                  " U5      nSSS5        WR                  U5      (       a  U(       d  [        SU S35      eX&U'   U(       aL  SXa   S	'   U H?  nXg   nXq:w  d  M  UR                  S	5      (       d  M&  U(       a  US		 M2  [        S
U S35      e   [        U SSS9 n	[        R                  " XiSSS9  SSS5        g! , (       d  f       N= f! , (       d  f       g= f)z<Save configuration data in a JSON file under the given name.z(Save configuration data for '%s' in '%s'rutf-8modeencodingNzNamed account (z2) already exists. Set overwrite=True to overwrite.Tis_default_accountzdefault_account (w   	sort_keysindent)	loggerdebug_ensure_file_existsopenjsonloadgetr   dump)
r   r   r	   r
   r   json_indataaccount_nameaccountjson_outs
             ]/home/james-whalen/.local/lib/python3.13/site-packages/qiskit_ibm_runtime/accounts/storage.pysave_configr'      s    LL;TL!	hS7	3wyy! 
4 xx~~i'dV#YZ
 	
 J +/
'( L(G#4H(I(I 453+D6 2; <  ! 
hS7	3x		$D; 
4	33 
4	32 
4	3s   C:D:
D
Dc                     [         R                  SX5        [        U 5        [        U SS9 n[        R
                  " U5      nUc  UsSSS5        $ X;   a  X1   sSSS5        $  SSS5        g! , (       d  f       g= f)z)Read configuration data from a JSON file.z*Read configuration data for '%s' from '%s'r   )r   N)r   r   r   r   r   r   )r   r   	json_filer"   s       r&   read_configr*   <   sj    
 LL=tN!	h	)Yyy#< 
*	) <: 
*	)  
*	)	)s   A-A-#A--
A;c                 F   [         R                  SX5        [        U 5        [        U SSS9 n[        R
                  " U5      nSSS5        UW;   a.  [        U SSS9 nX1	 [        R                  " X4SSS	9   SSS5        gg
! , (       d  f       NC= f! , (       d  f       g
= f)z+Delete configuration data from a JSON file.z,Delete configuration data for '%s' from '%s'r   r   r   Nr   Tr   r   F)r   r   r   r   r   r   r    )r   r   r!   r"   r%   s        r&   delete_configr,   L   s     LL?P!	hS7	3wyy! 
4 t|(w78
IIdQ? 87
  
4	3 87
 s   BB
B
B initial_contentc                 J   [         R                  R                  U 5      (       dn  [        R	                  SU 5        [         R
                  " [         R                  R                  U 5      SS9  [        U SSS9 nUR                  U5        S S S 5        g g ! , (       d  f       g = f)Nz%Create empty configuration file at %sT)exist_okr   r   r   )	ospathisfiler   r   makedirsdirnamer   write)r   r-   r)   s      r&   r   r   a   ss    77>>(##<hG 	BGGOOH-= (w79OOO, 87 $ 87s   8B
B")N)z{})__doc__r   loggingr0   typingr   r   
exceptionsr   	getLogger__name__r   strdictboolr'   r*   r,   r        r&   <module>rA      s    J   	 ! 1			8	$ _c!<!<!<&*!<7;!<MUVZ^!<	!<L 
3- d^ 
 
*	-# 	- 	-t 	-r@   