
    _f                     "   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!dS )    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                 F     t          j                    fd            }|S )Nc                    t          | j                            dd                    dk    }|rt          t          d          rt          j        rt          j        t          j                 d         }d                    | j                            d          pt          j	        | j
        j                  }  t          |t          j        |                    | g|R i |}n | g|R 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          ?/var/www/html/env/lib/python3.11/site-packages/qr_code/views.py_wrapped_viewz7cache_qr_code.<locals>.decorator.<locals>._wrapped_view   s    C CDDIM K3H!I!I KhNj K #/(*FG	R299KOO$;<<g	@gLO 
 ui:gX5Q^hiiijstt'  +6 
 &IwJJJJkJJO    )	functoolswraps)r+   r-   s   ` r,   	decoratorz cache_qr_code.<locals>.decorator   s9    		#	#	 	 	 	 
$	#	$ r.    )r1   s    r,   cache_qr_coder3      s    
  , r.   )	etag_funclast_modified_funcreturnc                    t          |           }t          | |           d}d| j        v rQ	 t          j        | j                            dd                    }n# t          j        $ r t          d          w xY wd| j        v rN	 t          | j                            dd                    }n# t          t          f$ r t          d          w xY w	 t          j        | j                            dd	                                        d
          }d}n:# t          j        $ r t          d          t          $ r t          d          w xY wt          |||          }t          ||j        dk    rdnd          S )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   s   " 6g>>O!'?;;;J'+	F#GKOOGS$A$ABBDD~ 	F 	F 	F%&DEEE	F	'+			@w{ud3344DDI& 	@ 	@ 	@%&>???	@	E#GKOOFB$?$?@@GGPPDJJ~ 	F 	F 	F%&DEEE! 	E 	E 	E%&CDDD	E
T?z
Z
Z
ZC_EaejEjEj//p{||||s$   -A A9(B/ /!CAD 7Ec                 ~   | j                                         }dD ]}|                    |d            t          |                    dd                    dk    |d<   t          |                    dd                    dk    |d<   t          |                    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@   a   s    K$$&&MA % %#t$$$$ !2!27A!>!>??1DM'}00::;;q@M%#&}'8'8'J'J#K#Kq#PM- ))=)))r.   c                     | j                             dd          }|rt          ||           dS t          | j                  st          d          dS )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   l   sd    KOOGR((E R!/5999990>> 	R"#PQQQ	R 	Rr.   c                 f   t                      }t          |t          j                 |t          j                           }	 |                    |          }|                    d          d         }t          | |          |k    rt          d          d S # 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   v   s    799.y/DELbclcyLz{{{F9 &e 4 4,22377;&EEI^^^"#STTT _^ 9 9 978889s   AB B0)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 H H H H H H H 4 4 4 4 4 4 4 4 $ $ $ $ $ $ 4 4 4 4 4 4 2 2 2 2 2 2 $ $ $ $ $ $ 3 3 3 3 3 3 . . . . . .               < \6KLLL&}L &} &} &}  ML&}R* * * * *R R R R9 9 9 9 9 9r.   