U
    ÂmœdË4  ã                   @   sÌ   d Z ddlZddlZddlZddlZddlZddlmZmZm	Z	m
Z
mZmZmZmZmZ G dd„ dƒZdd„ Zd	d
œdd„Zdd„ Zdd„ Zdd„ Zddd„Zdd„ Zdd„ Zdd„ Zdd„ Zd dd„ZdS )!a+  
Helper functions for managing the Matplotlib API.

This documentation is only relevant for Matplotlib developers, not for users.

.. warning::

    This module and its submodules are for internal use only.  Do not use them
    in your own code.  We may change the API at any time with no warning.

é    Né   )	Ú
deprecatedÚwarn_deprecatedÚrename_parameterÚdelete_parameterÚmake_keyword_onlyÚdeprecate_method_overrideÚdeprecate_privatize_attributeÚ'suppress_matplotlib_deprecation_warningÚMatplotlibDeprecationWarningc                   @   s.   e Zd ZdZd	dd„Zdd„ Zedd„ ƒZdS )
Úclasspropertya$  
    Like `property`, but also triggers on access via the class, and it is the
    *class* that's passed as argument.

    Examples
    --------
    ::

        class C:
            @classproperty
            def foo(cls):
                return cls.__name__

        assert C.foo == "C"
    Nc                 C   s4   || _ |d k	s|d k	rtdƒ‚|| _|| _|| _d S )Nz#classproperty only implements fget.)Ú_fgetÚ
ValueErrorÚfsetÚfdelÚ_doc)ÚselfÚfgetr   r   Údoc© r   úQ/home/sam/Atlas/atlas_env/lib/python3.8/site-packages/matplotlib/_api/__init__.pyÚ__init__,   s    zclassproperty.__init__c                 C   s
   |   |¡S ©N©r   )r   ÚinstanceÚownerr   r   r   Ú__get__5   s    zclassproperty.__get__c                 C   s   | j S r   r   )r   r   r   r   r   8   s    zclassproperty.fget)NNN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   Úpropertyr   r   r   r   r   r      s
   
	r   c              
      sÜ   | }t dƒ‰ t|t ƒr|fn"|dkr*ˆ fnt‡ fdd„|D ƒƒ}‡ fdd„}| ¡ D ]‚\}}t||ƒsTt||ƒ•}d|krŽ| d¡ | d¡ td |t	|ƒdkrÀd	 
|dd
… ¡d |d
  n|d |t |ƒƒ¡ƒ‚qTdS )a5  
    For each *key, value* pair in *kwargs*, check that *value* is an instance
    of one of *_types*; if not, raise an appropriate TypeError.

    As a special case, a ``None`` entry in *_types* is treated as NoneType.

    Examples
    --------
    >>> _api.check_isinstance((SomeClass, None), arg=arg)
    Nc                 3   s   | ]}|d krˆ n|V  qd S r   r   )Ú.0Útp©Z	none_typer   r   Ú	<genexpr>P   s     z#check_isinstance.<locals>.<genexpr>c                    s.   | ˆ krdS | j dkr| jS | j › d| j› �S )NÚNoneÚbuiltinsÚ.)r   r   )r#   r$   r   r   Ú	type_nameR   s    þz#check_isinstance.<locals>.type_namer&   z({!r} must be an instance of {}, not a {}r   ú, éÿÿÿÿz or r   )ÚtypeÚ
isinstanceÚtupleÚitemsÚmapÚremoveÚappendÚ	TypeErrorÚformatÚlenÚjoin)Ú_typesÚkwargsÚtypesr)   ÚkÚvÚnamesr   r$   r   Úcheck_isinstanceA   s,    þ



ÿ 
üÿr=   T)Ú_print_supported_valuesc                K   sb   |st dƒ‚| }| ¡ D ]D\}}||kr|›d|› �}|rT|dd tt|ƒ¡› �7 }t|ƒ‚qdS )aC  
    For each *key, value* pair in *kwargs*, check that *value* is in *_values*.

    Parameters
    ----------
    _values : iterable
        Sequence of values to check on.
    _print_supported_values : bool, default: True
        Whether to print *_values* when raising ValueError.
    **kwargs : dict
        *key, value* pairs as keyword arguments to find in *_values*.

    Raises
    ------
    ValueError
        If any *value* in *kwargs* is not found in *_values*.

    Examples
    --------
    >>> _api.check_in_list(["foo", "bar"], arg=arg, other_arg=other_arg)
    zNo argument to check!z is not a valid value for z; supported values are r*   N)r3   r/   r6   r0   Úreprr   )Z_valuesr>   r8   ÚvaluesÚkeyÚvalÚmsgr   r   r   Úcheck_in_liste   s    rD   c              
      s¸   | }|  ¡ D ]¦\}}|j}t|ƒt|ƒksBtdd„ t||ƒD ƒƒrtt ddd„ t ¡ D ƒ¡ƒ‰ d 	‡ fdd„|D ƒ¡}t|ƒdkrŒ|d7 }t
