https://t.me/RX1948
Server : Apache
System : Linux iad1-shared-b8-43 6.6.49-grsec-jammy+ #10 SMP Thu Sep 12 23:23:08 UTC 2024 x86_64
User : dh_edsupp ( 6597262)
PHP Version : 8.2.26
Disable Function : NONE
Directory :  /lib/python3/dist-packages/trac/util/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //lib/python3/dist-packages/trac/util/__pycache__/text.cpython-310.pyc
o

�k�`�k�	@s�ddlZddlZddlZddlZddlZddlZddlZddlmZm	Z	m
Z
ddlmZddl
Z
dZGdd�de�Ze�Z[dd�Zd�d
d�Zd�dd
�Zd�dd�Zdd�Ze�dej�Ze�dej�Zd�dd�Zd�dd�Zdddddddd d!�Zeed"��d#d$�d%D�D]Z e�!e"e �d&e �q�e�d'�Z#e�d(�Z$d)d*�Z%d+d,�Z&d�d.d/�Z'd�d1d2�Z(d3d4�Z)d�d5d6�Z*d0�+d7d8�ed9d:�D��Z,d;d<�Z-d�d>d?�Z.Gd@dA�dAe�Z/dBdC�Z0dDdE�Z1dFdG�Z2dHdI�Z3dJdK�Z4dLdM�Z5dNdO�Z6e�7�Z8dPdQ�Z7d�dSdT�Z9dUdV�Z:e:�Z;d�dXdY�Z<d�d[d\�Z=Gd]d^�d^ej>�Z?dZd0d0ej@dRfd_d`�ZAdaZBdbdc�ZCddde�ZDdfdg�ZEd�djdk�ZFdldm�ZGdndo�ZHd�dqdr�ZId�dtdu�ZJdvdw�ZKd�dxdy�ZLdzd{�ZMd|d}�ZNe�d~�ZOdd��ZPdS)��N)�quote�
quote_plus�unquote��east_asian_width�
c@seZdZdZgZdS)�Emptyz3A special tag object evaluating to the empty stringN)�__name__�
__module__�__qualname__�__doc__�	__slots__�rr�0/usr/lib/python3/dist-packages/trac/util/text.pyr#srcsbd�dd�}�fdd�}tdddd	d
d
gd�||d�	}|�|�tjdi|��}|jjtd
�|S)a8Creates a Jinja2 ``Environment`` configured with Trac conventions.

    All default parameters can optionally be overriden. The ``loader``
    parameter is not set by default, so unless it is set by the
    caller, only inline templates can be created from the environment.

    :rtype: `jinja.Environment`

    )�html�rss�xmlcSs|durdS|S�N�r)�vrrr�filterout_none9sz!jinja2env.<locals>.filterout_nonecs|o|�dd�d�vS)N�.�)�rsplit)�template��extsrr�autoescape_extensions;sz(jinja2env.<locals>.autoescape_extensionsz${�}�#z##T)z
jinja2.ext.dozjinja2.ext.i18nzjinja2.ext.with_)	�variable_start_string�variable_end_string�line_statement_prefix�line_comment_prefix�trim_blocks�
lstrip_blocks�
extensions�finalize�
autoescape��lenNr)�dict�update�jinja2�Environment�globalsr*)�kwargsrr�defaults�jenvrrr�	jinja2env.s(
�
�r3FcKstdd|i|���|�S)aZCreates a Jinja2 ``Template`` from inlined source.

    :param template: the template content
    :param text: if set to `False`, the result of the variable
                 expansion will be XML/HTML escaped
    :param kwargs: additional arguments to pass to `jinja2env`. See
                   `jinja2.Environment` for supported arguments.
    r(Nr)r3�from_string)r�textr0rrr�jinja2templateOs	r6cCs�t|t�rzt||pd�WStyt|d�YSwt|t�rnzt|�}Wnty;d�dd�|jD��YSwtj	dkrlt|t
