Ë
    º2Úi÷  ã                   ó  — d dl Z d dlZd dlZd dlmZ d dlmZmZ 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mZmZmZmZ d„ Z eee¬«       e«       defd„«       «       Zdefd„Zdd„Z dd„Z!y)é    N)Úsettings)ÚPermissionDeniedÚSuspiciousOperation)ÚBadSignatureÚSigner)ÚHttpResponse)Ú
cache_page)Ú	condition)Ú	constants)Úmake_qr_code_image)ÚQRCodeOptions)Úget_url_protection_optionsÚget_qr_url_protection_tokenÚqr_code_etagÚqr_code_last_modifiedÚ!allows_external_request_from_userc                  ó   — d„ } | S )z}
    Decorator that caches the requested page if a settings named 'QR_CODE_CACHE_ALIAS' exists and is not empty or None.
    c                 óB   ‡ — t        j                  ‰ «      ˆ fd„«       }|S )Nc                 óú  •— t        | j                  j                  dd«      «      dk(  }|rÃt        t        d«      r³t        j
                  r£t        j                  t        j
                     d   }dj                  | j                  j                  d«      xs t        j                  | j                  j                  «      }  t        |t        j
                  |¬«      ‰«      | g|¢­i |¤Ž}|S  ‰| g|¢­i |¤Ž}|S )NÚcache_enabledé   ÚQR_CODE_CACHE_ALIASÚTIMEOUTztoken={}.user_pk={}Úurl_signature_enabled)ÚcacheÚ
key_prefix)ÚintÚGETÚgetÚhasattrr   r   ÚCACHESÚformatr   ÚDEFAULT_URL_SIGNATURE_ENABLEDÚuserÚpkr	   )ÚrequestÚ	view_argsÚview_kwargsr   Útimeoutr   ÚresponseÚ	view_funcs          €úD/var/www/html/acx/venv/lib/python3.12/site-packages/qr_code/views.pyÚ_wrapped_viewz7cache_qr_code.<locals>.decorator.<locals>._wrapped_view   så   ø€ ä §¡§¡°ÀÓ CÓDÈÑIˆMÙ¤¬Ð3HÔ!IÌh×NjÒNjô #Ÿ/™/¬(×*FÑ*FÑGÈ	ÑR�Ø2×9Ñ9Ø—K‘K—O‘OÐ$;Ó<ÒgÄ	×@gÑ@gØ—L‘L—O‘Oó�
ð uÐiœ: g´X×5QÑ5QÐ^hÔiÐjsÓtØðØ'òØ+6ñ�ð ˆOñ & wÐJ°ÒJ¸kÑJ�ØˆOó    )Ú	functoolsÚwraps)r+   r-   s   ` r,   Ú	decoratorz cache_qr_code.<locals>.decorator   s&   ø€ Ü	�‰˜Ó	#ó	ó 
$ð	ð$ Ðr.   © )r1   s    r,   Úcache_qr_coder3      s   € ò
ð, Ðr.   )Ú	etag_funcÚlast_modified_funcÚreturnc                 óê  — t        | «      }t        | |«       d}d| j                  v r1	 t        j                  | j                  j                  dd«      «      }nvd| j                  v r'	 t        | j                  j                  dd«      «      }nA	 t        j                  | j                  j                  dd	«      «      j                  d
«      }d}t        |||¬«      }t        ||j                   dk(  rd¬«      S d¬«      S # t        j                  $ r t        d«      ‚w xY w# t        t        f$ r t        d«      ‚w xY w# t        j                  $ r t        d«      ‚t        $ r t        d«      ‚w xY w)u  Serve an image that represents the requested QR code.

    IMPORTANT NOTE: Each boolean option mentioned below (value True/False) must be passed as `<option name>=1` for `True`, respectively `<option name>=0` for `False`.

    You may pass any argument available for :py:func:`qr_code.qrcode.utils.QRCodeOptions.__init__` to adjust the appearance of the returned QR code. The arguments must be passed as query
    string arguments in the URL. Additionally, the following arguments are available:
        * cache_enabled: boolean â€“ Tells the generator to work around the caching mechanism if it is empty (default: True/undefined).
        * token: str â€“ By default, the application only serves QR code images for authenticated URLs (requests generated from your application and addressed to your application).
            The authentication uses a HMAC to sign the request query arguments. The authentication code is passed as a query argument named `token` which is automatically generated
            by `qr_url_from_text` or `qr_url_from_data`.
    FÚbytesr.   zInvalid base64 encoded data.r   NzInvalid integer value.ÚtextÚ zutf-8TzInvalid base64 encoded text.zInvalid UTF-8 encoded text.)Úqr_code_optionsÚ
