Mini Shell

Direktori : /lib64/python3.6/site-packages/pyanaconda/__pycache__/
Upload File :
Current File : //lib64/python3.6/site-packages/pyanaconda/__pycache__/localization.cpython-36.opt-1.pyc

3

C��e�f�@s�ddlZddlZddlZddlZddlZddlZddlZddlm	Z	ddl
mZmZddl
mZmZmZddlmZddlmZee�Zddd	hZGd
d�de�ZGdd
�d
e�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Z dd�Z!dEdd�Z"dd �Z#d!d"�Z$d#d$�Z%dFd%d&�Z&d'd(�Z'd)d*�Z(d+d,�Z)d-d.�Z*d/d0�Z+d1d2�Z,d3d4�Z-dGd5d6�Z.e	d7d8d9g�Z/dHd;d<�Z0d=d>�Z1dId?d@�Z2dAdB�Z3dCdD�Z4dS)J�N)�
namedtuple)�	constants�util)�upcase_first_letter�setenv�execWithRedirect)�BOSS)�get_module_loggerZLatnZCyrlZGrekc@seZdZdZdS)�LocalizationConfigErrorz?Exception class for localization configuration related problemsN)�__name__�
__module__�__qualname__�__doc__�rr�$/usr/lib64/python3.6/localization.pyr
'sr
c@seZdZdZdS)�InvalidLocaleSpecz>Exception class for the errors related to invalid locale specsN)rrr
rrrrrr-srcCstj|�}t|j�S)zCheck if the given locale has a language specified.

    :return: whether the language or locale is valid
    :rtype: bool
    )�	langtable�parse_locale�bool�language)�langcodeZparsedrrr�is_valid_langcode3s
rcCst|�stdj|���dS)zOHelper to abort when a locale is not valid.

    :raise: InvalidLocaleSpec
    z'{}' is not a valid localeN)rr�format)�argrrr�raise_on_invalid_locale=srcCstj|�jS)z6Return language id without territory or anything else.)rrr)�localerrr�get_language_idFsrcCst|�}t|�S)a~Function that tells if the given locale is supported by the Anaconda or
    not. We consider locales supported by the langtable as supported by the
    Anaconda.

    :param locale: locale to test
    :type locale: str
    :return: whether the given locale is supported or not
    :rtype: bool
    :raise InvalidLocaleSpec: if an invalid locale is given (see is_valid_langcode)
    )�get_english_namer)rZen_namerrr�is_supported_localeKsrcCst|�}t|�jt�S)a�Function that tells if the given locale can be displayed by the Linux console.

    The Linux console can display Latin, Cyrillic and Greek characters reliably,
    but others such as Japanese, can't be correctly installed.

    :param str locale: locale to test
    :return: whether the given locale is supported by the console or not
    :rtype: bool
    :raise InvalidLocaleSpec: if an invalid locale is given (see is_valid_langcode)
    )�get_locale_scripts�set�issubset�SCRIPTS_SUPPORTED_BY_CONSOLE)rZlocale_scriptsrrr�locale_supported_in_consoleZsr#cCsXt|�st|�rdStj|�}tj|�}x&t||�D]\}}|r8||kr8dSq8WdS)a�Function that tells if the given langcode matches the given locale. I.e. if
    all parts of appearing in the langcode (language, territory, script and
    encoding) are the same as the matching parts of the locale.

    :param langcode: a langcode (e.g. en, en_US, en_US@latin, etc.)
    :type langcode: str
    :param locale: a valid locale (e.g. en_US.UTF-8 or sr_RS.UTF-8@latin, etc.)
    :type locale: str
    :return: whether the given langcode matches the given locale or not
    :rtype: bool
    FT)rrr�zip)rr�langcode_parsed�
locale_parsedZlang_valZloc_valrrr�langcode_matches_localeis

r'c	Cs�dd�}t|�sdSg}x�|D]�}t|�s:|j|df�qtj|�}tj|�}||j|jd�||j|jd�||j|jd�||j|jd�||j|jd�}|j||f�qWt	|d	d
�dd�}|r�|dddkr�|ddSdSdS)
aBFind the best match for the locale in a list of langcodes. This is useful
    when e.g. pt_BR is a locale and there are possibilities to choose an item
    (e.g. rnote) for a list containing both pt and pt_BR or even also pt_PT.

    :param locale: a valid locale (e.g. en_US.UTF-8 or sr_RS.UTF-8@latin, etc.)
    :type locale: str
    :param langcodes: a list or generator of langcodes (e.g. en, en_US, en_US@latin, etc.)
    :type langcodes: list(str) or generator(str)
    :return: the best matching langcode from the list of None if none matches
    :rtype: str or None
    cSs0|r|r||kr|S|Sn|r,|r,|SdS)Nrr)Zlocale_valueZlangcode_valueZweightrrr�score_value_pair�s
