U
    :vh;                     @   sf   d Z ddlZddlmZ ddlZddlZddlZddlm	Z	 dd Z
G dd de	Zed	d
dZdS )z
Utilities to manage deprecation errors & warnings.

The contents of this module are internal to fpdf2, and not part of the public API.
They may change at any time without prior warning or any deprecation period,
in non-backward-compatible ways.
    Nwraps)
ModuleTypec                    s   t   fdd}|S )z<Decorator converting `txt=` arguments into `text=` argumentsc                    sN   | dd }|d k	r>d|kr$td||d< tjdtt d  | f||S )Ntxttextz.Both txt= & text= arguments cannot be providedz7The parameter "txt" has been renamed to "text" in 2.7.6
stacklevel)pop
ValueErrorwarningswarnDeprecationWarningget_stack_level)selfargskwargsZ	txt_valuefn 4/tmp/pip-unpacked-wheel-dvf6lv8i/fpdf/deprecation.pywrapper   s    z+support_deprecated_txt_arg.<locals>.wrapperr   )r   r   r   r   r   support_deprecated_txt_arg   s    r   c                       s0   e Zd Zdd Z fddZ fddZ  ZS ) WarnOnDeprecatedModuleAttributesc                 C   s   t dd S )NzrYou tried to instantied the fpdf module. You probably want to import the FPDF class instead: from fpdf import FPDF)	TypeError)r   r   r   r   __call__&   s    z)WarnOnDeprecatedModuleAttributes.__call__c                    s*   |dkrt jdtt d d S t |S N)ZFPDF_CACHE_DIRZFPDF_CACHE_MODEzefpdf.FPDF_CACHE_DIR & fpdf.FPDF_CACHE_MODE have been deprecated in favour of FPDF(font_cache_dir=...)r   )r   r   r   r   super__getattribute__)r   name	__class__r   r   __getattr__-   s    	z,WarnOnDeprecatedModuleAttributes.__getattr__c                    s0   |dkrt jdtt d d S t || d S r   )r   r   r   r   r   __setattr__)r   r   valuer   r   r   r"   ;   s    	z,WarnOnDeprecatedModuleAttributes.__setattr__)__name__
__module____qualname__r   r!   r"   __classcell__r   r   r   r   r   %   s   r   )returnc                  C   sn   ddl } tj| j}tjtj}t }d}|dk	rjt|}|	|sV|	|rj|j
}|d7 }q0qjq0|S )z>Get the first place in the call stack that is not inside fpdf2r   N   )fpdfospathdirname__file__
contextlibinspectcurrentframegetfile
startswithf_back)r*   Zpkg_dirZcontextlib_dirframenfnamer   r   r   r   J   s    

r   )__doc__r/   	functoolsr   r0   os.pathr+   r   typesr   r   r   intr   r   r   r   r   <module>   s   %