
    f5j
                         d Z ddlZddlZddlmZ ddlmZ ddl	m
Z
  ej                  d      Z G d dej                        Zy))PdfUnspHandler    N)PdfiumError	pypdfium2c                   >    e Zd ZdZdZd Zd Zed        Zd Z	ddZ
y)	r   am  
    Unsupported feature handler helper class.
    
    Attributes:
        raw (UNSUPPORT_INFO):
           The underlying pdfium ``UNSUPPORT_INFO`` struct.
        handlers (dict[str, typing.Callable]):
            A dictionary of named handler functions to be called with an unsupported code (:attr:`FPDF_UNSP_*`) when PDFium detects an unsupported feature.
    Nc                 H    i | _         t        j                  d      | _        y )N   )version)handlerspdfium_cUNSUPPORT_INFOrawselfs    T/var/www/html/qr/venv/lib/python3.12/site-packages/pypdfium2/_helpers/unsupported.py__init__zPdfUnspHandler.__init__   s    **15    c                 R    | j                   j                         D ]
  } ||        y N)r
   values)r   _typehandlers       r   __call__zPdfUnspHandler.__call__    s%    }}++- 	GDM	r   c                 n    t         j                  dt        j                  j	                  |               y )NzUnsupported PDF feature: )
lib_loggerwarningpdfium_iUnsupportedInfoToStrget)r   s    r   _defaultzPdfUnspHandler._default$   s+    6x7T7T7X7XY]7^6_`ar   c                 X    t        | j                         t        | j                         y r   )idr
   r   r   s    r   _keepzPdfUnspHandler._keep(   s    
4==
488r   c                 h   t         j                  rt        d      t        j                  | j
                  d|        t        j                  | j
                        }|st        d      | t         _        t        j                  | j                         |rt         j                  | j                  d<   yy)a  
        Register the handler with PDFium, and install an exit function that will keep the object alive until the end of session.
        
        Once set up, a :class:`.PdfUnspHandler` cannot be removed. It stands and falls with the library.
        Thus, this function can only be called once in a session.
        However, you may change the wrapped :attr:`.handlers` callbacks.
        Call ``.handlers.clear()`` to remove all handlers, thereby effectively disabling the instance.
        
        Parameters:
            add_default (bool):
                If True, add a default callback that will log unsupported features as warning.
        zAOnly one PdfUnspHandler instance can be registered for a session.FSDK_UnSupport_Handlerz)Failed to register PdfUnspHandler object.defaultN)r   	SINGLETONRuntimeErrorr   set_callbackr   r   FSDK_SetUnSpObjProcessHandlerr   atexitregisterr#   r    r
   )r   add_defaultoks      r   setupzPdfUnspHandler.setup,   s     ##bccdhh(@$G33DHH=IJJ#'  	

#'5'>'>DMM)$ r   )T)__name__
__module____qualname____doc__r'   r   r   staticmethodr    r#   r/    r   r   r   r      s8     I6 b b?r   r   )__all__r+   loggingpypdfium2.rawr   r   pypdfium2.internalinternalr   pypdfium2._helpers.miscr   	getLoggerr   AutoCastabler   r5   r   r   <module>r>      s?         % /W{+
6?h++ 6?r   