o
    [hW$                     @   s   d dl Z d dlmZmZ d dlmZ d dlmZmZm	Z	m
Z
mZ d dlmZ d dlmZ d dlmZ d dlmZ d d	lmZ e d
ZG dd dZG dd dZG dd dZG dd deeeZG dd deZdS )    N)iscoroutinefunctionmarkcoroutinefunction)ImproperlyConfigured)HttpResponseHttpResponseGoneHttpResponseNotAllowedHttpResponsePermanentRedirectHttpResponseRedirect)TemplateResponse)reverse)classonlymethod)classproperty)log_responsezdjango.requestc                   @   s   e Zd ZdZdZdd ZdS )ContextMixinz
    A default context mixin that passes the keyword arguments received by
    get_context_data() as the template context.
    Nc                 K   s&   | d|  | jd ur|| j |S )Nview)
setdefaultextra_contextupdate)selfkwargs r   /home/ubuntu/experiments/live_experiments/Pythonexperiments/Otree/venv/lib/python3.10/site-packages/django/views/generic/base.pyget_context_data   s   
zContextMixin.get_context_data)__name__
__module____qualname____doc__r   r   r   r   r   r   r      s    r   c                   @   s`   e Zd ZdZg dZdd Zedd Zedd Z	d	d
 Z
dd Zdd Zdd Zdd ZdS )Viewz}
    Intentionally simple parent class for all views. Only implements
    dispatch-by-method and simple sanity checking.
    )getpostputpatchdeleteheadoptionstracec                 K   s"   |  D ]
\}}t| || qdS )z|
        Constructor. Called in the URLconf; can contain helpful extra
        keyword arguments, and other things.
        N)itemssetattr)r   r   keyvaluer   r   r   __init__6   s   zView.__init__c                    sZ    fdd j D }|sdS t|d tfdd|dd  D s+t j dS )	Nc                    s(   g | ]}|d krt  |rt |qS )r$   )hasattrgetattr).0method)clsr   r   
<listcomp>B   s
    z&View.view_is_async.<locals>.<listcomp>Fr   c                 3   s    | ]	}t | kV  qd S N)r   )r-   h)is_asyncr   r   	<genexpr>J   s    z%View.view_is_async.<locals>.<genexpr>   z4 HTTP handlers must either be all sync or all async.)http_method_namesr   allr   r   )r/   handlersr   )r/   r3   r   view_is_async@   s   

zView.view_is_asyncc                    s   D ]}| j v rtd| jf t |s td j|f q fdd} |_|_ j|_ j|_ jj	|_	|j
 jj
  jrJt| |S )z0Main entry point for a request-response process.zAThe method name %s is not accepted as a keyword argument to %s().zm%s() received an invalid keyword %r. as_view only accepts arguments that are already attributes of the class.c                    sV    di }|j | g|R i | t|dstd j |j| g|R i |S )Nrequestz\%s instance has no 'request' attribute. Did you override setup() and forget to call super()?r   )setupr+   AttributeErrorr   dispatch)r:   argsr   r   r/   
initkwargsr   r   r   a   s   
zView.as_view.<locals>.view)r6   	TypeErrorr   r+   Z
view_classZview_initkwargsr   r   r=   __annotations____dict__r   r9   r   )r/   r@   r(   r   r   r?   r   as_viewQ   s0   



zView.as_viewc                 O   s2   t | drt | ds| j| _|| _|| _|| _dS )z1Initialize attributes shared by all view methods.r   r#   N)r+   r   r#   r:   r>   r   r   r:   r>   r   r   r   r   r;   ~   s
   
z
View.setupc                 O   sB   |j  | jv rt| |j  | j}n| j}||g|R i |S r1   )r.   lowerr6   r,   http_method_not_allowed)r   r:   r>   r   handlerr   r   r   r=      s   zView.dispatchc                    s>   t |   td|j|j |d | jr fdd}| S  S )NzMethod Not Allowed (%s): %sresponser:   c                          S r1   r   r   rJ   r   r   func      z*View.http_method_not_allowed.<locals>.func)r   _allowed_methodsr   r.   pathr9   r   r:   r>   r   rM   r   rL   r   rG      s   zView.http_method_not_allowedc                    s@   t   d|   jd< d jd< | jr fdd}| S  S )z8Handle responding to requests for the OPTIONS HTTP verb.z, ZAllow0zContent-Lengthc                      rK   r1   r   r   rL   r   r   rM      rN   zView.options.<locals>.func)r   joinrO   headersr9   rQ   r   rL   r   r$      s   
zView.optionsc                    s    fdd j D S )Nc                    s   g | ]}t  |r| qS r   )r+   upper)r-   mr   r   r   r0      s    z)View._allowed_methods.<locals>.<listcomp>)r6   rW   r   rW   r   rO      s   zView._allowed_methodsN)r   r   r   r   r6   r*   r   r9   r   rD   r;   r=   rG   r$   rO   r   r   r   r   r   %   s    


,r   c                   @   s0   e Zd ZdZdZdZeZdZdd Z	dd Z
dS )TemplateResponseMixinz.A mixin that can be used to render a template.Nc                 K   s0   | d| j | jd| j|  || jd|S )z
        Return a response, using the `response_class` for this view, with a
        template rendered with the given context.

        Pass response_kwargs to the constructor of the response class.
        content_type)r:   templatecontextusingNr   )r   rY   response_classr:   get_template_namestemplate_engine)r   r[   Zresponse_kwargsr   r   r   render_to_response   s   z(TemplateResponseMixin.render_to_responsec                 C   s   | j du r	td| j gS )z
        Return a list of template names to be used for the request. Must return
        a list. May not be called if render_to_response() is overridden.
        NztTemplateResponseMixin requires either a definition of 'template_name' or an implementation of 'get_template_names()')template_namer   rW   r   r   r   r^      s
   
z(TemplateResponseMixin.get_template_names)r   r   r   r   ra   r_   r
   r]   rY   r`   r^   r   r   r   r   rX      s    rX   c                   @   s   e Zd ZdZdd ZdS )TemplateViewzT
    Render a template. Pass keyword arguments from the URLconf to the context.
    c                 O   s   | j di |}| |S )Nr   )r   r`   )r   r:   r>   r   r[   r   r   r   r      s   
zTemplateView.getN)r   r   r   r   r   r   r   r   r   rb      s    rb   c                   @   s`   e Zd ZdZdZdZdZdZdd Zdd Z	dd	 Z
d
d Zdd Zdd Zdd Zdd ZdS )RedirectViewz&Provide a redirect on any GET request.FNc                 O   sX   | j r	| j | }n| jrt| j||d}ndS | jjdd}|r*| jr*d||f }|S )z
        Return the URL redirect to. Keyword arguments from the URL pattern
        match generating the redirect request are provided as kwargs to this
        method.
        )r>   r   NZQUERY_STRING z%s?%s)urlpattern_namer   r:   ZMETAr   query_string)r   r>   r   re   r   r   r   get_redirect_url   s   
