a
    PfF                     @  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
rdddlmZ eejfdd	d
dddZejfdd	ddddZddddddZddd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)	Generatorzstr | tuple[str, str]intz,Generator[str | tuple[str, str], None, None])
new_localelc_varreturnc              
   c  sn   t |}zPt ||  t  \}}|durF|durF| d| V  n| V  W t || nt || 0 dS )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	   Zcurrent_localeZnormalized_codeZnormalized_encoding r   T/var/www/ai-form-bot/venv/lib/python3.9/site-packages/pandas/_config/localization.py
set_locale   s    
r   strbool)lcr	   r
   c              	   C  sT   z0t | |d W d   n1 s$0    Y  W n ttjfyJ   Y dS 0 dS dS )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   zlist[str] | strz	list[str])locales	normalizer
   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!   Tz
str | None)prefixr   r
   c              
   C  s   t  dv rtddg}ng S z\|d}g }|D ]D}z|t|tjj	d W q4 t
yv   |t|dd Y q40 q4W n ty   Y n0 | du rt||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   Zraw_localesZsplit_raw_localesZout_localesxpatternfoundr   r   r   get_localeso   s$    

r8   )NT)__doc__
__future__r   
contextlibr   r   r(   r1   r*   typingr   Zpandas._config.configr   collections.abcr   LC_ALLr   r   r!   r8   r   r   r   r   <module>   s$   #  