ó ur™Vc@s§dZddlZddlmZdZdZdZd„Zd„Zd „Z e a d „Z d „Z d d d„Zd d„Zd d„Zd d„Zd„ZdS(s› methods for internationalized text processing, which counts "columns" in applicable cases, rather than assuming columns are same as characters or bytes. i’’’’N(teast_asian_widthtlefttrighttcentercCs5tjtjƒd}|dkr1tjƒ}n|S(s$ Get encoding of current locale iN(tlocalet getlocaletLC_CTYPEtNonetgetpreferredencoding(tenc((si18n.pyt get_encoding)s cCsTt|tƒr$|jtƒƒ}nt|ƒ}|dksH|dkrLdSdSdS(s; Count column width needed for given Unicode character tFtWiiN(t isinstancetstrtdecodeR R(tct width_class((si18n.pyt charwidth3s  cCs^t|tƒr$|jtƒƒ}n|jdƒ}d}x|D]}|t|ƒ7}q@W|S(sl Count column width needed for given string. text passed in should be a str or unicode object. ii(R RRR t expandtabsR(ttextt width_totaltchar((si18n.pyt textwidth@s cCstS(s± Get information on whether wrapping text should be done on white space or on arbitrary position. Default is True as in English. See also: set_wrap_on_whitespace() (t_WHITESPACE_WRAP(((si18n.pytif_wrap_on_whitespaceSscCs.t|tƒr$|jƒdk}n|adS(s`Sets the global flag which indicates whether text should be wrapped on whitespace. The default value is True, but varies by language. A gettext call such as the one below should be used to determine whether or not the current language wraps on whitespace: _("DONT_TRANSLATE_BUT_REPLACE_msgstr_WITH_True_OR_False: " "Should wrap text on whitespace in this language") The result of that call can be directly passed into this function; if "do_wrap" is the literal string "False" (case-insensitive), then wrapping will be done. Non-strings will be interpreted as booleans. tFalseN(R t basestringt capitalizeR(tdo_wrap((si18n.pytset_wrap_on_whitespace\s tu c Csˆt|tƒr$|jtƒƒ}n|jdƒ}|d krHd}nt|tƒrl|jtƒƒ}nt|ƒdkr‘td|ƒ‚nd}d}xB|D]:}t|ƒ}|||krŹPn||7}||7}q¤W||}|r„|dkr„|tkr|||}q„|t kr8|||}q„|t krq|d} || } || ||| }q„td|ƒ‚n|S( s« Fit a text in max_width columns, by truncating the text if needed. If just is one of LEFT, RIGHT, or CENTER, justify text and fill unused room with fillchar. iu is3Cannot use multi-column character "%c" as fillchar.uiisUnknown just=%sN( R RRR RRRt ValueErrortLEFTtRIGHTtCENTER( Rt max_widthtjusttfillchart fitted_textRRtwidthtnpadtnlefttnright((si18n.pytfit_text_truncateps<            cCst||dtd|ƒS(sE alternative to ljust(); counts multicolumn characters correctly R%R&(R,R!(RR$R&((si18n.pyt ljust_columnsscCst||dtd|ƒS(sE alternative to rjust(); counts multicolumn characters correctly R%R&(R,R"(RR$R&((si18n.pyt rjust_columns£scCst||dtd|ƒS(sF alternative to center(); counts multicolumn characters correctly R%R&(R,R#(RR$R&((si18n.pytcenter_columns©scCs‹tƒ}t|tƒr-|jtƒƒ}n|jdƒjƒ}g}x<|D]4}d}d}d}d} xüt|ƒD]ī\} } t | ƒ} || |kr*|rū|dk rū|d} |j || | !j ƒƒ|d} ||8}d}d}q*| } |j || | !j ƒƒ| } d}n|| 7}| dkrz| | krY|| 8}qh| }|}qzqzW|j || j ƒƒqOW|S(sźBreak a paragraph of text up into chunks that will each fit within max_chars. Splits on whitespace (if wrapping on whitespace is used in current language) and newlines. max_chars defaults to the size of this window. iiiu N( RR RRR Rt splitlinesRt enumerateRtappendtlstrip(Rt max_charstwrap_on_whitespacet text_linestparagraphed_linestlineRtlast_whitespacetwidth_upto_last_whitespacetstart_pttiRR(tend_pt((si18n.pytconvert_paragraphÆs@             (t__doc__Rt unicodedataRR!R"R#R RRtTrueRRRR,R-R.R/R>(((si18n.pyts    -