
    iS9                     B   S r SSKJr  SSKrSSKJrJrJrJrJ	r	  SSK
Jr  SSKJr  SSKJrJr  SSKJr  S	S
KJr  SSKJrJr  S	SKJr  S	SKJrJrJrJr  \\S      r\\S      r \\\!      r"\\S      r#Sr$Sr%\RL                  " \'5      r( " S S5      r) " S S\)5      r*g)z&Account related classes and functions.    )abstractmethodN)OptionalLiteralListDictAny)urlparse)IAMAuthenticator)GlobalSearchV2GlobalCatalogV1)AuthBase   )ProxyConfiguration   )InvalidAccountError CloudResourceNameResolutionError)	CloudAuth)resolve_crnget_iam_api_urlget_global_search_api_urlget_global_catalog_api_url)cloudlegacyzus-eastzeu-de)ibm_quantum_platform	ibm_cloudlocalzhttps://cloud.ibm.comc                      \ rS rSrSr   S!S\S\\   S\\   S\\   4S jjr	S	\
4S
 jr\S\
S	S 4S j5       r\        S"S\S\S\\   S\\   S\\   S\\   S\\   S\\   S\\\      S\\\      S	S 4S jj5       rS#S jrS	\\\\4      4S jrS\S	\4S jrS$S jr\S\S	S4S j5       r\S\S	S4S j5       r\S\S	S4S j5       r\S\S	S4S j5       r\\S\S	S4S j5       5       r\\S\S\\   S\\   S	S4S j5       5       rS r g)%Account5   z<Class that represents an account. This is an abstract class.Ntokeninstanceproxiesverifyc                     SU l         SU l        Xl        X l        X0l        X@l        SU l        SU l        SU l        SU l	        g)a  Account constructor.

Args:
    channel: Channel type,  ``ibm_quantum_platform``, ``ibm_cloud``.
    token: Account token to use.
    instance: Service instance to use.
    proxies: Proxy configuration.
    verify: Whether to verify server's TLS certificate.