z0find_best_locale_match.<locals>.score_value_pairNri��d�
�cSs|dS)Nr+r)Z
item_scorerrr�<lambda>�sz(find_best_locale_match.<locals>.<lambda>T)�key�reverse)
r�appendrrr�	territoryZscriptZvariant�encoding�sorted)	rZ	langcodesr(Zscoresrr&r%ZscoreZsorted_langcodesrrr�find_best_locale_match�s 



>r3FcCsN|r|j|�|r�t|�}tjd|t|��t|�}tjd||�d}|rj|rjx|D]}t|�rTd}PqTW|s�tjd|�|s�tjd|�|s�tjd|�|r�|r�tjd|�tjd	�tj	}|t
jd
<tjd|�td
|�yt
jt
j|�WnPt
jk
�r@}z0tjd|�tj	}td
|�t
jt
j|�WYd
d
}~XnXt|�|S)a�Procedure setting the system to use the given locale and store it in to the
    localization module (if given). DOES NOT PERFORM ANY CHECKS OF THE GIVEN
    LOCALE.

    $LANG must be set by the caller in order to set the language used by gettext.
    Doing this in a thread-safe way is up to the caller.

    We also try to set a proper console font for the locale in text mode.
    If the font for the locale can't be displayed in the Linux console,
    we fall back to the English locale.

    This function returns the locale that was used in the setlocale call, which,
    depending on what the environment and interface is able to support, may be
    different from the locale requested.

    :param str locale: locale to setup
    :param localization_proxy: DBus proxy of the localization module or None
    :param bool text_mode: if the locale is being setup for text mode
    :return: the locale that was actually set
    :rtype: str
    zscripts found for locale %s: %sz%console fonts found for locale %s: %sFTz$can't set console font for locale %sz-script not supported by console for locale %sz#no console font found for locale %sz4none of the suggested fonts can be set for locale %sz"falling back to the English locale�LANGzsetting locale to: %szsetlocale failed: %sN)ZSetLanguager#�log�debugr�get_locale_console_fonts�set_console_fontZwarningr�DEFAULT_LANG�os�environr�
locale_mod�	setlocale�LC_ALL�Error�set_modules_locale)rZlocalization_proxy�	text_modeZscript_supportedZ
console_fontsZfont_set�font�errr�setup_locale�sF






 rDcCstj�}|j|�dS)zSet locale of all modules.N)rZ	get_proxyZ	SetLocale)rZ
boss_proxyrrrr@sr@cCst|�tj|dd�}t|�S)a-Function returning english name for the given locale.

    :param locale: locale to return english name for
    :type locale: str
    :return: english name for the locale or empty string if unknown
    :rtype: st
    :raise InvalidLocaleSpec: if an invalid locale is given (see is_valid_langcode)
    �en)�
