Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes15kdownloads
strutils.cpython-313.pyc139 linesDownload Raw Back to __pycache__
1�

2��jv"�	��SSKrSSKrSSKrSSKJr SSKJr \S)Sj5r\S\\	-S\	4Sj5rSS\-\	-SS\	-4Sjr\S)S	j5r3\S\\	-S\4S4j5r5SS\-\	-SS\-4Sjr6\"S5Vs0sHnU\"S
5_M snr
\"S
5\
S'\
R5rSHr\\"\5	M \R#\
5r
\R#\5rS*S\S\4SjjrS+S\	S\S\S\4SjjrS\S\	4SjrS\	S\4SjrS\	S\4SjrSrSrSrSrSrSrS rS!rS\S"\\4S#jr S\S"\\4S$jr!S\4S%jr"S&\S'\#S\4S(jr$gs snf),�N)�Iterable)�overload�str_or_bytes�returnc��g�N��r�encode_argss  �^D:\code\apps\devtools\python\user_packages\Python313\site-packages\mitmproxy/utils/strutils.py�always_bytesr
7s��<?�c��grr	r8s  rr
r
s��DGrc���Ub[U[5(aU$[U[5(aUR"U6$[	S[U5RS35e)N�Expected str or bytes, but got �.)�9isinstance�bytes�str�encode�	TypeError�type�__name__r10s  rr
r
s]����z�,��>�>���	�L�#�	&�	&��"�"�K�0�0��-�d�<�.@�.I�.I�-J�!�L�11�	12rc��grr	r13s  r�14always_strrs��:=rc��grr	r15s  rrr!s��@Crc���Ub[U[5(aU$[U[5(aUR"U6$[	S[U5RS35e)z*16Returns,17    str_or_bytes unmodified, if18rr)rrr�decoderrr)r�decode_argss  rrr%s_��19��z�,��<�<���	�L�%�	(�	(��"�"�K�0�0��-�d�<�.@�.I�.I�-J�!�L�20�	21r� r�)�
�22�	�textc��[U[5(d![S[U5R35eU(a[23O[nURU5$)z�24Replace all unicode C1 control characters from the given text with a single "."25 26Args:27    keep_spacing: If True, tabs and newlines will not be replaced.28z!text type must be unicode but is )rr�29ValueErrorrr�_control_char_trans_newline�_control_char_trans�	translate)r%�keep_spacing�transs   r�escape_control_charactersr-EsI���d�C� � ��<�T�$�Z�=P�=P�<Q�R�S�S�+7�'�=P�E��>�>�%� � r�datar+�escape_single_quotesc�4�[U[5(d"[SURR35e[SU-5R
S5SSnU(d[R"SSU5nU(a[R"SS	U5nU$)30a31Take bytes and return a safe string that can be displayed to the user.32 33Single quotes are always escaped, double quotes are never escaped:34    "'" + bytes_to_escaped_str(...) + "'"35gives a valid Python string.36 37Args:38    keep_spacing: If True, tabs and newlines will not be escaped.39zdata must be bytes, but is �"�b������z(?<!\\)(\\\\)*\\'c�<�URS5=(d SS-$)N���')�group��ms r�<lambda>�&bytes_to_escaped_str.<locals>.<lambda>gs��a�g�g�a�j�6F�B�#�5Mrz(?<!\\)(\\\\)*\\([nrt])c�r�URS5=(d S[SSSS9URS5-$)Nr6r7r#r"r$)�n�r�tr3)r9�dictr:s rr<r=ks-��q�w�w�q�z�'�R�4�$�$�$�+G����PQ�40�+S�Sr)	rrr'�	__class__r�repr�lstrip�re�sub)r.r+r/�rets    r�bytes_to_escaped_strrISs����d�E�"�"��6�t�~�~�7N�7N�6O�P�Q�Q��t�d�{�41�42"�43"�3�44'��"�45-�C���f�f�)�+M�s�S����f�f�&�S��46��47�Jrc��[U[5(d"[SURR35e[48R"U5S$)z49Take an escaped string and return the unescaped bytes equivalent.50 51Raises:52    ValueError, if the escape sequence is invalid.53zdata must be str, but is r)rrr'rCr�codecs�
escape_decode�r.s r�escaped_str_to_bytesrNqsG���d�C� � ��4�T�^�^�5L�5L�4M�N�O�O�����%�a�(�(r�sc	��U(dg[U5S:�aC[S[S[U555HnXS-	S:HnU(aMUSUn O USSn[SU55n[SU55n[U5U-54U-55nU[U5-S:�agXT-[U5-S	:�aUR	5 gg56![57a g58f=f)NF�d�h�r3c3�b# �UH%oS:=(d SUs=:=(a S:Os v� M' g7f)�	�
r Nr	��.0�is  r�	<genexpr>� is_mostly_bin.<locals>.<genexpr>�s$���4�!�Q��E�(�R�!�[�[�b�[�(�!�s�-/c3�*# �UH	oS:�v� M g7f)�~Nr	rWs  rrZr[�s���(�a���W�a�s�gffffff�?gffffff�?T)�len�range�min�sumrr')rO�cut�is_continuation_byte�	low_bytes�59high_bytes�ascii_bytess      r�
is_mostly_binrg�s������1�v��|���c�#�s�1�v�.�/�C�$%�F�a�K�D�#8� �'�'��d�s�G���0��$�3��A��4�!�4�4�I��(�a�(�(�J��a�&�9�$�z�1�K��S��V��c�!��60	� �C��F�*�T�1�	�
�H�H�J�����	���	�s�8C61�62 63C�Cc�0�UHnUS;aMUS:Hs $ g)N)rU�64r �<Fr	)rO�chars  r�is_xmlrl�s&�����;����r�z���rc�0�U(aUSS:XaUSS$U$)z�65Many editors will silently add a newline to the final line of a66document (I'm looking at you, Vim). This function fixes this common67problem at the risk of removing a hanging newline in the rare cases68where the user actually intends it.69r4r#Nr	)rAs r�clean_hanging_newlinern�s!��	�Q�r�U�d�]���"�v�
��Hrc	#�$# �[S[U5S5HrnUSnXUS-nSRSU55nURS5n[	[UR
SS5RS	S705S55nX$U4v� Mt g7f)
z771Returns:72    A generator of (offset, hex, str) tuples73r�z0=10x� c3�(# �UHoSv� M74 g7f)z0=2xNr	rWs  rrZ�hexdump.<locals>.<genexpr>�s���/�$�Q�$�x�[�$�s��/�ascii�replaceu�rFN)r_r^�join�ljustrr-rrv)rOrY�offset�part�x�	part_reprs      r�hexdumpr}�s����75�1�c�!�f�b�
!���e�9���Q��V�}���H�H�/�$�/�/��
�G�G�B�K���%����G�Y�/�7�7��#�F��
�76�	�77�)�$�$�"�s�BBc�N�[[URS55S-5$�Nri���chr�ordr9��matchobjs r�_move_to_private_code_planer��� ���s�8�>�>�!�$�%��.�/�/rc�N�[[URS55S-785$rr�r�s r� _restore_from_private_code_planer��r�rz(?<!\\)(?:\\\\)*z[\s\S]*?z.*?z(?:.|(?<=\\)\n)*?�area_delimiterc��[R"SRSRU55U[RS9$)aN79Split a string of code into a [code, special area, code, special area, ..., code] list.80 81For example,82 83>>> split_special_areas(84>>>     "test /* don't modify me */ foo",85>>>     [r"/\*[\s\S]*?\*/"])  # (regex matching comments)86["test ", "/* don't modify me */", " foo"]87 88"".join(split_special_areas(x, ...)) == x always holds true.89z({})�|)�flags)rF�split�formatrw�	MULTILINE)r.r�s  r�split_special_areasr��s-�� �8�8�F�M�M�#�(�(�>�":�;�T����V�Vrc� �[R"5n[X5n[R"SUS35n[U5H6upgUS-(aUR
[U5nURU5 M8 UR5$)uL90Escape all control characters present in special areas with UTF8 symbols91in the private use plane (U+E000 t+ ord(char)).92This is useful so that one can then use regex replacements on the resulting string without93interfering with special areas.94 95control_characters must be 0 < ord(x) < 256.96 97Example:98 99>>> print(x)100if (true) { console.log('{}'); }101>>> x = escape_special_areas(x, "{", ["'" + SINGLELINE_CONTENT + "'"])102>>> print(x)103if (true) { console.log('�}'); }104>>> x = re.sub(r"\s*{\s*", " {105", x)106>>> x = unescape_special_areas(x)107>>> print(x)108if (true) {109    console.log('{}'); }110�[�]r3)111�io�StringIOr�rF�compile�	enumeraterGr��write�getvalue)r.r��control_characters�buf�parts�rexrYr{s        r�escape_special_areasr��st��4
�+�+�-�C���5�E�112�*�*��,�-�Q�/�1130�C��%� ����q�5����3�Q�7�A��	�	�!��!��<�<�>�rc�:�[R"S[U5$)zg114Invert escape_special_areas.115 116x == unescape_special_areas(escape_special_areas(x)) always holds true.117z[\ue000-\ue0ff])rFrGr�rMs r�unescape_special_areasr�s���6�6�$�&F��M�Mr�contentr?c��US:�deURS5nUS:�a.US:�a(URSUS-5nUS-nUS:�aUS:�aM(US:�aUSUS-nU$)Nrr#r6)�find)r�r?�poss   r�cut_after_n_linesr�sr���q�5�L�5�118�,�,�t�119�C�120
��(�q�1�u��l�l�4��q��)��	�Q�����(�q�1�u��a�x��)�C�!�G�$���Nr)rNrN)T)FF)%rKr�rF�collections.abcr�typingrr
rrrr_r�r)�copyr(r{�	maketransr-�boolrIrNrgrlrnr}r�r��	NO_ESCAPE�MULTILINE_CONTENT�SINGLELINE_CONTENT�#MULTILINE_CONTENT_LINE_CONTINUATIONr�r�r��intr�)r{s0r�<module>r�s>��
�	�	�$��121122�?�123�?�124�G�s�U�{�G�U�G�125�G�126�t�c�z�E�1�127�D�5�L�128�129�=�130�=�131�C�S�5�[�C�3�C�132�C�133�T�C�Z�%�/�134�$��*�135�*�2�Y��
���s�3�x�K�
����s�8��C��1�6�6�8��	�A�#�C��F�+�136��m�m�$7�8��!�m�m�,G�H��!�C�!�s�!�KP��137��#��CG����<)�s�)�u�)�"�U�"�t�"�J�e����	
�%�$0�0�
 �	�����&:�#�W�138
�W��S�M�W�&!�139
�!��S�M�!�HN��N��s��s��s���Cs�=E
codekingpro/portable-devtools · Team Ai