|›d	t|ƒ› d
|› d|j› d�ƒ‚qdS )a§  
    For each *key, value* pair in *kwargs*, check that *value* has the shape
    *_shape*, if not, raise an appropriate ValueError.

    *None* in the shape is treated as a "free" size that can have any length.
    e.g. (None, 2) -> (N, 2)

    The values checked must be numpy arrays.

    Examples
    --------
    To check for (N, 2) shaped arrays

    >>> _api.check_shape((None, 2), arg=arg, other_arg=other_arg)
    c                 s   s   | ]\}}||d fkV  qd S r   r   )r"   ÚtÚsr   r   r   r%   š   s   ÿzcheck_shape.<locals>.<genexpr>ZMNLIJKLHc                 s   s   | ]}d |› �V  qdS )ÚDNr   )r"   Úir   r   r   r%       s     r*   c                 3   s&   | ]}|d k	rt |ƒntˆ ƒV  qd S r   )ÚstrÚnext)r"   Ún©Z
dim_labelsr   r   r%   ¡   s   þÿ
r   ú,z	 must be zD with shape (z). Your input has shape r(   N)r/   Úshaper5   ÚanyÚzipÚiterÚ	itertoolsÚchainÚcountr6   r   )Ú_shaper8   Ztarget_shaper:   r;   Z
data_shapeZ
text_shaper   rL   r   Úcheck_shape†   s$    þþý ÿrV   c                 K   sj   | }t |ƒdkrtdƒ‚| ¡ \\}}z
|| W S  tk
rd   td ||d tt|ƒ¡¡ƒd‚Y nX dS )zô
    *kwargs* must consist of a single *key, value* pair.  If *key* is in
    *_mapping*, return ``_mapping[value]``; else, raise an appropriate
    ValueError.

    Examples
    --------
    >>> _api.check_getitem({"foo": "bar"}, arg=arg)
    r   z-check_getitem takes a single keyword argumentz9{!r} is not a valid value for {}; supported values are {}r*   N)r5   r   r/   ÚKeyErrorr4   r6   r0   r?   )Ú_mappingr8   Úmappingr:   r;   r   r   r   Úcheck_getitem¯   s     

  ÿÿþrZ   c                    sH   ˆ j dkst‚dd„ tˆ ƒ ¡ D ƒ‰ˆ ƒ ‰t d¡‡ ‡‡fdd„ƒ}|S )a
  
    Helper decorator for implementing module-level ``__getattr__`` as a class.

    This decorator must be used at the module toplevel as follows::

        @caching_module_getattr
        class __getattr__:  # The class *must* be named ``__getattr__``.
            @property  # Only properties are taken into account.
            def name(self): ...

    The ``__getattr__`` class will be replaced by a ``__getattr__``
    function such that trying to access ``name`` on the module will
    resolve the corresponding property (which may be decorated e.g. with
    ``_api.deprecated`` for deprecating module globals).  The properties are
    all implicitly cached.  Moreover, a suitable AttributeError is generated
    and raised if no property with the given name exists.
    Ú__getattr__c                 S   s    i | ]\}}t |tƒr||“qS r   )r-   r!   )r"   ÚnameÚpropr   r   r   Ú
<dictcomp>Ú   s    
ÿ z*caching_module_getattr.<locals>.<dictcomp>Nc                    s0   | ˆkrˆ|    ˆ¡S tdˆ j›d| ›�ƒ‚d S )Nzmodule z has no attribute )r   ÚAttributeErrorr   ©r\   ©Úclsr   Úpropsr   r   r[   Þ   s
    ÿz+caching_module_getattr.<locals>.__getattr__)r   ÚAssertionErrorÚvarsr/   Ú	functoolsÚ	lru_cache)rb   r[   r   ra   r   Úcaching_module_getattrÅ   s    rh   c                    sê   ˆ dkrt  t| ¡S ‡ fdd„}|  ¡ D ]|\}}d}dD ]X}|| tˆ ƒkr8d}|D ]:}||| ƒ}|| |_d || ¡|_tˆ || |ƒ qTq8|s(t	d |¡ƒ‚q(d	d
„ }	t
ˆ di ƒ}
|	|
ƒ|	| ƒ@ }|rÜtd|› �ƒ‚|
| –ˆ _ˆ S )aT  
    Class decorator for defining property aliases.

    Use as ::

        @_api.define_aliases({"property": ["alias", ...], ...})
        class C: ...

    For each property, if the corresponding ``get_property`` is defined in the
    class so far, an alias named ``get_alias`` will be defined; the same will
    be done for setters.  If neither the getter nor the setter exists, an
    exception will be raised.

    The alias map is stored as the ``_alias_map`` attribute on the class and
    can be used by `.normalize_kwargs` (which assumes that higher priority
    aliases come last).
    Nc                    s    t  tˆˆ ƒ¡‡ fdd„ƒ}|S )Nc                    s   t | ˆ ƒ||ŽS r   )Úgetattr)r   Úargsr8   r`   r   r   Úmethodþ   s    z2define_aliases.<locals>.make_alias.<locals>.method)rf   Úwrapsri   )r\   rk   ©rb   r`   r   Ú