�rO|jrOt|j�}nt|t
j�r^|jr^t|j�}nd}|rl|�||�dd	��}|St|�S)
aConvert input to a `str` object.

    For a `bytes` object, we'll first try to decode the bytes using the given
    `charset` encoding (or UTF-8 if none is specified), then we fall back to
    the latin1 encoding which might be correct or not, but at least preserves
    the original byte sequence by mapping each byte to the corresponding
    unicode code point in the range U+0000 to U+00FF.

    For anything else, a simple `str()` conversion is attempted,
    with special care taken with `Exception` objects.
    �utf-8�latin1� cs��|]}t|�VqdS�N��
to_unicode)�.0�argrrr�	<genexpr>u��zto_unicode.<locals>.<genexpr>�ntN�\\�\)�
isinstance�bytes�str�UnicodeDecodeError�	Exception�UnicodeError�join�args�os�name�EnvironmentError�filename�repr�configparser�ParsingError�source�replace)r5�charset�resultrTrrrr=]s,
�
�
r=cCsRd|jjt|�f}|r'ddlm}|��d�dd�}dtd�|��|f}|S)z�Convert an `Exception` to a `str` object.

    In addition to `to_unicode`, this representation of the exception
    also contains the class name and optionally the traceback.
    z%s: %sr)�get_last_traceback�
N���z
%s
%s)�	__class__r	r=�	trac.utilrX�splitrK)�e�	traceback�messagerX�traceback_onlyrrr�exception_to_unicode�srbcCs@t|t�rzt|t���WStyt|d�YSwt|�S)z@Convert a filesystem path to str, using the filesystem encoding.r8)rErFrG�sys�getfilesystemencodingrH)�pathrrr�path_to_unicode�s
�rfu
\A[\s​]+u
[\s​]+\ZTcCs$|rt�d|�}|rt�d|�}|S)aStrips unicode white-spaces and ZWSPs from ``text``.

    :param leading: strips leading spaces from ``text`` unless ``leading`` is
                    `False`.
    :param trailing: strips trailing spaces from ``text`` unless ``trailing``
                     is `False`.
    r)�_ws_leading_re�sub�_ws_trailing_re)r5�leading�trailingrrr�stripws�s
rlcCsft�d��|�}|rdd�|ddd�D�|ddd�<|r.dd�|ddd�D�|ddd�<d�|�S)a!Strips unicode white-spaces and ZWSPs from each line of ``text``.

    :param leading: strips leading spaces from ``text`` unless ``leading`` is
                    `False`.
    :param trailing: strips trailing spaces from ``text`` unless ``trailing``
                     is `False`.
    z(\n|\r\n|\r)cs��|]	}t�d|�VqdS�rN)rgrh�r>�linerrrr@���z strip_line_ws.<locals>.<genexpr>N�csrmrn)rirhrorrrr@�rqr)�re�compiler]rK)r5rjrk�linesrrr�
strip_line_ws�s""
rvrCz\"z\bz\fz\nz\rz\tz\')rD�"��rY�
�	�'� cCsg|]}t|��qSr)�ord�r>�crrr�
<listcomp>��r�u	&<>

z\u%04xu#[\x00-\x1f\\"\b\f\n\r\t\'&<>

]u![\x00-\x1f\\"\b\f\n\r\t&<>

]cCs|sdSdd�}t�||�S)z[Quote strings for inclusion in single or double quote delimited
    Javascript strings
    rcS�t|�d�S�Nr��	_js_quote�group��matchrrrrU��z!javascript_quote.<locals>.replace)�_js_quote_rerh�r5rUrrr�javascript_quote�sr�cCs |sdSdd�}dt�||�S)zhEmbed the given string in a double quote delimited Javascript string
    (conform to the JSON spec)
    z""cSr�r�r�r�rrrrU�r�zto_js_string.<locals>.replacez"%s")�
_js_string_rerhr�rrr�to_js_string�sr��/cC� tt|t�r
||�St|�|�S)a/A unicode aware version of `urllib.quote`

    :param value: anything that converts to a `bytes`. If `str`
                  input is given, it will be UTF-8 encoded.
    :param safe: as in `quote`, the characters that would otherwise be
                 quoted but shouldn't here (defaults to '/')
    )rrErFrG��value�saferrr�
