o
    ^[2h                     @   s8   d dl Z ddlmZ dgZdZG dd dZdd ZdS )	    N   )FrameworkIntegration	BaseOAuth)	client_idclient_secretrequest_token_urlrequest_token_paramsaccess_token_urlaccess_token_paramsrefresh_token_urlrefresh_token_paramsauthorize_urlauthorize_paramsapi_base_urlclient_kwargsserver_metadata_urlc                   @   sP   e Zd ZdZdZdZeZdddZdd Z	ddd	Z
d
d Zdd Zdd ZdS )r   z`Registry for oauth clients.

    Create an instance for registry::

        oauth = OAuth()
    Nc                 C   s"   i | _ i | _|| _|| _|| _d S N)	_registry_clientscachefetch_tokenupdate_token)selfr   r   r    r   z/home/skpark/git/infrasmart_work/infrasmart/venv/lib/python3.10/site-packages/authlib/integrations/base_client/registry.py__init__%   s
   
zBaseOAuth.__init__c                 C   s   || j v r
| j | S || jvrdS | j| \}}|dd}|r,|jr,|j}|| n|}| j||fi |}| || j}|rK|||fi |}n|dr[| j	||fi |}n
| j
||fi |}|| j |< |S )a>  Create or get the given named OAuth client. For instance, the
        OAuth registry has ``.register`` a twitter client, developers may
        access the client with::

            client = oauth.create_client("twitter")

        :param: name: Name of the remote application
        :return: OAuth remote app
        N
client_clsr   )r   r   popOAUTH_APP_CONFIGupdategenerate_client_kwargsframework_integration_clsr   getoauth1_client_clsoauth2_client_cls)r   name	overwriteconfigr   kwargs	frameworkclientr   r   r   create_client,   s&   






zBaseOAuth.create_clientFc                 K   s   ||f| j |< | |S )a  Registers a new remote application.

        :param name: Name of the remote application.
        :param overwrite: Overwrite existing config with framework settings.
        :param kwargs: Parameters for :class:`RemoteApp`.

        Find parameters for the given remote app class. When a remote app is
        registered, it can be accessed with *named* attribute::

            oauth.register('twitter', client_id='', ...)
            oauth.twitter.get('timeline')
        )r   r+   )r   r%   r&   r(   r   r   r   registerQ   s   
zBaseOAuth.registerc                 K   s   | dd }| dd }| |t}|rt|||}|s&| jr&t| j|}||d< |ds?|s;| jr;t| j|}||d< |S )Nr   r   r   )	r   load_configOAUTH_CLIENT_PARAMS_config_clientr   	functoolspartialr"   r   )r   r%   r&   r(   r   r   r'   r   r   r   r    a   s   


z BaseOAuth.generate_client_kwargsc                 C   s   | j | ||S r   )r!   r-   )r   r%   paramsr   r   r   r-   u   s   zBaseOAuth.load_configc              
   C   sX   zt | |W S  ty+ } z|| jv r| |W  Y d }~S td| |d }~ww )NzNo such client: )object__getattribute__AttributeErrorr   r+   )r   keyexcr   r   r   __getattr__x   s   
zBaseOAuth.__getattr__)NNN)F)__name__
__module____qualname____doc__r#   r$   r   r!   r   r+   r,   r    r-   r8   r   r   r   r   r      s    

%c                 C   sZ   t D ](}| |d }||vr|||< q|r*|r*t|| tr&|| | q|||< q|S r   )r.   r"   
isinstancedictr   )r'   r(   r&   kvr   r   r   r/      s   
r/   )r0   framework_integrationr   __all__r.   r   r/   r   r   r   r   <module>   s    h