Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
str_util.cpython-313.pyc138 linesDownload Raw Back to __pycache__
1�

2��j�2��L�%SSKJr SSKrSSKrSSKrSSKr\R(aSSKJr \R"S5r3\R"S5rSqS\
S'SS	jrSS4jrSSjrSSjrSS
jrSSjrSSjrSSjrS SjrS!SjrS"SjrS#SjrS"SjrS"SjrS$Sjrg)%�)�annotationsN)�Literalz^[ -~]*$s^[ -~]*$�narrow�!Literal['utf8', 'narrow', 'wide']�_byte_encodingc�t�[R"S[SS9 [R"U5=nS:�aU$g)zO5Return the screen column width for a single character.6 7.. deprecated:: 3.0.48z6get_char_width is deprecated in favor of wcwidth.width���9stacklevelr)�warnings�warn�DeprecationWarning�wcwidth)�char�widths  �TD:\code\apps\devtools\python\user_packages\Python313\site-packages\urwid/str_util.py�get_char_widthr&s9��
�M�M�@����10����&�&��1�,����c��[R"S[SS9 [R"[	U55=nS:�aU$g)zN11Return the screen column width for unicode ordinal o.12 13.. deprecated:: 3.0.414z1get_width is deprecated in favor of wcwidth.widthr	r15r)rr
rr�chr)�ors  r�	get_widthr7s=��
�M�M�;����16����Q��(�(��Q�.���rc��XURS5n[[R"U5S5nUR	S5nXA[U5-4$)a17Decode bytes starting at `start` to get the first grapheme cluster.18 19:param text: UTF-8 encoded bytes20:param start: starting byte position21:param end: ending byte position22:returns: (grapheme_string, next_byte_position)23 24Assumes caller provides valid UTF-8 byte boundaries.25�utf-8�)�decode�nextr�iter_graphemes�encode�len)�text�start�end�decoded�grapheme�grapheme_bytess      r�_decode_grapheme_atr'HsP����o�$�$�W�-�G��G�*�*�7�3�R�8�H��_�_�W�-�N��S��0�0�0�0rc26���[U5U-27nSnSnSn[U[5(aP[X5nUS:�a[XS-5nUS:�a[XS-5nUS:�a[XS-5nO+XnUS:�aXS-nUS:�aXS-nUS:�aXS-nUS	-(dXaS-4$[S285US-4nUS:aU$US-S:Xa'US-S	:waU$US
-S-US--=n	S	:�aX�S-4$U$US:aU$US-S:Xa;US-S	:waU$US-S	:waU$US-S-US-S--US--=n	S:�aX�S-4$U$US:aU$US-S:XaOUS-S	:waU$US-S	:waU$US-S	:waU$US-S-US-S--US-S--US--=n	S:�aX�S-4$U$U$![a8n[USU<SU<SU<35R
UR5UeSnAff=f)z@29Return (ordinal at pos, next position) for UTF-8 encoded text.30r�r	�z: text=z, pos=z, lt=N��?�������?����i�����i)r �31isinstance�str�ord�	Exception�32ValueError�with_traceback�
__traceback__)33r!�pos�lt�b2�b3�b4�b1�e�errorrs34          r�35decode_onerHYs���36
�T��S��B�	37�B�	38�B�	39�B�o��d�C� � ��T�Y��B��A�v���A�g��'���A�v���A�g��'���A�v���A�g��'�����B��A�v���'�]���A�v���'�]���A�v���'�]����9���7�{����H�c�A�g��E�	�A�v���	�D�y�D��
��9����L���9��"�r�D�y�1�1�A�d�:��A�g�:����	�A�v���	�D�y�D��
��9����L�
��9����L���9��#��d��q�(8�9�R�$�Y�G�G�A�E�Q��A�g�:����	�A�v���	�D�y�D��
��9����L�
��9����L�
��9����L���9��#��d��r�(9�:�r�D�y�Q�>N�O�SU�X\�S\�]�]�A�bi�i��A�g�:�����L��K�o��A�3�g�d�X�V�C�7�%��v�F�G�V�V�WX�Wf�Wf�g�mn�n��o�s�A$F,�;+F,�,40G.�63G)�)G.c�&�[X5US-4$)z/41decode_one implementation for unicode strings42r))r;)r!�is  r�decode_one_unirK�s���t�w�<��Q���rc���[U[5(d[U5e[S5US-434nUnUS:�a5XS-S:wa[	X5upEXCS-444$US-nX3S-45:XaU$US:�aM5g)z46Return (ordinal at pos, next position) for UTF-8 encoded text.47pos is assumed to be on the trailing byte of a utf-8 sequence.48r,r)rr.r+r5N)r9�bytes�	TypeErrorr;rH)r!r@rG�pr�	_next_poss      r�decode_one_rightrQ�s���49�d�E�"�"���o����H�c�A�g��E��A�50�q�&��7�T�>�T�!�%�d�.�L�A��!�e�8�O�	�Q����A��:��L�
�q�&�rc�*�US;a[U5eUqg)N>�utf8�wider)r=r)�encs r�set_byte_encodingrV�s��51�,�,���o���Nrc��[$)N)r�rr�get_byte_encodingrY�s���rc���X:�a[X45eSnUn[R"XU5H7n[R"USS9nXt-U:�aXT4s $XG-
nU[	U5-
nM9 X$4$)a�52Calculate the closest position to the screen column pref_col in text53where start_offs is the offset into text assumed to be screen column 054and end_offs is the end of the range to search.55 56Iterates by grapheme clusters for emoji ZWJ sequences, flags,57combining characters, and other multi-codepoint unicode sequences.58 59:param text: string60:param start_offs: starting text position61:param end_offs: ending text position62:param pref_col: target column63:returns: (position, actual_col)64r�ignore��
control_codes)r=rrrr )r!�65start_offs�end_offs�pref_col�colsr@r%�grapheme_widths        r�calc_string_text_posrc�s������*�/�0�0��D�66�C��*�*�4�8�+D�E�� ���x�x�H��� �8�+��9������s�8�}���F��>�rc���X:�a[X45e[U[5(a[XX#5$[U[5(d[U5e[S:XaOXURS5n[US[U5U5upV[USURS55nX-U4$X-nX�:�aX"U-674$[S:Xa[XU5S:XaUS-nX�U-684$)a!69Calculate the closest position to the screen column pref_col in text70where start_offs is the offset into text assumed to be screen column 071and end_offs is the end of the range to search.72 73text may be unicode or a byte string in the target _byte_encoding74 75Returns (position, actual_col).76rSrrNrTr	r))r=r9r:rcrMrNrrr r�within_double_byte)	r!r^r_r`r$�str_posra�byte_offsetrJs	         r�
calc_text_posrh�s������*�/�0�0��$����#�D�h�I�I��d�E�"�"���o������(�+�2�2�7�;��,�W�a��W��x�P�
���'�(�7�+�2�2�7�;�<���'��-�-�	��A��}��J�.�.�.����$6�t��$K�q�$P�	�Q����*�n��rc���X:�aSU<SU<3n[U5e[U[5(a[R"XUSS9$[77S:Xa'[R"XUR
S5SS9$X!-78$![a'n[R"SU3[SS	9 S79nAOS80nAff=fUnSnXR:a=[X5upu[R"[U55=nS:�aXh-
nXR:aM=U$)aV81Return the screen column width of text between start_offs and end_offs.82 83text may be unicode or a byte string in the target _byte_encoding84 85Some characters are wide (take two columns) and others affect the86previous character (take zero columns), while others are grouped87in sequence by "grapheme boundaries" (Emoji, Skin tones, flags, etc).88zstart_offs=z > end_offs=r[r\rSrzx`calc_width` with text encoded to bytes can produce incorrect resultsdue to possible offset in the middle of character: r	r89Nr)
r=r9r:rrrr�UnicodeDecodeErrorrr
�UnicodeWarningrHr)	r!r^r_�msg�excrJ�scr�ws	         r�90calc_widthrps������
�]���,����o���$�����}�}�T�X�6�h�O�O����	��=�=���!:�!A�!A�'�!J�Zb�c�c�"� � ��!"�	��M�M�F�FI�U�L���	
��	��
��
���l��d�&�D�A��_�_�S��V�,�,���1�����l��	s�%A<�<91B-�B(�(B-c��[U[5(a9[[R"XS55n[R92"USS9S:H$[U[5(d[U5e[S:Xa/[X[U55up#[R93"USS9S:H$[S:Xa[XU5S:H$g)	aK94Test if the grapheme cluster at offs within text is wide (2 columns).95 96For Unicode strings, extracts the full grapheme cluster starting at offs97and checks if it renders as wide. This correctly handles multi-codepoint98graphemes like emoji ZWJ sequences and flags.99 100text may be unicode or a byte string in the target _byte_encoding101Nr[r\r	rSrTr)F)r9r:rrrrrMrNrr'r re)r!�offsr%�_s    r�is_wide_charrt)s����$������.�.�t�E�{�;�<���}�}�X�X�>�!�C�C��d�E�"�"���o�����)�$�c�$�i�@����}�}�X�X�>�!�C�C����!�$�d�3�q�8�8�rc���X:�a[X45e[U[5(a[R"X5$[U[1025(d[
U5e[S:XaVXURS5n[U5n[R"X45nUSUnU[URS55-$[S:Xa[XUS-1035S:XaUS-104$US-105$)z�106Return the position of the grapheme cluster before end_offs.107 108For Unicode strings, handle multi-codepoint, "grapheme clusters",109to better measure emoji ZWJ, flags, combining characters, skin tones.110rSrNrTr)r	)r=r9r:r�grapheme_boundary_beforerMrNrrr rre)r!r^r_r$rf�prev_str_pos�prefixs       r�move_prev_charry@s������*�/�0�0��$�����/�/��?�?��d�E�"�"���o������(�+�2�2�7�;���g�,���7�7��I����,�'���C��
�
�g� 6�7�7�7����$6�t��TU��$V�Z[�$[��!�|���a�<�rc�h�X:�a[X45e[U[5(a/[[R111"XU55nU[
U5-$[U[5(d[U5e[S:Xa[XU5upEU$[S:Xa[XU5S:XaUS-$US-$)z�112Return the position of the next grapheme cluster after start_offs.113 114For Unicode strings, handle multi-codepoint, "grapheme clusters",115to better measure emoji ZWJ, flags, combining characters, skin tones.116rSrTr)r	)r=r9r:rrrr rMrNrr're)r!r^r_r%rs�next_poss      r�move_next_charr|Xs������*�/�0�0��$������.�.�t�x�/H�I�J���C��M�)�)��d�E�"�"���o�����)�$�H�E��������$6�t��$T�XY�$Y��A�~����>�rc��[U[5(d[U5eXnSUs=::aS:a)O O&X!:XagXS-117S:�a[XUS-1185S:XaggUS:agUS-119nXA:�aXS:aOUS-nXA:�aMX$-120S-(agg)aJReturn whether pos is within a double-byte encoded character.121 122text -- byte string in question123line_start -- offset of beginning of line (< pos)124pos -- offset in question125 126Return values:1270 -- not within dbe char, or double_byte_encoding == False1281 -- pos is on the 1st half of a dbe char1292 -- pos is on the 2nd half of a dbe char130�@�rr)�r	r+)r9rMrNre)r!�131line_startr@�vrJs     rrerens����d�E�"�"���o���	�A��q��4������a��=�D� �%7��#�PQ�'�%R�VW�%W����4�x���a��A�132�/��7�T�>��	�Q����/�133	��1�}��r)rr:�return�Literal[0, 1, 2])r�intr�r�)r!rMr"r�r#r�r�ztuple[str, int])r!zbytes | strr@r�r��tuple[int, int])r!r:rJr�r�r�)r!rMr@r�r�ztuple[int, int] | None)rUrr��None)r�r)134r!r:r^r�r_r�r`r�r�r�)135r!�str | bytesr^r�r_r�r`r�r�r�)r!r�r^r�r_r�r�r�)r!r�rrr�r��bool)r!rMr�r�r@r�r�r�)�136__future__r�re�typingrr�
TYPE_CHECKING�typing_extensionsr�compile�
SAFE_ASCII_RE�SAFE_ASCII_BYTES_REr�__annotations__rrr'rHrKrQrVrYrcrhrprtryr|rerXrr�<module>r�s���*#�	�
���	���)��137�138�;�'�
��j�j��.��4<��1�<�
�"
�"1�"@�F��&���<�D%!�P�.�0�,$
r
codekingpro/portable-devtools · Team Ai