
    gl                         d dl 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 d dlmZ d dlmZ d d	lmZmZ d
Zd Zd Zd Zd Zd Zd Zd Zd Z edg      d        Z edg      d        Zy)    )serializersstatus)api_view)Response)forms)User)HttpResponse)engines)CaptchaField)CaptchaModelSerializerCaptchaSerializera  
<!doctype html>
<html>
    <head>
        <meta http-equiv="Content-type" content="text/html; charset=utf-8">
        <title>captcha test</title>
    </head>
    <body>
        {% if passed %}
        <p style="color:green">Form validated</p>
        {% endif %}
        {% if form.errors %}
        {{form.errors}}
        {% endif %}

        <form action="{% url 'captcha-test' %}" method="post">
            {{form.as_p}}
            <p><input type="submit" value="Continue &rarr;"></p>
        </form>
    </body>
</html>
c                 2    t         d   j                  |       S )Ndjango)r
   from_string)template_strings    V/var/www/html/brdwt/brdwt/brdwtenv/lib/python3.12/site-packages/captcha/tests/views.py_get_templater   &   s    8((99    c                     d}| j                   r% || j                         }|j                         r
d}n |       }t        t              }t	        |j                  t        ||      |             S )NFT)passedform)contextrequest)POSTis_validr   TEST_TEMPLATEr	   renderdict)r   
form_classr   r   ts        r   _testr!   *   s_    F||',,'==?F|m$A	V$7I r   c                 L     G d dt         j                        }t        | |      S )Nc                   f    e Zd Z ej                  d      Z ej                         Z ed      Z	y)test.<locals>.CaptchaTestFormd   
max_lengthasdasd	help_textN)
__name__
__module____qualname__r   	CharFieldsubject
EmailFieldsenderr   captcha r   r   CaptchaTestFormr$   ;   s,    !%//S1!!!#2r   r4   r   Formr!   r   r4   s     r   testr8   :   s!    3%** 3
 /**r   c                 L     G d dt         j                        }t        | |      S )Nc                   z    e Zd Z ej                  d      Z ej                         Z ed      Z	 G d d      Z
y)-test_model_form.<locals>.CaptchaTestModelFormr%   r&   r(   r)   c                       e Zd ZeZdZy)2test_model_form.<locals>.CaptchaTestModelForm.Metar/   r1   r2   Nr+   r,   r-   r   modelfieldsr3   r   r   Metar=   I       E5Fr   rB   Nr+   r,   r-   r   r.   r/   r0   r1   r   r2   rB   r3   r   r   CaptchaTestModelFormr;   D   s6    !%//S1!!!#2	6 	6r   rE   r   	ModelFormr!   r   rE   s     r   test_model_formrI   C   "    6u 6 .//r   c                 L     G d dt         j                        }t        | |      S )Nc                   |    e Zd Z ej                  d      Z ej                         Z ed       Z	 G d d      Z
y)3test_custom_generator.<locals>.CaptchaTestModelFormr%   r&   c                       y)N)111111rO   r3   r3   r   r   <lambda>z<test_custom_generator.<locals>.CaptchaTestModelForm.<lambda>T   s    r   )	generatorc                       e Zd ZeZdZy)8test_custom_generator.<locals>.CaptchaTestModelForm.Metar>   Nr?   r3   r   r   rB   rS   V   rC   r   rB   NrD   r3   r   r   rE   rM   Q   s7    !%//S1!!!#)EF	6 	6r   rE   rF   rH   s     r   test_custom_generatorrT   P   rJ   r   c                 L     G d dt         j                        }t        | |      S )Nc                   .    e Zd Z ed ed            Zy)>test_custom_error_message.<locals>.CaptchaTestErrorMessageFormr(   zTEST CUSTOM ERROR MESSAGE)invalid)r*   error_messagesN)r+   r,   r-   r   r   r2   r3   r   r   CaptchaTestErrorMessageFormrW   ^   s    t<W/X
r   rZ   r5   )r   rZ   s     r   test_custom_error_messager[   ]   s"    
ejj 

 566r   c                 L     G d dt         j                        }t        | |      S )Nc                   h    e Zd Z ej                         Z ej                  d      Z edd      Z	y)*test_non_required.<locals>.CaptchaTestFormr%   r&   r(   F)r*   requiredN)
r+   r,   r-   r   r0   r1   r.   r/   r   r2   r3   r   r   r4   r^   g   s.    !!!#!%//S1EBr   r4   r5   r7   s     r   test_non_requiredr`   f   s#    C%** C
 /**r   c                 L     G d dt         j                        }t        | |      S )Nc                   x    e Zd Z ej                         Z ej                  d      Z ed      Z	 ed      Z
y)'test_id_prefix.<locals>.CaptchaTestFormr%   r&   form1)	id_prefixform2N)r+   r,   r-   r   r0   r1   r.   r/   r   captcha1captcha2r3   r   r   r4   rc   p   s6    !!!#!%//S1'2'2r   r4   r5   r7   s     r   test_id_prefixri   o   s!    3%** 3 /**r   r   c                     t        | j                        }|j                  d       t        t        j
                        S )NdataTraise_exceptionr   )r   r   r   r   r   HTTP_200_OK)r   
serializers     r   test_serializerrr   y   s2    "5J-6--..r   c                      G d dt               } || j                        }|j                  d       t        t        j
                        S )Nc                   h    e Zd Z ej                  d      Z ej                         Z G d d      Zy)9test_model_serializer.<locals>.UserCaptchaModelSerializerr%   r&   c                       e Zd ZeZdZy)>test_model_serializer.<locals>.UserCaptchaModelSerializer.Meta)r/   r1   captcha_codecaptcha_hashkeyNr?   r3   r   r   rB   rw      s    EMFr   rB   N)	r+   r,   r-   r   r.   r/   r0   r1   rB   r3   r   r   UserCaptchaModelSerializerru      s0    '+''37''')	N 	Nr   rz   rk   Trm   ro   )r   r   r   r   r   rp   )r   rz   rq   s      r   test_model_serializerr{      sC    N%; N ,>J-6--..r   N)rest_frameworkr   r   rest_framework.decoratorsr   rest_framework.responser   r   r   django.contrib.auth.modelsr   django.httpr	   django.templater
   captcha.fieldsr   captcha.serializersr   r   r   r   r!   r8   rI   rT   r[   r`   ri   rr   r{   r3   r   r   <module>r      s    . . ,  + $ # ' I0: +
0
07++ 
6(/ / 
6(/ /r   