a
    ‹Qx_`  ã                   @   s|   d dl mZ d dlmZ d dlmZ d dlmZmZm	Z	 ddl
mZ G dd„ deƒZG d	d
„ d
eƒZe	 e¡Ze e¡ZdS )é    )ÚElementTree)Ú
ExpatError)ÚOAuth)ÚOAuthAdapterÚOAuthCallbackViewÚOAuthLoginViewé   )ÚOpenStreetMapProviderc                   @   s   e Zd ZdZdd„ ZdS )ÚOpenStreetMapAPIz2https://www.openstreetmap.org/api/0.6/user/detailsc              
   C   sp   |   | j¡}zDt |¡ d¡}|j}| d¡}|d urL| d|j d¡i¡ |W S  tt	t
fyj   Y d S 0 d S )NÚuserZimgZavatarZhref)ÚqueryÚurlr   Z
fromstringÚfindZattribÚupdateÚgetr   ÚKeyErrorÚ
IndexError)ÚselfZraw_xmlZuser_elementZ	user_infoZuser_avatar© r   úk/var/www/html/Ranjet/env/lib/python3.9/site-packages/allauth/socialaccount/providers/openstreetmap/views.pyÚget_user_info   s    
zOpenStreetMapAPI.get_user_infoN)Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r   r   r
      s   r
   c                   @   s&   e Zd ZejZdZdZdZdd„ Z	dS )ÚOpenStreetMapOAuthAdapterz1https://www.openstreetmap.org/oauth/request_tokenz0https://www.openstreetmap.org/oauth/access_tokenz-https://www.openstreetmap.org/oauth/authorizec                 C   s,   t ||j|j| jƒ}| ¡ }|  ¡  ||¡S )N)r
   Z	client_idZsecretÚrequest_token_urlr   Úget_providerZsociallogin_from_response)r   ÚrequestZappÚtokenÚresponseZclientÚ
extra_datar   r   r   Úcomplete_login%   s
    ÿz(OpenStreetMapOAuthAdapter.complete_loginN)
r   r   r   r	   ÚidZprovider_idr   Zaccess_token_urlZauthorize_urlr!   r   r   r   r   r      s
   r   N)Z	xml.etreer   Úxml.parsers.expatr   Z,allauth.socialaccount.providers.oauth.clientr   Z+allauth.socialaccount.providers.oauth.viewsr   r   r   Zproviderr	   r
   r   Zadapter_viewZoauth_loginZoauth_callbackr   r   r   r   Ú<module>   s   
