ó ¾[/\c@s7ddlmZddlmZddlmZddlZddlZddlZddlZddl Z ddl Z de fd„ƒYZ d„Z d„Zd „Zd „Zd „Zd „Zd „Zdd„Zd„Zdeddd„Zdddd„Zd„Zd„Zedƒ\ZZeZdS(iÿÿÿÿ(tprint_function(tunicode_literals(tunicodeNt UnicodeStreamcBs#eZd„Zd„Zd„ZRS(cCs||_||_dS(N(tstreamtencoding(tselfRR((s,/usr/lib/python2.7/site-packages/dnf/i18n.pyt__init__$s cCsÜt|tƒsHtjjr0|j|jdƒn|j|jdƒ}ny|jj |ƒWnyt k r×|j|jjdƒ}t |jdƒr¬|jj j |ƒqØ|j|jjdƒ}|jj |ƒnXdS(Nureplaceubackslashreplaceubufferuignore( t isinstancetstrtdnftpycomptPY3tdecodeRtencodeRtwritetUnicodeEncodeErrorthasattrtbuffer(Rtsts_bytes((s,/usr/lib/python2.7/site-packages/dnf/i18n.pyR(s! cCst|j|ƒS(N(tgetattrR(Rtname((s,/usr/lib/python2.7/site-packages/dnf/i18n.pyt __getattr__7s(t__name__t __module__RRR(((s,/usr/lib/python2.7/site-packages/dnf/i18n.pyR#s  cCsB|dkrtS|jƒ}|jdƒs:|jdƒr>tStS(u‘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. uutf-uutf_N(tNonetFalsetlowert startswithtTrue(RR((s,/usr/lib/python2.7/site-packages/dnf/i18n.pyt_full_ucd_support:s  cCs&tjtƒ}|jdƒr"dS|S(u= Take the best shot at the current system's string encoding. uANSIuutf-8(tlocaletgetpreferredencodingRR(R((s,/usr/lib/python2.7/site-packages/dnf/i18n.pyt_guess_encodingKscCsmytjjtjdƒWnLtjk rh}tddtjƒdt j d "%s" % (chop_str(msg, 10)) iuN(Rt exact_widthRA(tmsgtchoptwidtht chopped_msgtchart char_width((s,/usr/lib/python2.7/site-packages/dnf/i18n.pytchop_str—s    cCstd„|DƒƒS(uQ Calculates width of char at terminal screen (Asian char counts for two) css|]}t|ƒVqdS(N(RA(t.0tc((s,/usr/lib/python2.7/site-packages/dnf/i18n.pys ®s(tsum(RC((s,/usr/lib/python2.7/site-packages/dnf/i18n.pyRB«sucCsœt||ƒ\}}||krK|s-|r˜dj|||gƒ}q˜nMd||}|r}dj||||gƒ}ndj||||gƒ}|S(uµ 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))``. uu (RItjoin(RCtfillRDtlefttprefixtsuffixREtextra((s,/usr/lib/python2.7/site-packages/dnf/i18n.pytfill_exact_width±s  iFc s–‡fd†‰|jdƒ}|jdd ƒjdƒ}g}|}t}d}d} x|D]} | jdƒ} || } } ˆ| ƒ\}} t} |r­| r­t} n|rÎ|t| ƒkrÎt} n|rÿ| rÿ|dkrÿ|| krÿt} qÿn| r*|j|jdƒƒ|}t}n|t| ƒkrEd} n|rc| jdƒ} | } nt|| ƒ|krœt}|j|| ƒ|}q^nt}| jdƒ}|} | }| rÙ|dkrÙ|}nxw|D]o}|t| |ƒkr;t| ƒt|ƒkr;|j| jdƒƒ|d|} n| |7} | d7} qàW| jdƒd}q^W|r‰|j|jdƒƒndj |ƒS( uq Works like we want textwrap.wrap() to work, uses Unicode strings and doesn't screw up lists/blocks/etc. csÃd}d}x(|D] }|dkr)Pn|d7}qW|d krM|dfSt||dƒd}|dkr¹ˆ||t|ƒƒ}|dp›|d}|r¹||d|fSn|dfS(NiuXu iu-u*u.uouâu•u‣u∘(u-u*u.uouâ(u-u*u.uou•u‣u∘(RItlen(tlinetcounttbytetlist_chrtnxt(t_indent_at_beg(s,/usr/lib/python2.7/site-packages/dnf/i18n.pyRZ×s      u u u iiiuu ( trstriptreplacetsplitRRRTtappendtlstripRBRM(ttextREtinitial_indenttsubsequent_indenttlinestrettindentt wrap_lasttcsabt cspc_indentRUtlsabt lspc_indenttforce_nltwordstspcstword((RZs,/usr/lib/python2.7/site-packages/dnf/i18n.pyt textwrap_fillÓsf             cCsDtƒd„}tjjj|dtƒ}t|tjj|ƒƒS(u< Easy gettext translations setup based on given domain name cs ‡fd†S(Ncstˆ|ŒƒS(N(R=(tw(tfnc(s,/usr/lib/python2.7/site-packages/dnf/i18n.pyt(s((Rq((Rqs,/usr/lib/python2.7/site-packages/dnf/i18n.pyt ucd_wrapper'stfallback(R-R R tgettextt translationRtmapt gettext_setup(RRstt((s,/usr/lib/python2.7/site-packages/dnf/i18n.pyRv"s cCs2t|tdƒ|ƒ}d|kr*|S|SdS(Niu(t_tchr(tcontexttmessagetresult((s,/usr/lib/python2.7/site-packages/dnf/i18n.pytpgettext-s udnf(t __future__RRt dnf.pycompRR R R*R0R(R>tobjectRRR"R-R4R8R=RARRIRBRRSRoRvRRztP_tC_(((s,/usr/lib/python2.7/site-packages/dnf/i18n.pyts0             "O