force_textÚsvgzimage/svg+xmlz	image/png)ÚcontentÚcontent_type)Úget_qr_code_option_from_requestÚcheck_image_access_permissionr   Úbase64Ú	b64decoder   ÚbinasciiÚErrorr   r   Ú
ValueErrorÚ	TypeErrorÚdecodeÚUnicodeDecodeErrorr   r   Úimage_format)r&   r;   r<   ÚdataÚimgs        r,   Úserve_qr_code_imagerM   6   sa  € ô 6°gÓ>€Oä! '¨?Ô;Ø€JØ�'—+‘+Ñð	FÜ×#Ñ# G§K¡K§O¡O°G¸SÓ$AÓB‰Dð 
�'—+‘+Ñ	ð	@Ü�w—{‘{—‘ u¨dÓ3Ó4‰Dð	EÜ×#Ñ# G§K¡K§O¡O°F¸BÓ$?Ó@×GÑGÈÓPˆDØˆJô
 ˜T°?ÈzÔ
Z€CÜ À_×EaÑEaÐejÒEj°/Ô|Ð|Ðp{Ô|Ð|øô! �~‰~ò 	FÜ%Ð&DÓEÐEð	Fûô
 œIÐ&ò 	@Ü%Ð&>Ó?Ð?ð	@ûô �~‰~ò 	FÜ%Ð&DÓEÐEÜ!ò 	EÜ%Ð&CÓDÐDð	Eús$   ©/D  Á(%D" ÂA E  Ä DÄ"D=Å 2E2c                 óD  — | j                   j                  «       }dD ]  }|j                  |d «       Œ t        |j	                  dd«      «      dk(  |d<   t        |j	                  dd«      «      dk(  |d<   t        |j	                  dd«      «      dk(  |d<   t        di |¤ŽS )N)r8   r9   r   Útokenr   Úmicror   r   ÚeciÚboost_errorr2   )r   ÚdictÚpopr   r   r   )r&   Úrequest_queryÚkeys      r,   r@   r@   ^   s¦   € Ø—K‘K×$Ñ$Ó&€MØAò %ˆØ×Ñ˜#˜tÕ$ð%ô ! ×!2Ñ!2°7¸AÓ!>Ó?À1ÑD€M�'ÑÜ˜}×0Ñ0°¸Ó:Ó;¸qÑ@€M�%ÑÜ#& }×'8Ñ'8¸ÈÓ'JÓ#KÈqÑ#P€M�-Ñ ÜÑ)˜=Ñ)Ð)r.   c                 óš   — | j                   j                  dd«      }|rt        ||«       yt        | j                  «      st        d«      ‚y)zNHandle image access protection (we do not allow external requests for anyone).rO   r:   z+You are not allowed to access this QR code.N)r   r   Úcheck_url_signature_tokenr   r$   r   )r&   r;   rO   s      r,   rA   rA   i   s@   € à�K‰K�O‰O˜G RÓ(€EÙÜ! /°5Õ9ä0°·±Ô>Ü"Ð#PÓQÐQð ?r.   c                 ó&  — t        «       }t        |t        j                     |t        j                     ¬«      }	 |j                  |«      }|j                  d«      d   }t        | |«      |k7  rt        d«      ‚y # t        $ r t        d«      ‚w xY w)N)rV   Úsaltú.éÿÿÿÿz.Request query does not match protection token.zWrong token signature.)
r   r   r   ÚSIGNING_KEYÚSIGNING_SALTÚunsignÚsplitr   r   r   )r;   rO   Úurl_protection_optionsÚsignerÚurl_protection_stringÚrandom_tokens         r,   rX   rX   s   s–   € Ü7Ó9ÐÜÐ.¬y×/DÑ/DÑEÐLbÔcl×cyÑcyÑLzÔ{€Fð9à &§¡¨eÓ 4Ðà,×2Ñ2°3Ó7¸Ñ;ˆÜ& ¸ÓEÐI^Ò^Ü"Ð#SÓTÐTð _øäò 9ÜÐ7Ó8Ð8ð9ús   »?A; Á;B)r6   N)"rB   rD   r/   Údjango.confr   Údjango.core.exceptionsr   r   Údjango.core.signingr   r   Údjango.httpr   Údjango.views.decorators.cacher	   Údjango.views.decorators.httpr
   Úqr_code.qrcoder   Úqr_code.qrcode.makerr   Úqr_code.qrcode.utilsr   Úqr_code.qrcode.server   r   r   r   r   r3   rM   r@   rA   rX   r2   r.   r,   ú<module>ro      s�   ðÛ Û Û å  ß Hß 4Ý $Ý 4Ý 2å $Ý 3Ý .÷õ òñ< �\Ð6KÔLÙƒð#} Lò #}ó ó Mð#}ðL*°ó *óRô9r.   