o
    Û­jF  ã                   @  s¦   d Z ddlmZ ddlmZ ddlZddlZddlZddlZddl	m
Z
 ddlmZ e
r2ddlmZ eejfd dd„ƒZejfd!dd„Zd"dd„Z		d#d$dd„ZdS )%zx
Helpers for configuring locale settings.

Name `localization` is chosen to avoid overlap with builtin `locale` module.
é    )Úannotations)ÚcontextmanagerN)ÚTYPE_CHECKING)Úoptions)Ú	GeneratorÚ
new_localeústr | tuple[str, str]Úlc_varÚintÚreturnú,Generator[str | tuple[str, str], None, None]c              
   c  s€   � t  |¡}z2t  || ¡ t  ¡ \}}|dur$|dur$|› d|› �V  n| V  W t  ||¡ dS W t  ||¡ dS t  ||¡ w )aE  
    Context manager for temporarily setting a locale.

    Parameters
    ----------
    new_locale : str or tuple
        A string of the form <language_country>.<encoding>. For example to set
        the current locale to US English with a UTF8 encoding, you would pass
        "en_US.UTF-8".
    lc_var : int, default `locale.LC_ALL`
        The category of the locale being set.

    Notes
    -----
    This is useful when you want to run a particular block of code under a
    particular locale, without globally setting the locale. This probably isn't
    thread-safe.
    NÚ.)ÚlocaleÚ	setlocaleÚ	getlocale)r   r	   Úcurrent_localeÚnormalized_codeÚnormalized_encoding© r   úX/var/www/html/CropPilot/venv/lib/python3.10/site-packages/pandas/_config/localization.pyÚ
set_locale   s   €
ür   ÚlcÚstrÚboolc              	   C  sR   zt | |d��
 W d  ƒ W dS 1 sw   Y  W dS  ttjfy(   Y dS w )aj  
    Check to see if we can set a locale, and subsequently get the locale,
    without raising an Exception.

    Parameters
    ----------
    lc : str
        The locale to attempt to set.
    lc_var : int, default `locale.LC_ALL`
        The category of the locale being set.

    Returns
    -------
    bool
        Whether the passed locale can be set
    )r	   NFT)r   Ú
ValueErrorr   ÚError)r   r	   r   r   r   Úcan_set_locale9   s   ÿúüþr   Úlocalesúlist[str] | strÚ	normalizeú	list[str]c                   s   dd„ ‡ fdd„| D ƒD ƒS )ar  
    Return a list of normalized locales that do not throw an ``Exception``
    when set.

    Parameters
    ----------
    locales : str
        A string where each locale is separated by a newline.
    normalize : bool
        Whether to call ``locale.normalize`` on each locale.

    Returns
    -------
    valid_locales : list
        A list of valid locales.
    c                 S  s   g | ]}t |ƒr|‘qS r   )r   ©Ú.0Úlocr   r   r   Ú
<listcomp>e   s    úÿz"_valid_locales.<locals>.<listcomp>c                 3  s*   � | ]}ˆ rt  | ¡ ¡n| ¡ V  qd S )N)r   r   Ústripr!   ©r   r   r   Ú	<genexpr>g   s
   € ÿ
ÿz!_valid_locales.<locals>.<genexpr>r   )r   r   r   r&   r   Ú_valid_localesT   s
   
þþr(   TÚprefixú
str | Nonec              
   C  sÊ   t  ¡ dv rt ddg¡}ng S z-| d¡}g }|D ]!}z| t|tjj	d�¡ W q t
y;   | t|dd�¡ Y qw W n	 tyF   Y nw | du rPt||ƒS t | › d�¡}| d	 |¡¡}t||ƒS )
a)  
    Get all the locales that are available on the system.

    Parameters
    ----------
    prefix : str
        If not ``None`` then return only those locales with the prefix
        provided. For example to get all English language locales (those that
        start with ``"en"``), pass ``prefix="en"``.
    normalize : bool
        Call ``locale.normalize`` on the resulting list of available locales.
        If ``True``, only locales that can be set without throwing an
        ``Exception`` are returned.

    Returns
    -------
    locales : list of strings
        A list of locale strings that can be set with ``locale.setlocale()``.
        For example::

            locale.setlocale(locale.LC_ALL, locale_string)

    On error will return an empty list (no locale available, e.g. Windows)

    )ÚLinuxÚDarwinr   z-aó   
)Úencodingzwindows-1252Nz.*Ú
)ÚplatformÚsystemÚ
subprocessÚcheck_outputÚsplitÚappendr   r   Údisplayr.   ÚUnicodeErrorÚ	TypeErrorr(   ÚreÚcompileÚfindallÚjoin)r)   r   Úraw_localesÚsplit_raw_localesÚout_localesÚxÚpatternÚfoundr   r   r   Úget_localeso   s*   
úýÿ

rC   )r   r   r	   r
   r   r   )r   r   r	   r
   r   r   )r   r   r   r   r   r    )NT)r)   r*   r   r   r   r    )Ú__doc__Ú
__future__r   Ú
contextlibr   r   r0   r9   r2   Útypingr   Úpandas._config.configr   Úcollections.abcr   ÚLC_ALLr   r   r(   rC   r   r   r   r   Ú<module>   s&    ÿ#
þ