unicode_quote�s r�rcCr�)aKA unicode aware version of `urllib.quote_plus`.

    :param value: anything that converts to a `bytes`. If `str`
                  input is given, it will be UTF-8 encoded.
    :param safe: as in `quote_plus`, the characters that would
                 otherwise be quoted but shouldn't here (defaults to
                 '/')
    )rrErFrGr�rrr�unicode_quote_plus�s 	r�cCs"t|t�r
|�d�}t|ddd�S)z�A unicode aware version of `urllib.unquote`.

    :param value: UTF-8 encoded `str` value (for example, as obtained by
                  `unicode_quote`).
    :rtype: `str`
    r8r7�strict)�encoding�errors)rErF�decoder)r�rrr�unicode_unquote�s

r�cCsrt|t�rt|��dd�d�}g}|D] \}}|tur$|�t||��q|�t||�dt||��qd�|�S)z�A unicode aware version of `urllib.urlencode`.

    Values set to `empty` are converted to the key alone, without the
    equal sign.
    cSs|dSr�r)�irrr�<lambda>sz#unicode_urlencode.<locals>.<lambda>)�key�=�&)rEr+�sorted�items�empty�appendr�rK)�paramsr��l�krrrr�unicode_urlencode�s
�
r�ccr:r;)�chrrrrrr@rAr@�!�cCs
t|t�S)z#Quote strings for query string
    )r��_qs_quote_safe�r5rrr�quote_query_strings
r�r8cCslt|t�r-zt|d�}W|Sty,zt||�}Wnty)t|d�}YnwYnwt|�}|�d�S)z�Convert input to a UTF-8 `bytes` object.

    If the input is not an `str` object, we assume the encoding is
    already UTF-8, ISO Latin-1, or as specified by the optional
    *charset* parameter.
    r7r8)rErFrGrJr=�encode)r5rV�urrr�to_utf8s

����
r�c@seZdZdZdd�ZdS)�unicode_passwdz?Conceal the actual content of the string when `repr` is called.cCsdS)Nz*******r)�selfrrr�__repr__4szunicode_passwd.__repr__N)r	r
rrr�rrrrr�2sr�cCst|dd�}|dvr|SdS)z5Return the appropriate encoding for the given stream.r�N)N�cp0r7)�getattr)�streamr�rrr�stream_encoding8sr�cOs8|�d�dd�|D���|�dd�r|�d�dSdS)z�Output the given arguments to the console, encoding the output
    as appropriate.

    :param kwargs: ``newline`` controls whether a newline will be appended
                   (defaults to `True`)
    r9csr:r;r<)r>�arrrr@FrAz console_print.<locals>.<genexpr>�newlineTrYN)�writerK�get)�outrLr0rrr�
console_print?s�r�cO�ttjg|�Ri|��dS)z%Do a `console_print` on `sys.stdout`.N)r�rc�stdout�rLr0rrr�printoutK�r�cOr�)z%Do a `console_print` on `sys.stderr`.N)r�rc�stderrr�rrr�printerrPr�r�cO�*|r||;}t|fi|��tj��dS)zUFormat `message`, do a `console.print` on `sys.stdout` and flush
    the buffer.
    N)r�rcr��flush�r`rLr0rrr�	printfoutU�r�cOr�)zUFormat `message`, do a `console.print` on `sys.stderr` and flush
    the buffer.
    N)r�rcr�r�r�rrr�	printferr_r�r�cCst|dd�tt�tjj�S)zSInput one line from the console and converts it to unicode as
    appropriate.
    F)r�)r�r=�inputrc�stdinr�)�promptrrr�	raw_inputisr�cCstS)z�Return the encoding, which is retrieved on ahead, according to user
    preference.

    We should use this instead of `locale.getpreferredencoding()` which
    is not thread-safe.)�_preferredencodingrrrr�getpreferredencodingssr�rcs*|dkrdnd�t�fdd�t|�D��S)aPDetermine the column width of `text` in Unicode characters.

    The characters in the East Asian Fullwidth (F) or East Asian Wide (W)
    have a column width of 2. The other characters in the East Asian
    Halfwidth (H) or East Asian Narrow (Na) have a column width of 1.

    That `ambiwidth` parameter is used for the column width of the East
    Asian Ambiguous (A). If `1`, the same width as characters in US-ASCII.
    This is expected by most users. If `2`, twice the width of US-ASCII
    characters. This is expected by CJK users.

    cf. http://www.unicode.org/reports/tr11/.
    rr�FWA�FWcs g|]}t|��vrdnd�qS)rrrr)r>r���twicerrr��s�ztext_width.<locals>.<listcomp>)�sumr=)r5�	ambiwidthrr�r�
text_width~s�r�cCs�tjdkrddl}|jj��}|dvrdSdSdD]*}tj�|�p"d}|rC|dkr4d	|vr4|�d	�d}|�	��
d
�r?dSdSqdS)zhReturn width of East Asian Ambiguous based on locale environment
    variables or Windows codepage.
    rBrN)i�i�i�i�rr)�LANGUAGE�LC_ALL�LC_MESSAGES�LANGrr��:)�zh�ja�kor)rMrN�ctypes�windll�kernel32�GetConsoleOutputCP�environr�r]�lower�
startswith)r��codepagerNr�rrr�_get_default_ambiwidth�s
	��r��  cs^|durtj}�dur
t�t���|r��d|�n�sdSdd���fdd���fdd�}|���t�d�}��fd	d
�t|�D�}|�d�t��D]Z\}}	t|	�D]2\}
}|
d|krb|}n |ro|dkrod
�|�}
n|}
d||
�|�t|�||
f}|�|�qU|�d�|dkr�|r�|�d�|�|
t	|��|�d�qM|�d�dS)aHPrint data according to a tabular layout.

    :param data: a sequence of rows; assume all rows are of equal length.
    :param headers: an optional row containing column headers; must be of
                    the same length as each row in `data`.
    :param sep: column separator
    :param out: output file descriptor (`None` means use `sys.stdout`)
    :param ambiwidth: column width of the East Asian Ambiguous (A). If None,
                      detect ambiwidth with the locale settings. If others,
                      pass to the `ambiwidth` parameter of `text_width`.
    NrcSs|durdSt|�Srr<)�valrrr�to_text�szprint_table.<locals>.to_textcst|�d�S�N�r�)r�r�r�rr�tw�szprint_table.<locals>.twcs�g}|D]N��fdd��D��tdd��D��rMdd��D��tdd��D��}�D]}t|�|kr=|dg|t|�7}q*|��fdd�t|�D��q|���q|S)	Ncsg|]}�|��qSrr�r>�cell�r�rrr��r�z1print_table.<locals>.to_lines.<locals>.<listcomp>css�|]}d|vVqdS)rYNrr�rrrr@�rAz0print_table.<locals>.to_lines.<locals>.<genexpr>cSsg|]}|���qSr)�
splitlinesr�rrrr��r�csr:r;r)r�rrrr@�rArc3s"�|]��fdd��D�VqdS)csg|]}|��qSrrr���idxrrr��r�z;print_table.<locals>.to_lines.<locals>.<genexpr>.<listcomp>Nr�r>��rowr�rr@�s��)�any�maxr*�extend�ranger�)�dataru�	max_linesr�r�r�r�to_lines�s�
�zprint_table.<locals>.to_linescs$g|]�t��fdd��D���qS)c3s�|]	}�|��VqdSr;r)r>r�)r�r�rrr@�rqz)print_table.<locals>.<listcomp>.<genexpr>)r�r�)r�r�r�rr��s�zprint_table.<locals>.<listcomp>rYrr9z%-*s%s�-)
rcr��_default_ambiwidth�list�insertr*r�r��	enumerater�)r��headers�sepr�r�r��num_cols�	col_width�ridxr��cidxr�rp�spr)r�r�r�r�r�print_table�sF�
�

�r�KcCs^t|pd�|kr
|Sd}|t|�}t|�dd|�|�dd|��}|dkr'|}|d|�|S)z�Truncates `text` to length less than or equal to `maxlen` characters.

    This tries to be (a bit) clever and attempts to find a proper word
    boundary for doing so.
    rz ...r9rrYN)r*r��rfind)r5�maxlen�suffix�
maxtextlen�cutrrr�shorten_line�src@sNeZdZgd�ZdZdZedd��Z		ddd	�Zd
d�Z	dd
�Z
dd�ZdS)�UnicodeTextWrapper))ii�)i�.i�.)i0i?0)i@0i�0)i�0i�0)i01i�1)i�1i�1)i�1i�1)i2i�2)i3i�3)i4i�M)iNi��)i`�i�)i�i��)i��i��)i�i��)i0�iO�)i�i�)ii��u[�-�][�-�])ii��u[�-�][�-�]NcCs�g}|jD]}t|d�}t|d�}|�d||f�qd�|�}d|}t�d|ddd	tj�|_t�d
|tj�|_dS)Nrrz%s-%srz[%s]+z(\s+|�|z$[^\s\w]*\w+[^0-9\W]-(?=\w+[^0-9\W])|z#(?<=[\w\!\"\'\&\.\,\?])-{2,}(?=\w))z\A)	�breakable_char_rangesr�r�rKrsrt�UNICODE�split_re�breakable_re)�cls�char_rangesr��high�low�patternrrr�_init_patterns"s(

�����z!UnicodeTextWrapper._init_patternsrrrcCs8tjj||dd||d�||_|jdur|��dSdS)Nr)�replace_whitespace�break_long_words�initial_indent�subsequent_indent)�textwrap�TextWrapper�__init__r�rr)r��colsr r!r"r#r�rrrr&4s�
�zUnicodeTextWrapper.__init__cCs|j�t|��}ttd|��Sr;)rr]r=r�filter)r�r5�chunksrrr�_split>szUnicodeTextWrapper._splitcCst||jd�Sr�)r�r�)r�r5rrr�_text_widthBr�zUnicodeTextWrapper._text_widthcCsjg}|��|j}|r�g}d}|r|j}n|j}|j||�}|d��dkr,|r,|d=|r�|d}||�}	||	|krH|�|���||	7}n@|j�	|�r�||}
t
t|��D]}|||�}	|
|	krfn|
|	8}
qX|dkr�|�|d|��||d�}||d<||�}	nn|s.|r�|	|kr�|�||||�|r�|d��dkr�|d=|r�|�|d�
|��|s|S)Nr���r)�reverser+r#r"�width�stripr��poprr�r�r*�_handle_long_wordrK)r�r)rur��cur_line�	cur_width�indentr.�chunk�w�
left_spacer�rrr�_wrap_chunksEsR

