B
    ò¶I`„	  ã               @   s<   d dl Z d dlmZ G dd„ dƒZdd„ Zeƒ Zdd„ ZdS )	é    N)Úcbookc               @   sB   e Zd ZdZdd„ Zdd„ Zdd„ Zeej	dd	d
�dd„ ƒƒZ
dS )ÚSubstitutionaG  
    A decorator that performs %-substitution on an object's docstring.

    This decorator should be robust even if ``obj.__doc__`` is None (for
    example, if -OO was passed to the interpreter).

    Usage: construct a docstring.Substitution with a sequence or dictionary
    suitable for performing substitution; then decorate a suitable function
    with the constructed object, e.g.::

        sub_author_name = Substitution(author='Jason')

        @sub_author_name
        def some_function(x):
            "%(author)s wrote this function"

        # note that some_function.__doc__ is now "Jason wrote this function"

    One can also use positional arguments::

        sub_first_last_names = Substitution('Edgar Allen', 'Poe')

        @sub_first_last_names
        def some_function(x):
            "%s %s wrote the Raven"
    c             O   s   |r|rt dƒ‚|p|| _d S )Nz+Only positional or keyword args are allowed)Ú	TypeErrorÚparams)ÚselfÚargsÚkwargs© r	   ú8/tmp/pip-unpacked-wheel-tvo012g9/matplotlib/docstring.pyÚ__init__!   s    zSubstitution.__init__c             C   s   |j r| j | j;  _ |S )N)Ú__doc__r   )r   Úfuncr	   r	   r
   Ú__call__&   s    zSubstitution.__call__c             O   s   | j j||Ž dS )zW
        Update ``self.params`` (which must be a dict) with the supplied args.
        N)r   Úupdate)r   r   r   r	   r	   r
   r   +   s    zSubstitution.updatez3.3zassign to the params attribute)Úalternativec             C   s   | ƒ }||_ |S )a(  
        In the case where the params is a mutable sequence (list or
        dictionary) and it may change before this class is called, one may
        explicitly use a reference to the params rather than using *args or
        **kwargs which will copy the values and not reference them.
        )r   )Úclsr   Úresultr	   r	   r
   Úfrom_params1   s    	zSubstitution.from_paramsN)Ú__name__Ú
__module__Ú__qualname__r   r   r   r   Úclassmethodr   Ú
deprecatedr   r	   r	   r	   r
   r      s   r   c                s   ‡ fdd„}|S )z;Copy a docstring from another source function (if present).c                s   ˆ j rˆ j | _ | S )N)r   )Útarget)Úsourcer	   r
   Údo_copyA   s    zcopy.<locals>.do_copyr	   )r   r   r	   )r   r
   Úcopy?   s    r   c             C   s   t  | ¡| _t| ƒS )z@Dedent *func*'s docstring, then interpolate it with ``interpd``.)ÚinspectÚgetdocr   Úinterpd)r   r	   r	   r
   Údedent_interpdM   s    r    )r   Z
matplotlibr   r   r   r   r    r	   r	   r	   r
   Ú<module>   s
   9