U
    ÎZj  ã                   @  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m	Z	m
Z
 d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„Zddef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)ÚCallableÚIterator)Úoptionszstr | tuple[str, str]ÚintzIterator[str | tuple[str, str]])Ú
new_localeÚlc_varÚreturnc              
   c  sb   t  |¡}zDt  || ¡ t  ¡ \}}|dk	rF|dk	rF|› d|› �V  n| V  W 5 t  ||¡ X 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   ú^/var/www/html/TRUCKING_PROJECT/venv/lib/python3.8/site-packages/pandas/_config/localization.pyÚ
set_locale   s    

r   ÚstrÚbool)Úlcr	   r
   c              	   C  sB   zt | |d�� W 5 Q R X W n ttjfk
r8   Y dS X 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	   FTN)r   Ú
ValueErrorr   ÚError)r   r	   r   r   r   Úcan_set_locale8   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>d   s   ûz"_valid_locales.<locals>.<listcomp>c                 3  s(   | ] }ˆ rt  | ¡ ¡n| ¡ V  qd S )N)r   r   Ústripr   ©r   r   r   Ú	<genexpr>f   s   ÿz!_valid_locales.<locals>.<genexpr>r   )r   r   r   r   r   Ú_valid_localesS   s
    
þþr!   Úbytes)r
   c                   C  s   t jdgdd�S )Nz	locale -aT)Úshell)Ú
subprocessÚcheck_outputr   r   r   r   Ú_default_locale_gettern   s    r&   Tz
str | NonezCallable[[], bytes]zlist[str] | None)Úprefixr   Úlocale_getterr
   c           	   
   C  sÔ   z
|ƒ }W n t jk
r"   Y dS X z^| d¡}g }|D ]F}z| t|tjjd�¡ W q8 tk
r|   | t|dd�¡ Y q8X q8W n t	k
r–   Y nX | dkrªt
||ƒ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.
    locale_getter : callable
        The function to use to retrieve the current locales. This should return
        a string with each locale separated by a newline character.

    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 None (no locale available, e.g. Windows)

    Nó   
)Úencodingzwindows-1252z.*Ú
)r$   ÚCalledProcessErrorÚsplitÚappendr   r   Údisplayr*   ÚUnicodeErrorÚ	TypeErrorr!   ÚreÚcompileÚfindallÚjoin)	r'   r   r(   Zraw_localesZsplit_raw_localesZout_localesÚxÚpatternÚfoundr   r   r   Úget_localesr   s&    !


r9   )Ú__doc__Ú
__future__r   Ú
contextlibr   r   r2   r$   Útypingr   r   Zpandas._config.configr   ÚLC_ALLr   r   r!   r&   r9   r   r   r   r   Ú<module>   s"   ÿ#ý