��,zUnicodeTextWrapper._wrap_chunks)rrrrr)r	r
rrrr�classmethodrr&r*r+r8rrrrrs

�
rc	Csb|���dd��dd�}t|dd|||d�}g}|�d�D]}||�|���p)dg7}q|�|�S)a�Wraps the single paragraph in `t`, which contains unicode characters.
    The every line is at most `cols` characters long.

    That `ambiwidth` parameter is used for the column width of the East
    Asian Ambiguous (A). If `1`, the same width as characters in US-ASCII.
    This is expected by most users. If `2`, twice the width of US-ASCII
    characters. This is expected by CJK users.
    rrYrzr)r r!r"r#r�r)r/rUrr]�wrap�rstriprK)	�tr'r"r#�linesepr��wrapper�wrappedLinesrprrrr:ys
�
r:u@…cCs@|r|�d�}|dkr|d|�t|ddkrdSdS|S)uqReplace anything looking like an e-mail address (``'@something'``)
    with a trailing ellipsis (``'@…'``)
    �@r,N�>r)�find�_obfuscation_char)�address�atrrr�obfuscate_email_address�s
��rFcCst|vS)z_Returns `True` if the `word` looks like an obfuscated e-mail
    address.

    :since: 1.2
    )rC)�wordrrr�
is_obfuscated�srHcCsF|s|Sd}|�d�rd}|dd�}||�dd��dd��dd	�S)
z_Make a path breakable after path separators, and conversely, avoid
    breaking at spaces.
    rr�rNu/​rDu\​r9� )r�rU)re�prefixrrr�breakable_path�s