zRedirectView.get_redirect_urlc                 O   sF   | j |i |}|r| jrt|S t|S t }td|j||d |S )NzGone: %srI   )rh   	permanentr   r	   r   r   rP   )r   r:   r>   r   re   rJ   r   r   r   r     s   zRedirectView.getc                 O      | j |g|R i |S r1   r   rE   r   r   r   r#        zRedirectView.headc                 O   rj   r1   rk   rE   r   r   r   r     rl   zRedirectView.postc                 O   rj   r1   rk   rE   r   r   r   r$     rl   zRedirectView.optionsc                 O   rj   r1   rk   rE   r   r   r   r"     rl   zRedirectView.deletec                 O   rj   r1   rk   rE   r   r   r   r      rl   zRedirectView.putc                 O   rj   r1   rk   rE   r   r   r   r!     rl   zRedirectView.patch)r   r   r   r   ri   re   rf   rg   rh   r   r#   r   r$   r"   r    r!   r   r   r   r   rc      s    rc   )loggingZasgiref.syncr   r   Zdjango.core.exceptionsr   Zdjango.httpr   r   r   r   r	   Zdjango.template.responser
   Zdjango.urlsr   Zdjango.utils.decoratorsr   Zdjango.utils.functionalr   Zdjango.utils.logr   	getLoggerloggerr   r   rX   rb   rc   r   r   r   r   <module>   s     
 &
