B
    ç¹`÷  ã               @   sì   d Z dZddlZddlZddlZeek	r,eneee	fZ
G dd„ deƒZeƒ ZG dd„ deƒZejZG dd	„ d	eƒZG d
d„ deƒZG dd„ deƒZG dd„ deƒZG dd„ deƒZefdd„Zefdd„ZG dd„ deƒZdefdd„ZdS )ziDeprecation Support

This module provides utilities to ease the development of backward-compatible
code.
ZreStructuredTexté    Nc               @   s@   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Z	dS )Ú
ShowSwitchzSimple stack-based switch.c             C   s
   g | _ d S )N)Ústack)Úself© r   úd/home/kop/projects/devel/pgwui/test_venv/lib/python3.7/site-packages/zope/deprecation/deprecation.pyÚ__init__   s    zShowSwitch.__init__c             C   s   | j  ¡  d S )N)r   Úpop)r   r   r   r   Úon    s    zShowSwitch.onc             C   s   | j  d¡ d S )NF)r   Úappend)r   r   r   r   Úoff#   s    zShowSwitch.offc             C   s
   g | _ d S )N)r   )r   r   r   r   Úreset&   s    zShowSwitch.resetc             C   s
   | j g kS )N)r   )r   r   r   r   Ú__call__)   s    zShowSwitch.__call__c             C   s   d| ƒ rdpd S )Nz<ShowSwitch %s>r	   r   r   )r   r   r   r   Ú__repr__,   s    zShowSwitch.__repr__N)
Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r	   r   r   r   r   r   r   r   r   r      s   r   c               @   s   e Zd Zdd„ Zdd„ ZdS )Ú
Suppressorc             C   s   t  ¡  d S )N)Ú__show__r   )r   r   r   r   Ú	__enter__7   s    zSuppressor.__enter__c             G   s   t  ¡  d S )N)r   r	   )r   Zignoredr   r   r   Ú__exit__:   s    zSuppressor.__exit__N)r   r   r   r   r   r   r   r   r   r   5   s   r   c               @   s8   e Zd Zdd„ Zefdd„Zdd„ Zdd„ Zd	d
„ ZdS )ÚDeprecationProxyc             C   s   || _ i | _d S )N)Ú"_DeprecationProxy__original_moduleÚ_DeprecationProxy__deprecated)r   Úmoduler   r   r   r   @   s    zDeprecationProxy.__init__c             C   s4   t |ttfƒs|f}x|D ]}||f| j|< qW dS )zDeprecate the given names.N)Ú
isinstanceÚtupleÚlistr   )r   ÚnamesÚmessageÚclsÚnamer   r   r   Ú	deprecateD   s    
zDeprecationProxy.deprecatec             C   sr   |dks|  d¡rt| |ƒS |dkr*tjS |t| dƒkrbtƒ rb| j| \}}t |d | |d¡ tt| dƒ|ƒS )Nr"   Ú_DeprecationProxy__Ú	__class__r   z: é   r   )	Ú
startswithÚogetattrÚtypesÚ
ModuleTyper   r   ÚwarningsÚwarnÚgetattr)r   r!   Úmsgr    r   r   r   Ú__getattribute__K   s    

z!DeprecationProxy.__getattribute__c             C   s*   |  d¡rt | ||¡S t| j||ƒ d S )Nr#   )r&   ÚobjectÚ__setattr__Úsetattrr   )r   r!   Úvaluer   r   r   r0   Z   s    
zDeprecationProxy.__setattr__c             C   s&   |  d¡rt | |¡S t| j|ƒ d S )Nr#   )r&   r/   Ú__delattr__Údelattrr   )r   r!   r   r   r   r3   `   s    
zDeprecationProxy.__delattr__N)	r   r   r   r   ÚDeprecationWarningr"   r.   r0   r3   r   r   r   r   r   >   s
   r   c               @   s0   e Zd Zefdd„Zdd„ Zdd„ Zdd„ Zd	S )
ÚDeprecatedModulec             C   s   || _ || _|| _d S )N)Ú"_DeprecatedModule__original_moduleÚ_DeprecatedModule__msgÚ_DeprecatedModule__cls)r   r   r-   r    r   r   r   r   h   s    zDeprecatedModule.__init__c             C   sJ   |  d¡rt| |ƒS |dkr"tjS tƒ r:t | j| jd¡ t	t| dƒ|ƒS )NÚ_DeprecatedModule__r$   r%   r7   )
r&   r'   r(   r)   r   r*   r+   r8   r9   r,   )r   r!   r   r   r   r.   m   s    