make_aliasý   s    z"define_aliases.<locals>.make_aliasF)Úget_Úset_TzAlias for `{}`.z)Neither getter nor setter exists for {!r}c                 S   s   | dd„ |   ¡ D ƒ™S )Nc                 s   s   | ]}|D ]
}|V  q
qd S r   r   )r"   ÚaliasesÚaliasr   r   r   r%     s       zBdefine_aliases.<locals>.get_aliased_and_aliases.<locals>.<genexpr>)r@   )Údr   r   r   Úget_aliased_and_aliases  s    z/define_aliases.<locals>.get_aliased_and_aliasesÚ
_alias_mapz2Parent class already defines conflicting aliases: )rf   ÚpartialÚdefine_aliasesr/   re   r   r4   r    Úsetattrr   ri   ÚNotImplementedErrorru   )Zalias_drb   rn   r]   rq   ÚexistsÚprefixrr   rk   rt   Zpreexisting_aliasesÚconflictingr   rm   r   rw   è   s8    
ÿÿÿ
rw   c              	   O   sN   t | ƒD ]@\}}z|||ŽW   S  tk
rF   |t| ƒd krB‚ Y qX qdS )a  
    Select and call the function that accepts ``*args, **kwargs``.

    *funcs* is a list of functions which should not raise any exception (other
    than `TypeError` if the arguments passed do not match their signature).

    `select_matching_signature` tries to call each of the functions in *funcs*
    with ``*args, **kwargs`` (in the order in which they are given).  Calls
    that fail with a `TypeError` are silently skipped.  As soon as a call
    succeeds, `select_matching_signature` returns its return value.  If no
    function accepts ``*args, **kwargs``, then the `TypeError` raised by the
    last failing call is re-raised.

    Callers should normally make sure that any ``*args, **kwargs`` can only
    bind a single *func* (to avoid any ambiguity), although this is not checked
    by `select_matching_signature`.

    Notes
    -----
    `select_matching_signature` is intended to help implementing
    signature-overloaded functions.  In general, such functions should be
    avoided, except for back-compatibility concerns.  A typical use pattern is
    ::

        def my_func(*args, **kwargs):
            params = select_matching_signature(
                [lambda old1, old2: locals(), lambda new: locals()],
                *args, **kwargs)
            if "old1" in params:
                warn_deprecated(...)
                old1, old2 = params.values()  # note that locals() is ordered.
            else:
                new, = params.values()
            # do things with params

    which allows *my_func* to be called either with two parameters (*old1* and
    *old2*) or a single one (*new*).  Note that the new signature is given
    last, so that callers get a `TypeError` corresponding to the new signature
    if the arguments they passed in do not match any signature.
    r   N)Ú	enumerater3   r5   )Úfuncsrj   r8   rH   Úfuncr   r   r   Úselect_matching_signature  s    ,r€   c                 C   s   t | › d|› d|› d�ƒS )zEGenerate a TypeError to be raised by function calls with wrong arity.z	() takes z positional arguments but z were given)r3   )r\   ZtakesÚgivenr   r   r   Únargs_errorS  s    r‚   c                 C   s*   t |tƒstt|ƒƒ}t| › d|› d�ƒS )aL  
    Generate a TypeError to be raised by function calls with wrong kwarg.

    Parameters
    ----------
    name : str
        The name of the calling function.
    kw : str or Iterable[str]
        Either the invalid keyword argument name, or an iterable yielding
        invalid keyword arguments (e.g., a ``kwargs`` dict).
    z'() got an unexpected keyword argument 'ú')r-   rI   rJ   rQ   r3   )r\   Úkwr   r   r   Úkwarg_errorY  s    
r…   c                 c   s&   | V  |   ¡ D ]}t|ƒE dH  qdS )z8Yield *cls* and direct and indirect subclasses of *cls*.N)Ú__subclasses__Úrecursive_subclasses)rb   Úsubclsr   r   r   r‡   j  s    r‡   c                 C   sV   t  ¡ }t d¡D ]0}|dkr" qDt d|j dd¡¡s< qD|j}qt	 
| ||¡ dS )a4  
    `warnings.warn` wrapper that sets *stacklevel* to "outside Matplotlib".

    The original emitter of the warning can be obtained by patching this
    function back to `warnings.warn`, i.e. ``_api.warn_external =
    warnings.warn`` (or ``functools.partial(warnings.warn, stacklevel=2)``,
    etc.).
    r   Nz-\A(matplotlib|mpl_toolkits)(\Z|\.(?!tests\.))r   Ú )ÚsysÚ	_getframerR   rT   ÚreÚmatchÚ	f_globalsÚgetÚf_backÚwarningsÚwarn)ÚmessageÚcategoryÚframeÚ
stacklevelr   r   r   Úwarn_externalq  s    	þr—   )N)N)r    rf   rR   rŒ   rŠ   r‘   Údeprecationr   r   r   r   r   r   r	   r
   r   r   r=   rD   rV   rZ   rh   rw   r€   r‚   r…   r‡   r—   r   r   r   r   Ú<module>   s$   ,&$!)#
74