B
    ]”t\Ë  ã               @   sf   d dl Z d dlZd dlmZ G dd„ deƒZG dd„ deƒZdd„ Zd	d
„ Zeƒ Z	dd„ Z
dd„ ZdS )é    N)Úcbookc               @   s4   e Zd ZdZdd„ Zdd„ Zdd„ Zedd	„ ƒZd
S )ÚSubstitutiona/  
    A decorator to take a function's docstring and perform string
    substitution on it.

    This decorator should be robust even if func.__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&   t |ƒrt |ƒrtdƒ‚|p|| _d S )Nz+Only positional or keyword args are allowed)ÚlenÚAssertionErrorÚparams)ÚselfÚargsÚkwargs© r
   ú3lib/python3.7/site-packages/matplotlib/docstring.pyÚ__init__#   s    zSubstitution.__init__c             C   s   |j o|j | j |_ |S )N)Ú__doc__r   )r   Úfuncr
   r
   r   Ú__call__(   s    zSubstitution.__call__c             O   s   | j j||Ž dS )z=Assume self.params is a dict and update it with supplied argsN)r   Úupdate)r   r   r	   r
   r
   r   r   ,   s    zSubstitution.updatec             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_params0   s    zSubstitution.from_paramsN)	Ú__name__Ú
__module__Ú__qualname__r   r   r   r   Úclassmethodr   r
   r
   r
   r   r      s
   r   c               @   s"   e Zd ZdZddd„Zdd„ ZdS )	ÚAppenderaf  
    A function decorator that will append an addendum to the docstring
    of the target function.

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

    Usage: construct a docstring.Appender with a string to be joined to
    the original docstring. An optional 'join' parameter may be supplied
    which will be used to join the docstring and addendum. e.g.

    add_copyright = Appender("Copyright (c) 2009", join='
')

    @add_copyright
    def my_dog(has='fleas'):
        "This docstring will have a copyright below"
        pass
    Ú c             C   s   || _ || _d S )N)ÚaddendumÚjoin)r   r   r   r
   r
   r   r   P   s    zAppender.__init__c             C   s$   |j | jg}|j o| j |¡|_ |S )N)r   r   r   )r   r   Zdocitemsr
   r
   r   r   T   s    zAppender.__call__N)r   )r   r   r   r   r   r   r
   r
   r
   r   r   =   s   
r   c             C   s   | j ot | j ¡| _ | S )zDedent a docstring (if present))r   r   Údedent)r   r
   r
   r   r   Z   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_copyb   s    zcopy.<locals>.do_copyr
   )r   r   r
   )r   r   Úcopy`   s    r    c             C   s   t t| ƒƒS )zXA special case of the interpd that first performs a dedent on
    the incoming docstring)Úinterpdr   )r   r
   r
   r   Údedent_interpdm   s    r"   c                s   ‡ fdd„S )zOA decorator that will copy the docstring from the source and
    then dedent itc                s   t tˆ ƒ| ƒƒS )N)r   r    )r   )r   r
   r   Ú<lambda>z   s    zcopy_dedent.<locals>.<lambda>r
   )r   r
   )r   r   Úcopy_dedents   s    r$   )ÚsysÚtypesZ
matplotlibr   Úobjectr   r   r   r    r!   r"   r$   r
   r
   r
   r   Ú<module>   s   6
