3
ƽh	                 @   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	   :/tmp/pip-build-7iwl8md4/matplotlib/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   Z
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 j| | _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