B @`g@sdZddlmZddlZddlZddlZddlmZeejfe dddZ ejfe e e dd d Z d d Zd dZddefddZdS)zx Helpers for configuring locale settings. Name `localization` is chosen to avoid overlap with builtin `locale` module. )contextmanagerN)options)lc_varc csZt}z>t||t}tdd|Dr>d|Vn|VWdt||XdS)aE Context manager for temporarily setting a locale. Parameters ---------- new_locale : str or tuple A string of the form .. 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).0xrr?/tmp/pip-unpacked-wheel-q9tj5l6a/pandas/_config/localization.py 'szset_locale...N)locale getlocale setlocalealljoin)Z new_localerZcurrent_localeZnormalized_localerrr set_locales  r)lcrreturnc Cs@yt||dWdQRXWnttjfk 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)rrrrrcan_set_locale/s rcsddfdd|DDS)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. cSsg|]}t|r|qSr)r)rlocrrr \sz"_valid_locales..c3s(|] }rt|n|VqdS)N)r normalizestrip)rr)rrrr ^sz!_valid_locales..r)Zlocalesrr)rr_valid_localesJs rcCstjdgddS)Nz locale -aT)shell) subprocess check_outputrrrr_default_locale_getteresrTc Csy |}Wntjk r dSXyb|d}g}xN|D]F}y|t|tjjdWq8tk r||t|ddYq8Xq8WWnt k rYnX|dkrt ||St |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.* )rCalledProcessErrorsplitappendstrrZdisplayr UnicodeError TypeErrorrrecompilefindallr)prefixrZ locale_getterZ raw_localesZ out_localesrpatternfoundrrr get_localesis&     r.)__doc__ contextlibrr r(rZpandas._config.configrLC_ALLintrr%boolrrrr.rrrrs