U
    
W[!
                     @   st   d Z ddlmZmZ ddlZddlmZ ddlmZm	Z	 dd Z
dd	 Zd
d Ze
e	ee
e  edd ZdS )zD
Utilities to assist in the "flag day" new-style object transition.
    )absolute_importdivisionN)wraps)_shouldEnableNewStyle_PY3c                    s    fdd}|S )a2  
    If C{condition}, replace this function with C{alternative}.

    @param condition: A L{bool} which says whether this should be replaced.

    @param alternative: An alternative function that will be swapped in instead
        of the original, if C{condition} is truthy.

    @return: A decorator.
    c                    sF   dkr n dkr|  nt dtt|  fdd}|S )NTFz8condition argument to _replaceIf requires a bool, not {}c                     s
    | |S )N )argskwargscallr   :/usr/lib/python3/dist-packages/twisted/python/_oldstyle.pywrapped'   s    z._replaceIf.<locals>.decorator.<locals>.wrapped)
ValueErrorformatreprr   )funcr   alternative	conditionr
   r   	decorator   s    z_replaceIf.<locals>.decoratorr   )r   r   r   r   r   r   
_replaceIf   s    r   c                 C   s   | S )z]
    Return C{arg}. Do nothing.

    @param arg: The arg to return.

    @return: C{arg}
    r   )argr   r   r   passthru1   s    r   c                 C   s2   t | tjk	r.ddlm} tdj|| d| S )z
    Ensure that C{cls} is an old-style class.

    @param cls: The class to check.

    @return: The class, if it is an old-style class.
    @raises: L{ValueError} if it is a new-style class.
    r   )fullyQualifiedNameztwisted.python._oldstyle._oldStyle is being used to decorate a new-style class ({cls}). This should only be used to decorate old-style classes.)cls)typetypesZ	ClassTypeZtwisted.python.reflectr   r   r   )r   r   r   r   r   _ensureOldClass=   s    	r   c                 C   s$   t |  | jtf }t| j|| jS )a  
    A decorator which conditionally converts old-style classes to new-style
    classes. If it is Python 3, or if the C{TWISTED_NEWSTYLE} environment
    variable has a falsey (C{no}, C{false}, C{False}, or C{0}) value in the
    environment, this decorator is a no-op.

    @param cls: An old-style class to convert to new-style.
    @type cls: L{types.ClassType}

    @return: A new-style version of C{cls}.
    )r   	__bases__objectr   __name____dict__)r   Z_basesr   r   r   	_oldStyleS   s    r"   )__doc__Z
__future__r   r   r   	functoolsr   Ztwisted.python.compatr   r   r   r   r   r"   r   r   r   r   <module>   s   