usr/lib/python3.6/site-packages/dnf/__pycache__/i18n.cpython-36.pyc000064400000022612147205376060020614 0ustar003 ft`!0@sddlmZddlmZddlmZddlZddlZddlZddlZddl Z ddl Z Gddde Z ddZ d d Zd d Zd dZddZddZddZd'ddZddZd(ddZd)ddZd d!Zd"d#Zd$d%Zed&\ZZeZdS)*)print_function)unicode_literals)unicodeNc@s$eZdZddZddZddZdS) UnicodeStreamcCs||_||_dS)N)streamencoding)selfrrr /usr/lib/python3.6/i18n.py__init__$szUnicodeStream.__init__c Cst|ts.tjjr |j|jdn |j|jd}y|jj |Wn\t k r|j|jjd}t |jdrz|jj j |n|j|jjd}|jj |YnXdS)Nreplacebackslashreplacebufferignore) isinstancestrdnfpycompPY3decoderencoderwriteUnicodeEncodeErrorhasattrr)rsZs_bytesr r r r(s  zUnicodeStream.writecCs t|j|S)N)getattrr)rnamer r r __getattr__7szUnicodeStream.__getattr__N)__name__ __module__ __qualname__r rrr r r r r#srcCs0|dkr dS|j}|jds(|jdr,dSdS)aReturn 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}|jdrdS|S)z= Take the best shot at the current system's string encoding. FZANSIzutf-8)localegetpreferredencodingr")rr r r _guess_encodingKs r&cCsytjjtjdWntjk rytjjtjddtjd<Wn0tjk rttjjtjddtjd<YnXtdj tjdt j dYnXdS)NzC.UTF-8LC_ALLCz&Failed to set locale, defaulting to {})file) rr setlocaler$r(Errorosenvironprintformatsysstderrr r r r setup_localePsr3c Cs`tj}|jstjtjtjy |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) r1stdoutisattysignalSIGPIPESIG_DFLrAttributeErrorr#rr&)r4rr r r setup_stdout^s  r:cCst|ddtjjS)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_inputrs r<c Cstjjr:tjj|r$t|tddSt|tr2|St|St|tjjrL|St|drxy tjj|St k rvYnXtjjt|tddSdS)zD Like the builtin unicode() but tries to use a reasonable encoding. r)errorsZ __unicode__N) rrrZ is_py3bytesrr&rrr UnicodeError)objr r r ucd}s    r@cCstj|dkrdSdS)NWF)rArB) unicodedataZeast_asian_width)Zucharr r r _exact_width_charsrFcCsX|dkrt||fSd}d}x2|D]*}t|}|||kr "%s" % (chop_str(msg, 10)) Nrr') exact_widthrF)msgchopwidthZ chopped_msgcharZ char_widthr r r chop_strs    rLcCstdd|DS)zQ Calculates width of char at terminal screen (Asian char counts for two) css|]}t|VqdS)N)rF).0cr r r szexact_width..)sum)rHr r r rGsrGTr'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' )rLjoin)rHZfillrIleftprefixsuffixrJZextrar r r fill_exact_widths rVFcsfdd|jd}|jdd jd}g}|}d}d}d} xr|D]h} | jd} || } } | \}} d} |rz| rzd } |r|t| krd } |r| r|d kr|| krd } | r|j|jd|}d}|t| krd } |r| jd} | } t|| |krd}|j|| |}qDd }| jd}|} | }| r@|d kr@|}x^|D]V}|t| |krt| t|kr|j| jd|d|} | |7} | d7} qFW| jdd}qDW|r|j|jddj|S) zq Works like we want textwrap.wrap() to work, uses Unicode strings and doesn't screw up lists/blocks/etc. csd}d}x|D]}|dkrP|d7}qW|d kr8|dfSt||ddd}|dkr||t|d}|dp||d}|r||d|fS|dfS)NrXrQrD-*.oâ•‣∘)rYrZr[r\r])rYrZr[r\r^r_r`)rLlen)linecountZbyteZlist_chrZnxt)_indent_at_begr r rds   z%textwrap_fill.._indent_at_beg  rQFrTr'z )rstripr splitraappendlstriprGrR)textrJZinitial_indentZsubsequent_indentlinesretindentZ wrap_lastZcsabZ cspc_indentrbZlsabZ lspc_indentZforce_nlZwordsZspcsZwordr )rdr textwrap_fillsf           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_longZ width_shortZ width_longr r r select_short_long'srrcCs2tdd}tjjj|dd}t|tjj|S)z< Easy gettext translations setup based on given domain name cs fddS)Ncs t|S)N)r@)w)fncr r Tsz2translation..ucd_wrapper..r )rtr )rtr ucd_wrapperSsz translation..ucd_wrapperT)Zfallback)r3rrgettext translationmapZ gettext_setup)rrvtr r r rxNsrxcCs(t|td|}d|kr |S|SdS)Nrh)_chr)contextmessageresultr r r pgettextYsrr)N)NTr'r')rWr'r')Z __future__rrZ dnf.pycomprrr$r-r6r1rEobjectrr#r&r3r:r<r@rFrLrGrVrqrrrxrr|ZP_ZC_r r r r s2      " O'