z!DeprecatedModule.__getattribute__c             C   s*   |  d¡rt | ||¡S t| j||ƒ d S )Nr:   )r&   r/   r0   r1   r7   )r   r!   r2   r   r   r   r0   z   s    
zDeprecatedModule.__setattr__c             C   s&   |  d¡rt | |¡S t| j|ƒ d S )Nr:   )r&   r/   r3   r4   r7   )r   r!   r   r   r   r3      s    
zDeprecatedModule.__delattr__N)r   r   r   r5   r   r.   r0   r3   r   r   r   r   r6   f   s   r6   c               @   s    e Zd Zefdd„Zdd„ ZdS )ÚDeprecatedGetPropertyc             C   s   || _ || _|| _d S )N)r   Úpropr    )r   r<   r   r    r   r   r   r   †   s    zDeprecatedGetProperty.__init__c             C   s&   t ƒ rt | j| jd¡ | j ||¡S )Nr%   )r   r*   r+   r   r    r<   Ú__get__)r   ÚinstÚklassr   r   r   r=   ‹   s    zDeprecatedGetProperty.__get__N)r   r   r   r5   r   r=   r   r   r   r   r;   „   s   r;   c               @   s   e Zd Zdd„ ZdS )ÚDeprecatedGetSetPropertyc             C   s*   t ƒ rt | j| jd¡ | j ||¡ d S )Nr%   )r   r*   r+   r   r    r<   Ú__set__)r   r>   r<   r   r   r   rA   ’   s    z DeprecatedGetSetProperty.__set__N)r   r   r   rA   r   r   r   r   r@      s   r@   c               @   s   e Zd Zdd„ ZdS )ÚDeprecatedGetSetDeletePropertyc             C   s(   t ƒ rt | j| jd¡ | j |¡ d S )Nr%   )r   r*   r+   r   r    r<   Ú
__delete__)r   r>   r   r   r   rC   ™   s    z)DeprecatedGetSetDeleteProperty.__delete__N)r   r   r   rC   r   r   r   r   rB   —   s   rB   c                s   ‡ ‡‡fdd„}|S )Nc                 s   t ƒ rt ˆˆ d¡ ˆ| |ŽS )Nr%   )r   r*   r+   )ÚargsÚkw)r    r   Úmethodr   r   Údeprecated_method    s    z+DeprecatedMethod.<locals>.deprecated_methodr   )rF   r   r    rG   r   )r    r   rF   r   ÚDeprecatedMethodž   s    rH   c             C   sð   t | tƒrXt d¡j}|d }t tj| tƒsBttj| ƒtj|< tj|  | ||¡ n”t | tj	ƒrpt
| ||ƒS t | tjƒrˆt| ||ƒS | }t|dƒr¶t|dƒr¶t|dƒr¶t|||ƒS t|dƒrÖt|dƒrÖt|||ƒS t|dƒrìt|||ƒS dS )zDeprecate the given names.é   r   r=   rA   rC   N)r   Ústr_and_sequence_typesÚsysÚ	_getframeÚ	f_globalsÚmodulesr   r"   r(   ÚFunctionTyperH   r)   r6   ÚhasattrrB   r@   r;   )Ú	specifierr   r    ÚglobalsÚmodnamer<   r   r   r   Ú
deprecated§   s$    


rT   c               @   s$   e Zd ZdZefdd„Zdd„ ZdS )r"   zDeprecation decoratorc             C   s   || _ || _d S )N)r-   r    )r   r-   r    r   r   r   r   É   s    zdeprecate.__init__c             C   s   t || j| jƒS )N)rH   r-   r    )r   Úfuncr   r   r   r   Í   s    zdeprecate.__call__N)r   r   r   r   r5   r   r   r   r   r   r   r"   Æ   s   r"   c       	      C   s’   t  d¡jd }d|| f }|r0|d||f 7 }t ||d¡ t| ƒ t j|  j}t j| }||_x*| 	¡ D ]\}}||jkrlt
|||ƒ qlW d S )NrI   r   z%s has moved to %s.z+ Import of %s will become unsupported in %sé   )rK   rL   rM   r*   r+   Ú
__import__rN   Ú__dict__r   Úitemsr1   )	Zto_locationZunsupported_inr    Úoldr   ZfromdictZtomodr!   Úvr   r   r   ÚmovedÐ   s    

r\   )r   Z__docformat__rK   r(   r*   ÚstrÚbytesÚ
basestringr   r   rJ   r/   r   r   r   r.   r'   r   r6   r;   r@   rB   r5   rH   rT   r"   r\   r   r   r   r   Ú<module>   s$   (	
