o
    h	                  
   @   s   d dl mZmZ d dlmZmZ d dlmZmZm	Z	 d dl
mZ d dlmZmZmZ d dlmZ d dlmZ ded	efd
dZded	eeeeeeef f fddZd	eeef fddZdd Zdeded	efddZdeded	efddZdS )    )DictTuple)urlparse
urlunparse)HttpRequestHttpResponseJsonResponse)render)quote	urlencode
urlencoded)OAuth2Error)app_settingsrequestreturnc                 C   sZ   t t|  }tdd |d D t}|D ]}|d |t|dd|d< qt|S )z
    Django considers "safe" some characters that aren't so for oauthlib.
    We have to search for them and properly escape.
    c                 s   s    | ]}|V  qd S N ).0cr   r   _/var/www/html/pos/venv/lib/python3.10/site-packages/allauth/idp/oidc/internal/oauthlib/utils.py	<genexpr>   s    zget_uri.<locals>.<genexpr>       )safe)	listr   get_full_pathset
differencer   replacer
   r   )r   parsedunsafer   r   r   r   get_uri   s
   r!   c                 C   s@   t | }t| j }t| }| jd u rt| j|| j||fS r   )r!   r   POSTitemsextract_headersmethod
ValueError)r   uribodyheadersr   r   r   extract_params   s   

r*   c                 C   sb   | j  }|dd |dd d|v r|d |d< d|v r%|d |d< d|v r/|d |d	< |S )
z
    You need to define extract_params and make sure it does not include file
    like objects waiting for input. In Django this is request.META['wsgi.input']
    and request.META['wsgi.errors']
    z
wsgi.inputNzwsgi.errorsHTTP_AUTHORIZATIONAuthorizationHTTP_ORIGINOriginCONTENT_TYPEzContent-Type)METAcopypop)r   r)   r   r   r   r$   #   s   
r$   c                 C   sB   t |trt||d}nt||d}|  D ]\}}|||< q|S )N)status)contentr3   )
isinstancedictr   r   r#   )r)   r(   r3   responsekvr   r   r   convert_response5   s   

r:   errorc                 C   s   d|i}t | dtj |S )Nr;   zidp/oidc/error.)r	   account_settingsTEMPLATE_EXTENSION)r   r;   contextr   r   r   respond_html_error?   s   r?   c                 C   s2   t |j|jdd}|j D ]\}}|||< q|S )Nzapplication/json)r3   content_type)r   jsonstatus_coder)   r#   )r   r;   r7   r8   r9   r   r   r   respond_json_errorH   s   

rC   N)typingr   r   urllib.parser   r   django.httpr   r   r   django.shortcutsr	   oauthlib.commonr
   r   r   oauthlib.oauth2.rfc6749.errorsr   allauth.accountr   r<   strr!   r*   r$   r:   r?   rC   r   r   r   r   <module>   s    &	
	