HOME


sh-3ll 1.0
DIR:/usr/local/lib64/python3.6/site-packages/pandas/_config/__pycache__/
Upload File :
Current File : //usr/local/lib64/python3.6/site-packages/pandas/_config/__pycache__/localization.cpython-36.pyc
3

���h��@s�dZddlmZddlZddlZddlZddlmZeejfe	d�dd��Z
ejfee	ed�d	d
�Z
dd�Zd
d�Zddefdd�ZdS)zx
Helpers for configuring locale settings.

Name `localization` is chosen to avoid overlap with builtin `locale` module.
�)�contextmanagerN)�options)�lc_varccsZtj�}z>tj||�tj�}tdd�|D��r>dj|�Vn|VWdtj||�XdS)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.
    css|]}|dk	VqdS)N�)�.0�xrr�=/tmp/pip-build-5_djhm0z/pandas/pandas/_config/localization.py�	<genexpr>'szset_locale.<locals>.<genexpr>�.N)�locale�	getlocale�	setlocale�all�join)Z
new_localerZcurrent_localeZnormalized_localerrr�
set_locales
r)�lcr�returncCs@yt||d��WdQRXWnttjfk
r6dSXdSdS)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
    )rNFT)r�
ValueErrorr�Error)rrrrr�can_set_locale/srcCs*|rdd�}ndd�}tttt||���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.
    cSstj|j��S)N)r�	normalize�strip)rrrr�<lambda>\sz _valid_locales.<locals>.<lambda>cSs|j�S)N)r)rrrrr^s)�list�filterr�map)ZlocalesrZ
normalizerrrr�_valid_localesJs
rcCstjdgdd�}|S)Nz	locale -aT)�shell)�
subprocess�check_output)�raw_localesrrr�_default_locale_gettercsr!TcCs�y
|�}Wntjk
r dSXyb|jd�}g}xN|D]F}y|jt|tjjd��Wq8tk
r||jt|dd��Yq8Xq8WWnt	k
r�YnX|dkr�t
||�Stj|�d��}|j
dj|��}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�append�strr�displayr#�UnicodeError�	TypeErrorr�re�compile�findallr)�prefixrZ
locale_getterr Zout_localesr�pattern�foundrrr�get_localeshs&


 
r2)�__doc__�
contextlibrrr,rZpandas._config.configr�LC_ALL�intrr(�boolrrr!r2rrrr�<module>s