NF
channelurlr!   r"   r#   r$   private_endpointregionplans_preferencetags)selfr!   r"   r#   r$   s        ]/home/james-whalen/.local/lib/python3.13/site-packages/qiskit_ibm_runtime/accounts/account.py__init__Account.__init__8   sD      !
 &++/#	    returnc                     U R                   R                  5        VVs0 s H  u  pUc  M
  X_M     nnnU R                  (       a  U R                  R                  5       US'   U$ s  snnf )zFReturns a dictionary that represents how the account is saved on disk.r#   )__dict__itemsr#   to_dict)r-   kvresults       r.   to_saved_formatAccount.to_saved_formatS   sV    #'==#6#6#8J#841A$!$#8J<< $ 4 4 6F9 Ks
   	A$A$datac                    UR                  S5      nUR                  S5      nU(       a  [        S0 UD6OSnUR                  S5      nUR                  S5      nUR                  S5      nUR                  SS5      nUR                  S	S
5      nUR                  S5      n	UR                  S5      n
UR                  S5      nU R                  UUUUUUUU	U
US9
$ )z4Creates an account instance from data saved on disk.r'   r#   Nr(   r!   r"   r$   Tr)   Fr*   r+   r,   r&    )getr   create_account)clsr<   r'   r#   r(   r!   r"   r$   r)   r*   r+   r,   s               r.   from_saved_formatAccount.from_saved_formatZ   s     ((9%((9%3:$/w/hhuo!88J'(D)88$6>(#88$67xx!!-- " 
 	
r1   r'   r(   r)   r*   r+   r,   c                 Z    US;   a  [        UUUUUUUU	UU
S9
$ [        SSS/ SU S35      e)z*Creates an account for a specific channel.r   r   )
r(   r!   r"   r#   r$   r)   r*   r+   r'   r,   z)Invalid `channel` value. Expected one of r   r   z, got ''.)CloudAccountr   )rA   r'   r!   r(   r"   r#   r$   r)   r*   r+   r,   s              r.   r@   Account.create_accountu   sd     ;;!!1!1  &;!789	M r1   c                     g)zResolves the corresponding unique Cloud Resource Name (CRN) for the given non-unique service
instance name and updates the ``instance`` attribute accordingly.
Relevant for "ibm_cloud" channel only.Nr>   r-   s    r.   r   Account.resolve_crn        	r1   c                     g)7Retrieve all crns with the IBM Cloud Global Search API.Nr>   rJ   s    r.   list_instancesAccount.list_instances   s    r1   otherc           	      d   [        U[        5      (       d  g[        U R                  UR                  :H  U R                  UR                  :H  U R
                  UR
                  :H  U R                  UR                  :H  U R                  UR                  :H  U R                  UR                  :H  /5      $ )NF)	
isinstancer   allr'   r!   r(   r"   r#   r$   )r-   rQ   s     r.   __eq__Account.__eq__   s    %))-

ekk)EII%/-u||+	
 		
r1   c                 v   U R                  U R                  U R                  U R                  5        U R	                  U R
                  5        U R                  U R                  5        U R                  U R                  5        U R                  U R                  5        U R                  U R                  5        U $ )zValidates the account instance.

Raises:
    InvalidAccountError: if the account is invalid

Returns:
    This Account instance.
)_assert_valid_preferencesr*   r+   r,   _assert_valid_channelr'   _assert_valid_tokenr!   _assert_valid_urlr(   _assert_valid_instancer"   _assert_valid_proxiesr#   rJ   s    r.   validateAccount.validate   s     	&&t{{D4I4I499U""4<<0  ,txx(##DMM2""4<<0r1   c                 .    U S;  a  [        SU  S35      eg)z+Assert that the channel parameter is valid.rE   zTInvalid `channel` value. Expected one of ['ibm_cloud', 'ibm_quantum_platform], got 'rF   N)r   )r'   s    r.   rY   Account._assert_valid_channel   s2     @@%>>EYbJ  Ar1   c                 j    [        U [        5      (       a  [        U 5      S:  d  [        SU  S35      eg)zAssert that the token is valid.r   z9Invalid `token` value. Expected a non-empty string, got 'rF   N)rS   strlenr   )r!   s    r.   rZ   Account._assert_valid_token   s:     5#&&3u:>%KE7RTU  ,:r1   c                 D     [        U 5        g!   [        SU  S35      e= f)zAssert that the URL is valid.z&Invalid `url` value. Failed to parse 'z	' as URL.N)r	   r   r(   s    r.   r[   Account._assert_valid_url   s-    	_SM	_%(NseS\&]^^s    configc                 ,    U b  U R                  5         gg)z-Assert that the proxy configuration is valid.N)r^   )ri   s    r.   r]   Account._assert_valid_proxies   s     OO r1   c                     g)BAssert that the instance name is valid for the given account type.Nr>   r"   s    r.   r\   Account._assert_valid_instance   rL   r1   c                     g).Assert that the account preferences are valid.Nr>   r*   r+   r,   s      r.   rX   !Account._assert_valid_preferences   s     	r1   )
r'   r"   r+   r)   r#   r*   r,   r!   r(   r$   )NNT)NNNTFNNNr2   N)r2   r   )!__name__
__module____qualname____firstlineno____doc__rc   r   r   boolr/   dictr:   classmethodrB   r   r@   r   r   r   rO   objectrU   r^   staticmethodChannelTyperY   rZ   r[   r]   r   r\   rX   __static_attributes__r>   r1   r.   r   r   5   so   F
 #'04!%$$ 3-$ ,-	$
 $6  
T 
i 
 
4 
 ""&04!%+0 $04$(  c]	
 3- ,-  #4.  #49- tCy! 
 BT#s(^ 4 
F 
t 
$ { t   3 4   _s _t _ _ &8 T  
      '+Cy8<S		  r1   r   c                   ,  ^  \ rS rSrSr         SS\S\\   S\\   S\\   S\\   S	\\   S
\\   S\\	\      S\\   S\\   4U 4S jjjr
S\4S jrSS jrS\	\\\4      4S jr\S\SS4S j5       r\S
\S\	\   S\	\   SS4S j5       rSrU =r$ )rG      zTClass that represents an account with channel 'ibm_cloud' or 'ibm_quantum_platform'.Nr!   r(   r"   r#   r$   r)   r*   r+   r'   r,   c                    > [         TU ]  XXE5        U=(       d    U	S:X  a  [        O[        nXl        Xl        X`l        Xpl        Xl        Xl	        g)aU  Account constructor.

Args:
    token: Account token to use.
    url: Authentication URL.
    instance: Service instance to use.
    proxies: Proxy configuration.
    verify: Whether to verify server's TLS certificate.
    private_endpoint: Connect to private API URL.
    region: Set a region preference. Accepted values are ``us-east`` or ``eu-de``.
    plans_preference: A list of account types, ordered by preference.
    channel: Channel identifier. Accepted values are ``ibm_cloud`` or ``ibm_quantum_platform``.
        Defaults to ``ibm_quantum_platform``.
    tags: List of instance tags.
r   N)
superr/   IBM_CLOUD_API_URLIBM_QUANTUM_PLATFORM_API_URLr'   r(   r)   r*   r+   r,   )r-   r!   r(   r"   r#   r$   r)   r*   r+   r'   r,   resolved_url	__class__s               r.   r/   CloudAccount.__init__   sQ    8 	': 
!(K!7=Y 	  0 0	r1   r2   c                 T    [        U R                  U R                  U R                  S9$ )z)Returns the Cloud authentication handler.)api_keycrnprivate)r   r!   r"   r)   rJ   s    r.   get_auth_handlerCloudAccount.get_auth_handler  s    H]H]^^r1   c                     [        U R                  U R                  U R                  U R                  S9n[        U5      S:X  a  [        SU R                   S35      e[        U5      S:  a  [        R                  SUS   5        US   U l        g)a7  Resolves the corresponding unique Cloud Resource Name (CRN) for the given non-unique service
instance name and updates the ``instance`` attribute accordingly.

No-op if ``instance`` attribute is set to a Cloud Resource Name (CRN).

Raises:
    CloudResourceNameResolutionError: if CRN value cannot be resolved.
)r'   r(   r!   r"   r   z:Failed to resolve CRN value for the provided service name .r   z.Multiple CRN values found for service name %s:N)	r   r'   r(   r!   r"   rd   r   loggerwarning)r-   r   s     r.   r   CloudAccount.resolve_crn  s     LL**]]	
 s8q=2LT]]O[\]  s8a<NN@A Ar1   c           	      H   [        U R                  5      n[        U R                  US9n[	        US9n[        US9nUR                  [        U R                  5      5        UR                  [        U R                  5      5        Sn/ n  UR                  S/ SQUSS9R                  5       n/ nUR                  S	/ 5      n	U	 GH  n
U
R                  S
0 5      R                  S5      nU(       d  M.  UR                  U
R                  S5      S9R                  5       nUR                  S0 5      R                  S0 5      R                  SS5      nUR                  S0 5      R                  S0 5      R                  SS5      nUR                  U
R                  S5      UR                  5       U
R                  S5      U
R                  S5      UR                  5       S.5        GM!     UR!                  U5        UR                  S5      nU(       d   U$ GM  !   [        S5      e= f)rN   rg   )authenticatorNzservice_name:quantum-computing)r   service_plan_unique_idnamedocr,   d   )queryfieldssearch_cursorlimitzPUnable to retrieve instances. Please check that you are using a valid API token.r5   r   
extensionsr   )idoverview_uiendisplay_name metadatapricingtyper   r   r,   )r   planr   r,   pricing_typer   )r   r(   r
   r!   r   r   set_service_urlr   r   search
get_resultr   r?   get_catalog_entryappendlowerextend)r-   iam_urlr   clientcatalogr   all_crnsr9   crnsr5   itemallocationscatalog_result	plan_namer   s                  r.   rO   CloudAccount.list_instances;  s   !$((+(Am<!>8BC :488 DE: #0 '  *, " DJJw+E"hhub155lC;%,%>%>88$<= &? & jl # '**="=AA$KOOP^`bc  '**:r:>>y"MQQRXZ\] ! KK#'88E?$-OO$5$(HHV$4$(HHV$4,8,>,>,@ . OOD!"JJ7M a )I s   
"H H!c                 \    U (       a%  [        U [        5      (       d  [        SU  S35      egg)rm   z:Invalid `instance` value. Expected an IBM Cloud crn, got '' instead. N)rS   rc   r   rn   s    r.   r\   #CloudAccount._assert_valid_instancew  s4     Jx55%LXJVab  68r1   c                    U (       a*  U S;  d  [        U [        5      (       d  [        SU  S35      eU(       a$  [        U[        5      (       d  [        SU S35      eU(       a%  [        U[        5      (       d  [        SU S35      egg)rq   r   z<Invalid `region` value. Expected `us-east` or `eu-de`, got 'r   zCInvalid `plans_preference` value. Expected a list of strings, got 'z
' instead.z7Invalid `tags` value. Expected a list of strings. got 'N)rS   rc   r   listrr   s      r.   rX   &CloudAccount._assert_valid_preferences  s    
 v%99FTWAXAX%NvhVab  J/?$F$F%()5  
4..%LTFR\]  /4r1   )r'   r"   r+   r)   r*   r,   r(   )	NNNTFNNr   Nrt   )ru   rv   rw   rx   ry   rc   r   r   rz   r   r/   r   r   r   r   r   rO   r~   r\   rX   r   __classcell__)r   s   @r.   rG   rG      sF   ^
 ""&04!%+0 $04!7"%% c]% 3-	%
 ,-% % #4.% % #49-% #% sm% %N_( _<:T#s(^ 4 :x     '+Cy8<S		 r1   rG   )+ry   abcr   loggingtypingr   r   r   r   r   urllib.parser	   !ibm_cloud_sdk_core.authenticatorsr
   ibm_platform_servicesr   r   requests.authr   r#   r   
exceptionsr   r   api.authr   utilsr   r   r   r   AccountType
RegionTyperc   PlanTyper   r   r   	getLoggerru   r   r   rG   r>   r1   r.   <module>r      s    -   5 5 ! > A " ( M    w012g012
DI	  7 + 			8	$w wta7 ar1   