�rKrI�​cCs8|s|S|D]}|�|d�}q|D]}|�|d�}q|S)zrNormalize whitespace in a string, by replacing special spaces by normal
    spaces and removing zero-width spaces.r9r)rU)r5�to_space�remove�eachrrr�normalize_whitespace�srPcCs0|r|ddvr|d|dkr|dd�S|S)zYRemove (one level of) enclosing single or double quotes.

    .. versionadded :: 1.0
    rz'"r,rr)�txtrrr�
unquote_label�s0rRcCsddlm}||���S)z<Removes uniform indentation and leading/trailing whitespace.r)�cleandoc)�inspectrSr/)r`rSrrrrS�srS�%.1fcCs�|durdSd}||krddlm}|dd|d�Sgd	�}d}||kr;|t|�kr;|d
7}|d}||kr;|t|�ks)|d|||d
fS)
z�Pretty print content size information with appropriate unit.

    :param size: number of bytes
    :param format: can be used to adjust the precision shown
    Nrir)�ngettextz%(num)d bytez
%(num)d bytes)�num)�KB�MB�GB�TBrg�@z %s)�trac.util.translationrVr*)�size�format�jumprV�unitsr�rrr�pretty_size�s�ra�cCs�d|vr|S|dur|�|�Sg}|�d�D]H}d|vr"|�|�qd}g}|D]-}|dkr@|||}|�d|�||7}q(|rF||vrP|d7}|�|�q(|�|�q(|�d�|��qd�|�S)a�Expand tab characters `'\\t'` into spaces.

    :param tabstop: number of space characters per tab
                    (defaults to the canonical 8)

    :param ignoring: if not `None`, the expansion will be "smart" and
                     go from one tabstop to the next. In addition,
                     this parameter lists characters which can be
                     ignored when computing the indent.
    r{NrYrr9rr)�
expandtabsr]r�rK)�s�tabstop�ignoring�outlinesrp�pr��nrrrrc�s,



rccCs:|��}t|t�rd}|�d�}nd}|�|�|�|�S)zFix end-of-lines in a text.�r7r)r�rErFr�r�rK)r5�eolru�lastrrr�fix_eols


rmcCs6t|�}|�d�}|rt�|�}nt�|�}t|d�S)z�Safe conversion of ``text`` to base64 representation using
    utf-8 bytes.

    Strips newlines from output unless ``strip_newlines`` is `False`.
    r7�ascii)r=r��base64�	b64encode�encodebytesrG)r5�strip_newlines�rvrrr�unicode_to_base64s


rtcCstt�|�d�S)z8Safe conversion of ``text`` to str based on utf-8 bytes.r7)rGro�	b64decoder�rrr�unicode_from_base64%srvc		Cs�t|�t|�kr
||}}|st|�Stt|�d�}t|�D]1\}}|dg}t|�D]!\}}||kd}|�t||dd||d|||��q,|}q|dS)z4Return the Levenshtein distance between two strings.rrrr,)r*r�rr��min)	�lhs�rhs�prev�lidx�lch�currr	�rch�costrrr�levenshtein_distance*s



�r�z[$]([A-Z_][A-Z0-9_]*)cs�fdd�}t�||�S)aSubstitute $XYZ-style variables in a string with provided values.

    :param text: string containing variables to substitute.
    :param args: dictionary with keys matching the variables to be substituted.
                 The keys should not be prefixed with the $ character.cs"|�d�}|�vr
�|Sd|S)Nr�$)r�)r�r��rLrr�replEs
zsub_vars.<locals>.repl)�sub_vars_rerh)r5rLr�rr�r�sub_vars?sr�)Fr;)TT)r�)r)r8)r)Nr�NN)r
)rIrL)rU)rbN)T)QrorR�localerMrsrcr$�urllib.parserrr�unicodedatarr-�CRLFrGrr�r3r6r=rbrfrtrrgrirlrvr�rr�r��
setdefaultr�r�r�r�r�r�r�r�r�rKr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrr%rr=r:rCrFrHrKrPrRrSrarcrmrtrvr�r�r�rrrr�<module>s�
!

'


�










Kr
�	


%



https://t.me/RX1948 - 2025