Your IP : 18.191.174.190
3
�ft`!0�@s�ddlmZddlmZddlmZddlZddlZddlZddlZddl Z ddl
Z
Gdd�de�Zdd�Z
d d
�Zdd�Zd
d�Zdd�Zdd�Zdd�Zd'dd�Zdd�Zd(dd�Zd)dd�Zd d!�Zd"d#�Zd$d%�Zed&�\ZZeZdS)*�)�print_function)�unicode_literals)�unicodeNc@s$eZdZdd�Zdd�Zdd�ZdS)�
UnicodeStreamcCs||_||_dS)N)�stream�encoding)�selfrr�r �/usr/lib/python3.6/i18n.py�__init__$szUnicodeStream.__init__cCs�t|t�s.tjjr |j|jd�n|j|jd�}y|jj |�Wn\t
k
r�|j|jjd�}t|jd�rz|jjj |�n|j|jjd�}|jj |�YnXdS)N�replace�backslashreplace�buffer�ignore)
�
isinstance�str�dnf�pycomp�PY3�decoder�encoder�write�UnicodeEncodeError�hasattrr)r�sZs_bytesr r r
r(s
zUnicodeStream.writecCst|j|�S)N)�getattrr)r�namer r r
�__getattr__7szUnicodeStream.__getattr__N)�__name__�
__module__�__qualname__rrrr r r r
r#srcCs0|dkrdS|j�}|jd�s(|jd�r,dSdS)a�Return true if encoding can express any Unicode character.
Even if an encoding can express all accented letters in the given language,
we can't generally settle for it in DNF since sometimes we output special
characters like the registered trademark symbol (U+00AE) and surprisingly
many national non-unicode encodings, including e.g. ASCII and ISO-8859-2,
don't contain it.
NFzutf-Zutf_T)�lower�
startswith)rr!r r r
�_full_ucd_support:s
r#cCstjd�}|jd�rdS|S)z= Take the best shot at the current system's string encoding. FZANSIzutf-8)�locale�getpreferredencodingr")rr r r
�_guess_encodingKs
r&cCs�ytjjtjd�Wn�tjk
r�ytjjtjd�dtjd<Wn0tjk
rttjjtjd�dtjd<YnXtdj tjd�t
jd�YnXdS)N�zC.UTF-8�LC_ALL�Cz&Failed to set locale, defaulting to {})�file)rr� setlocaler$r(�Error�os�environ�print�format�sys�stderrr r r r
�setup_localePsr3cCs`tj}|j�stjtjtj�y
|j}Wntk
r@d}YnXt|�s\t |t
��t_dSdS)z� Check that stdout is of suitable encoding and handle the situation if
not.
Returns True if stdout was of suitable encoding already and no changes
were needed.
NFT)r1�stdout�isatty�signal�SIGPIPE�SIG_DFLr�AttributeErrorr#rr&)r4rr r r
�setup_stdout^s
r:cCst|dd�tjj�S)z� It uses print instead of passing the prompt to raw_input.
raw_input doesn't encode the passed string and the output
goes into stderr
r')�end)r/rrZ raw_input)Zucstringr r r
� ucd_inputrsr<c
Cs�tjjr:tjj|�r$t|t�dd�St|t�r2|St|�St|tjj�rL|St|d�rxytjj|�St k
rvYnXtjjt|�t�dd�SdS)zD Like the builtin unicode() but tries to use a reasonable encoding. r)�errorsZ__unicode__N)
rrrZis_py3bytesrr&rrr�UnicodeError)�objr r r
�ucd}s
r@cCstj|�dkrdSdS)N�W�F��)rArB)�unicodedataZeast_asian_width)Zucharr r r
�_exact_width_char�srFcCsX|dkrt|�|fSd}d}x2|D]*}t|�}|||kr<P||7}||7}q"W||fS)a' Return the textual width of a Unicode string, chopping it to
a specified value. This is what you want to use instead of %.*s, as it
does the "right" thing with regard to different Unicode character width
Eg. "%.*s" % (10, msg) <= becomes => "%s" % (chop_str(msg, 10)) Nrr')�exact_widthrF)�msg�chop�widthZchopped_msg�charZ
char_widthr r r
�chop_str�s
rLcCstdd�|D��S)zQ Calculates width of char at terminal screen
(Asian char counts for two) css|]}t|�VqdS)N)rF)�.0�cr r r
� <genexpr>�szexact_width.<locals>.<genexpr>)�sum)rHr r r
rG�srGTr'cCsjt||�\}}||kr0|s|rfdj|||g�}n6d||}|rTdj||||g�}ndj||||g�}|S)a� Expand a msg to a specified "width" or chop to same.
Expansion can be left or right. This is what you want to use instead of
%*.*s, as it does the "right" thing with regard to different Unicode
character width.
prefix and suffix should be used for "invisible" bytes, like
highlighting.
Examples:
``"%-*.*s" % (10, 20, msg)`` becomes
``"%s" % (fill_exact_width(msg, 10, 20))``.
``"%20.10s" % (msg)`` becomes
``"%s" % (fill_exact_width(msg, 20, 10, left=False))``.
``"%s%.10s%s" % (pre, msg, suf)`` becomes
``"%s" % (fill_exact_width(msg, 0, 10, prefix=pre, suffix=suf))``.
r'� )rL�join)rHZfillrI�left�prefix�suffixrJZextrar r r
�fill_exact_width�srV�Fcs��fdd��|jd�}|jdd�jd�}g}|}d}d}d} �xr|D�]h}
|
jd�}
|| }}�|
�\}} d}
|rz| rzd }
|r�|t|
�kr�d }
|r�|r�|d
kr�||kr�d }
|
r�|j|jd��|}d}|t|
�kr�d}
|r�|
jd�}
|} t||
�|k�rd}|j||
�|}qDd }|
jd�}|}
| }|�r@|d
k�r@|}x^|D]V}|t|
|�k�r�t|
�t|�k�r�|j|
jd��|d|}
|
|7}
|
d7}
�qFW|
jd�d}qDW|�r�|j|jd��dj|�S)
zq Works like we want textwrap.wrap() to work, uses Unicode strings
and doesn't screw up lists/blocks/etc. cs�d}d}x|D]}|dkrP|d7}qW|d
kr8|dfSt||d�d�d}|dkr��||t|�d��}|dp||d}|r�||d|fS|dfS)Nr�XrQrD�-�*�.�o�â�•�‣�∘)rYrZr[r\r])rYrZr[r\r^r_r`)rL�len)�line�countZbyteZlist_chrZnxt)�_indent_at_begr r
rd�s
z%textwrap_fill.<locals>._indent_at_beg�
� rQ�FrT�r'z )�rstripr�splitra�append�lstriprGrR)�textrJZinitial_indentZsubsequent_indent�lines�ret�indentZ wrap_lastZcsabZcspc_indentrbZlsabZlspc_indentZforce_nlZwordsZspcsZwordr )rdr
�
textwrap_fill�sf
rqcCsHt|�}t|�}||kr|S||kr4||kr0|S|S||kr@|S|SdS)a� Automatically selects the short (abbreviated) or long (full) message
depending on whether we have enough screen space to display the full
message or not. If a caller by mistake passes a long string as
msg_short and a short string as a msg_long this function recognizes
the mistake and swaps the arguments. This function is especially useful
in the i18n context when you cannot predict how long are the translated
messages.
Limitations:
1. If msg_short is longer than width you will still get an overflow.
This function does not abbreviate the string.
2. You are not obliged to provide an actually abbreviated string, it is
perfectly correct to pass the same string twice if you don't want
any abbreviation. However, if you provide two different strings but
having the same width this function is unable to recognize which one
is correct and you should assume that it is unpredictable which one
is returned.
Example:
``select_short_long (10, _("Repo"), _("Repository"))``
will return "Repository" in English but the results in other languages
may be different. N)rG)rJZ msg_shortZmsg_longZwidth_shortZ
width_longr r r
�select_short_long'srrcCs2t�dd�}tjjj|dd�}t|tjj|��S)z< Easy gettext translations setup based on given domain name cs�fdd�S)Ncst�|��S)N)r@)�w)�fncr r
�<lambda>Tsz2translation.<locals>.ucd_wrapper.<locals>.<lambda>r )rtr )rtr
�ucd_wrapperSsz translation.<locals>.ucd_wrapperT)Zfallback)r3rr�gettext�translation�mapZ
gettext_setup)rrv�tr r r
rxNsrxcCs(t|td�|�}d|kr |S|SdS)Nrh�)�_�chr)�context�message�resultr r r
�pgettextYsr�r)N)NTr'r')rWr'r')Z
__future__rrZ
dnf.pycomprrr$r-r6r1rE�objectrr#r&r3r:r<r@rFrLrGrVrqrrrxr�r|ZP_ZC_r r r r
�<module>s2
"
O'
?>