languageId�languageIdQuery)rr�
language_namer)r�namerrrrs	rcCst|�tj|d�}t|�S)a+Function returning native name for the given locale.

    :param locale: locale to return native name for
    :type locale: str
    :return: english name for the locale or empty string if unknown
    :rtype: st
    :raise InvalidLocaleSpec: if an invalid locale is given (see is_valid_langcode)
    )rF)rrrHr)rrIrrr�get_native_name&s	rJccsz|ptj}ttj|d�dg�}dd�|D�}t�}x>|D]6}t|�}|r<||kr<|j|�t|�}|slq<|Vq<WdS)z�Method that generates (i.e. returns a generator) available translations
    for the installer in the given localedir.

    :type localedir: str
    :return: generator yielding available translations (languages)
    :rtype: generator yielding strings
    z/*/LC_MESSAGES/anaconda.mozblob/en/blob/blobcss |]}|jtjj�dVqdS)�N���)�splitr:�path�sep)�.0rNrrr�	<genexpr>Bsz-get_available_translations.<locals>.<genexpr>N)�gettextZ_default_localedirr2�globr r�add�get_language_locales)Z	localedirZmessagefilesZ	trans_genZlangsZtrans�lang�localesrrr�get_available_translations5s



rXcCst|�tj|d�S)a*Function returning all locales available for the given language.

    :param lang: language to get available locales for
    :type lang: str
    :return: a list of available locales
    :rtype: list of strings
    :raise InvalidLocaleSpec: if an invalid locale is given (see is_valid_langcode)
    )rF)rr�list_locales)rVrrrrURs	rUcCstj|d�S)a;Function returning list of locales for the given territory. The list is
    sorted from the most probable locale to the least probable one (based on
    langtable's ranking.

    :param territory: territory to return locales for
    :type territory: str
    :return: list of locales
    :rtype: list of strings
    )ZterritoryId)rrY)r0rrr�get_territory_locales`s
rZcCst|�tj|d�S)a Function returning preferred keyboard layouts for the given locale.

    :param locale: locale string
    :type locale: str
    :return: list of preferred keyboard layouts
    :rtype: list of strings
    :raise InvalidLocaleSpec: if an invalid locale is given (see is_valid_langcode)
    )rF)rrZlist_keyboards)rrrr�get_locale_keyboardsms	r[cCst|�tj|d�S)aFunction returning preferred timezones for the given locale.

    :param locale: locale string
    :type locale: str
    :return: list of preferred timezones
    :rtype: list of strings
    :raise InvalidLocaleSpec: if an invalid locale is given (see is_valid_langcode)
    )rF)rrZlist_timezones)rrrr�get_locale_timezones{s	r\cCst|�tj|d�S)aFunction returning preferred console fonts for the given locale.

    :param str locale: locale string
    :return: list of preferred console fonts
    :rtype: list of strings
    :raise InvalidLocaleSpec: if an invalid locale is given (see is_valid_langcode)
    )rF)rrZlist_consolefonts)rrrrr7�sr7cCst|�tj|d�S)a Function returning preferred scripts (writing systems) for the given locale.

    :param locale: locale string
    :type locale: str
    :return: list of preferred scripts
    :rtype: list of strings
    :raise InvalidLocaleSpec: if an invalid locale is given (see is_valid_langcode)
    )rF)rrZlist_scripts)rrrrr�s	rcCs*tjjdtj�}t|�tj||d�}|S)a�Function returning translated name of a region, city or complete timezone
    name according to the current value of the $LANG variable.

    :param tz_spec_part: a region, city or complete timezone name
    :type tz_spec_part: str
    :return: translated name of the given region, city or timezone
    :rtype: str
    :raise InvalidLocaleSpec: if an invalid locale is given (see is_valid_langcode)
    r4)rG)r:r;�getrr9rrZ
timezone_name)Ztz_spec_partrZxlatedrrr�get_xlated_timezone�s
r^cCsy&d}t|d��}|j�}WdQRXWntk
r:dSXt|�dkrVtjd�dS|dd�}|ddkr|tjd	�dS|dd�d
|dd�}|jd
�r�d}n|jd�r�d}|d7}t|�s�tjd|�dSt|�}|s�tjd|�dStjd||d�|dS)z�Procedure that returns the firmware language information (if any).

    :param boot text_mode: if the locale is being setup for text mode
    :return: the firmware language translated into a locale string, or None
    :rtype: str
    zK/sys/firmware/efi/efivars/PlatformLang-8be4df61-93ca-11d2-aa0d-00e098032b8c�rNr*zPlatformLang was too short���-zPlatformLang was malformed�_rKr+Zzh_chsZzh_HansZzh_chtZzh_Hantz.UTF-8z,PlatformLang was '%s', which is unsupported.z+No locales found for the PlatformLang '%s'.z4Using UEFI PlatformLang '%s' ('%s') as our language.r���)	�open�read�IOError�lenr5r6�
startswithrrU)rA�n�f�drWrrr�get_firmware_language�s8



rmZ
DateFieldSpecr�suffixTcsvd}���fdd�}tjtj�}|s.d|krD|r8|}ntd|��y||�Stk
rp|sd�n||�SYnXdS)a.Puts the year, month and day objects in the right order according to the
    currently set locale and provides format specification for each of the
    fields.

    :param year: any object or value representing year
    :type year: any
    :param month: any object or value representing month
    :type month: any
    :param day: any object or value representing day
    :type day: any
    :param bool fail_safe: whether to fall back to default in case of invalid
                           format or raise exception instead
    :returns: a pair where the first field contains a tuple with the year, month
              and day objects/values put in the right order and where the second
              field contains a tuple with three :class:`_DateFieldSpec` objects
              specifying formats respectively to the first (year, month, day)
              field, e.g. ((year, month, day), (y_fmt, m_fmt, d_fmt))
    :rtype: tuple
    :raise ValueError: in case currently set locale has unsupported date
                       format and fail_safe is set to False
    z%Y-%m-%dc
s�tjd�}|jdd�}|jd�dd�}g}g}x�|D]x}|j|�}|sJq6|j�\}}}	|dkrl|j��n&|dkr�|j��n|dkr�|j��|jtd|||	j���q6Wt	|�d
ks�t	|�d
kr�t
d|��t|�t|�fS)Nz([-_0OE^#]*)([yYmbBde])(.*)z%Fz%Y-%m-%d�%r+rlrC�Y�y�m�b�BrKz9Not all fields successfully identified in the format '%s')rlrC)rprq)rrrsrt)�re�compile�replacerM�match�groupsr/�_DateFieldSpec�striprh�
ValueError�tuple)
�fmt_strZ
field_spec_reZfieldsZ
ordered_termsZordered_formatsZfieldrx�prefix�itemrn)�day�month�yearrr�order_terms_formatss(



 z0resolve_date_format.<locals>.order_terms_formatsroz3Invalid date format string for current locale: '%s'N)r<�nl_langinfo�D_FMTr|)r�r�r�Z	fail_safeZFAIL_SAFE_DEFAULTr�r~r)r�r�r�r�resolve_date_format�s&r�cCsDtjd|�td|g�}|dkr0tjd|�dStjd|�dSdS)	z�Try to set console font to the given value.

    :param str font: console font name
    :returns: True on success, False on failure
    :rtype: bool
    zsetting console font to %sZsetfontrz#console font set successfully to %sTz!setting console font to %s failedFN)r5r6r�error)rB�rcrrrr8=sr8cCs�|s
|r8x,dD]$}|tjkrtj|rtj|}PqW|sDt|�}|r�yt|�}|d}Wn(ttfk
r�tjd|�d}YnX|s�tj	}|tjd<xd	D]}|tjkr�tj|=q�WdS)
aUClean and configure the local environment variables.

    This function will attempt to determine the desired locale and configure
    the process environment (os.environ) in the least surprising way. If a
    locale argument is provided, it will be attempted first. After that, this
    function will attempt to use the language environment variables in a manner
    similar to gettext(3) (in order, $LANGUAGE, $LC_ALL, $LC_MESSAGES, $LANG),
    followed by the UEFI PlatformLang, followed by a default.

    When this function returns, $LANG will be set, and $LANGUAGE, $LC_ALL,
    and $LC_MESSAGES will not be set, because they get in the way when changing
    the language after startup.

    This function must be run before any threads are started. This function
    modifies the process environment, which is not thread-safe.

    :param str locale: locale to setup if provided
    :param bool text_mode: if the locale is being setup for text mode
    :param bool prefer_environment: whether the process environment, if available, overrides the locale parameter
    :return: None
    :rtype: None
    �LANGUAGEr>�LC_MESSAGESr4rzCInvalid locale '%s' given on command line, kickstart or environmentN)r�r>r�r4)r�r>r�)
r:r;rmrUr�
IndexErrorr5r�rr9)rrAZprefer_environmentZvarnameZ	env_langsrrr�setup_locale_environmentNs(






r�c
Csddgi}|jd�s"tjd�dS|td�d�}tjtjj|d��tj	ddd	||d
dd|g�}|d
krztj
d�dSxltjddtjj|d�dg�D]L}t|�}d|kr�|j
dd�\}}n|}||kr�|g||<q�||j|�q�Wtjtjj|d��|S)z�Get a map of languages and locales from the given OSTree.

    For example: {"en": ["en_US"]}

    :param repo: the OSTree repository url
    :param ref: the name of branch inside the repository
    :return: a map of languages and locales
    rEZen_USzfile://z-ostree repo is not local; defaulting to en_USNztmp/usr/libz/usr/bin/ostreeZcheckoutz--repoz	--subpathz/usr/lib/locale/locale-archivez%s/tmp/usr/lib/localerz5failed to check out locale-archive; check program.logz/usr/bin/localedefz--prefixZtmpz--list-archivercr+ztmp/usr)rir5�inforhrZ
mkdirChainr:rN�joinrr�Z
execReadlines�strip_codeset_and_modifierrMr/�shutilZrmtree)Zrepo�refZ
locale_mapr��linerVZ
_territoryrrr�get_locale_map_from_ostree�s2




r�cCs8d|kr|d|jd��}d|kr4|d|jd��}|S)zzReturn a striped version of the given locale.

    :param locale: a name of the locale
    :return: a stripped locale
    �@N�.)�find)rrrrr��s
r�)NF)N)F)T)NFF)5rRr:rur�rrr<rS�collectionsrZpyanaconda.corerrZpyanaconda.core.utilrrrZ,pyanaconda.modules.common.constants.servicesrZpyanaconda.anaconda_loggersr	rr5r"�	Exceptionr
rrrrrr#r'r3rDr@rrJrXrUrZr[r\r7rr^rmrzr�r8r�r�r�rrrr�<module>sR

	7
S



2
R
@2