
    G8c1                         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      Zd Zdd	d
Zd Zd Zd ZddZd Zd ZddZy)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                   .    e Zd ZdZddZd Zed        Zy)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                 Z    || _         ||t        d      || _        || _        || _        y )Nz#classproperty only implements fget.)_fget
ValueErrorfsetfdel_doc)selffgetr   r   docs        :/usr/lib/python3/dist-packages/matplotlib/_api/__init__.py__init__zclassproperty.__init__,   s5    
t/BCC			    c                 $    | j                  |      S Nr   )r   instanceowners      r   __get__zclassproperty.__get__5   s    zz%  r   c                     | j                   S r   r   )r   s    r   r   zclassproperty.fget8   s    zzr   )NNN)__name__
__module____qualname____doc__r   r    propertyr    r   r   r   r      s%     !  r   r   c                    | }t        d      t        |t               r|fn|fnt        fd|D              }fd}|j                         D ]  \  }}t        ||      rg t	        ||      }d|v r"|j                  d       |j                  d       t        dj                  |t        |      dkD  rdj                  |dd       d	z   |d   z   n|d
    |t        |                         y)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   *   K   | ]
  }|n|  y wr   r'   ).0tp	none_types     r   	<genexpr>z#check_isinstance.<locals>.<genexpr>P   s     Cr
92Cs   c                 |    | u rdS | j                   dk(  r| j                  S | j                    d| j                   S )NNonebuiltins.)r#   r$   )r+   r,   s    r   	type_namez#check_isinstance.<locals>.type_nameR   sD    	/ 	;(*(CR__	;a'89	;r   r/   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typesr2   kvnamesr,   s          @r   check_isinstancerF   A   s     ET
I#E40eX"]i\CUCC 
;
  )1!U#,c)U+,EV$V$:AA5zA~ IIeCRj)F2U2Y>+08d1g&	() ))r   T)_print_supported_valuesc          	          |st        d      | }|j                         D ]B  \  }}||vs|d| }|r%|ddj                  t        t        |             z  }t        |       y)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 r3   N)r<   r8   r?   r9   reprr   )_valuesrG   rA   valueskeyvalmsgs          r   check_in_listrO   e   sz    , /00FLLN "SfG5cU;C&03tV;L1M0NOOS/!"r   c                    | }|j                         D ]  \  }}|j                  }t        |      t        |      k7  st        d t	        ||      D              sFt        t        j                  dd t        j                         D                    dj                  fd|D              }t        |dt        |       d| d|j                   d	       y
)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              3   .   K   | ]  \  }}||d fv  y wr   r'   )r*   tss      r   r-   zcheck_shape.<locals>.<genexpr>   s%      7
Aq !T"7
   MNLIJKLHc              3   &   K   | ]	  }d |   yw)DNr'   )r*   is     r   r-   zcheck_shape.<locals>.<genexpr>   s     4Q1QC4s   r3   c              3   N   K   | ]  }|t        |      n
t                y wr   )strnext)r*   n
dim_labelss     r   r-   zcheck_shape.<locals>.<genexpr>   s3      $; )* ()} %(F)-j)9%: $;s   "%z	 must be zD with shape (z). Your input has shape r1   N)r8   shaper>   anyzipiter	itertoolschaincountr?   r   )_shaperA   target_shaperC   rD   
data_shape
text_shaper]   s          @r   check_shaperi      s      L 1WW
|J/3 7
j97
 4
 ioo4)//"346 7J  $; .:$; <J
 %y\!2 3 4)l +(()y3 r   c                     | }t        |      dk7  rt        d      |j                         \  \  }}	 ||   S # t        $ r; t        dj	                  ||dj                  t        t        |                        dw xY w)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 {}r3   N)r>   r   r8   KeyErrorr=   r?   r9   rI   )_mappingrA   mappingrC   rD   s        r   check_getitemrn      s     G
6{aHIIllnGFQDqz DGVAq$))Cg$678:?C	DDs
   7 AA;c                       j                   dk(  sJ t               j                         D ci c]  \  }}t        |t              r|| c}}         t        j                  d       fd       }|S c c}}w )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__Nc                 j    | v r|    j                        S t        dj                  d|       )Nzmodule z has no attribute )r    AttributeErrorr#   )nameclsr   propss    r   rp   z+caching_module_getattr.<locals>.__getattr__   sD    5=;&&x00cnn''9$BD 	Dr   )r"   varsr8   r6   r&   	functools	lru_cache)rt   rs   proprp   r   ru   s   `   @@r   caching_module_getattrrz      s~    & <<=(((*.s)//*; ,JD$4* 4Z ,EuHD D ,s   A:c                    t        j                  t        |       S fd}| j                         D ]  \  }}d}dD ]Z  }||z   t	              v sd}|D ]@  } |||z         }||z   |_        dj                  ||z         |_        t        ||z   |       B \ |rjt        dj                  |             d }	t        di       }
 |	|
       |	|       z  }|rt        d	|       i |
| _        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).
    c                 X     t        j                  t                      fd       }|S )Nc                 (     t        |       |i |S r   )getattr)r   argsrA   rs   s      r   methodz2define_aliases.<locals>.make_alias.<locals>.method   s    &74&777r   )rw   wrapsr~   )rs   r   rt   s   ` r   
make_aliasz"define_aliases.<locals>.make_alias   s*    	d+	,	8 
-	8r   F)get_set_TzAlias for `{}`.z)Neither getter nor setter exists for {!r}c                 8    h | d | j                         D        S )Nc              3   .   K   | ]  }|D ]  }|   y wr   r'   )r*   aliasesaliass      r   r-   zBdefine_aliases.<locals>.get_aliased_and_aliases.<locals>.<genexpr>  s     K7K%eKeKrT   )rK   )ds    r   get_aliased_and_aliasesz/define_aliases.<locals>.get_aliased_and_aliases  s    LLK188:KLLr   
_alias_mapz2Parent class already defines conflicting aliases: )rw   partialdefine_aliasesr8   rv   r"   r=   r%   setattrr   r~   NotImplementedErrorr   )alias_drt   r   ry   r   existsprefixr   r   r   preexisting_aliasesconflictings    `          r   r   r      s:   $ {  99 ! Jg& 	9F}S	)$ 9E'6F&,unFO%6%=%=ftm%LFNC%8	9	9 ;BB4HJ JJM "#|R8*+>?,W56K!@NP 	P7+7w7CNJr   c                     t        |       D ]  \  }}	  ||i |c S  y# t        $ r |t        |       dz
  k(  r Y 0w xY w)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)	enumerater<   r>   )funcsr   rA   rX   funcs        r   select_matching_signaturer     s[    X U# 4	(((  	CJN" #	s   ==c              #   h   K   |  | j                         D ]  }t        |      E d{     y7 w)z8Yield *cls* and direct and indirect subclasses of *cls*.N)__subclasses__recursive_subclasses)rt   subclss     r   r   r   Q  s4     
I$$& 0'///0/s   &202c                    t        j                         }t        j                  d      D ]D  }| n@t	        j
                  d|j                  j                  dd            s n|j                  }F t        j                  | |       y)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	_getframerb   rd   rematch	f_globalsgetf_backwarningswarn)messagecategoryframe
stacklevels       r   warn_externalr   X  sr     MMOEooa( 
=xxH++J;=  MM'8Z0r   r   )r%   rw   rb   r   r   r   deprecationr   r   r   r   r   r	   r
   r   r   r   rF   rO   ri   rn   rz   r   r   r   r   r'   r   r   <module>r      sn   
   	 
 " " " L!)H 7; "B$ND, F4n1h01r   