Team Ai
Datasetpublic

codekingpro/portable-devtools

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

2��j?#�3��SrSSKrSSKJr SSKJr \S\\\\\	\4\\4	r
S\
S\	4SjrS\
S\SS4S	jrS5\R S\S\
S\4SjrS
\	S\
4SjrS\S\
4SjrS\S\S\
4SjrS\S\	S\\\44SjrS\S\\
\44Sjr/SQrg)aY6tnetstring:  data serialization using typed netstrings7======================================================8 9This is a custom Python 3 implementation of tnetstrings.10Compared to other implementations, the main difference11is that this implementation supports a custom unicode datatype.12 13An ordinary tnetstring is a blob of data prefixed with its length and postfixed14with its type. Here are some examples:15 16    >>> tnetstring.dumps("hello world")17    11:hello world,18    >>> tnetstring.dumps(12345)19    5:12345#20    >>> tnetstring.dumps([12345, True, 0])21    19:5:12345#4:true!1:0#]22 23This module gives you the following functions:24 25    :dump:    dump an object as a tnetstring to a file26    :dumps:   dump an object as a tnetstring to a string27    :load:    load a tnetstring-encoded object from a file28    :loads:   load a tnetstring-encoded object from a string29 30Note that since parsing a tnetstring requires reading all the data into memory31at once, there's no efficiency gain from using the file-based versions of these32functions.  They're only here so you can use load() to read precisely one33item from a file or socket without consuming any extra data.34 35The tnetstrings specification explicitly states that strings are binary blobs36and forbids the use of unicode at the protocol level.37**This implementation decodes dictionary keys as surrogate-escaped ASCII**,38all other strings are returned as plain bytes.39 40:Copyright: (c) 2012-2013 by Ryan Kelly <ryan@rfk.id.au>.41:Copyright: (c) 2014 by Carlo Pires <carlopires@gmail.com>.42:Copyright: (c) 2016 by Maximilian Hils <tnetstring3@maximilianhils.com>.43 44:License: MIT45�N)�BinaryIO)�Union�value�returnc�h�[R"5n[USU5 SRU5$)z646This function dumps a python object as a tnetstring.47r�)�collections�deque�_rdumpq�join)r�qs  �]D:\code\apps\devtools\python\user_packages\Python313\site-packages\mitmproxy/io/tnetstring.py�dumpsr2s,��'�,�,�.�A��A�q�%���8�8�A�;�r�file_handlec�8�UR[U55 g)zV48This function dumps a python object as a tnetstring and49writes it to the given file.50N)�writer)rrs  r�dumpr>s��51���e�E�l�#rr
�sizec��URnUc
U"S5 US-$USLa
U"S5 US-$USLa
U"S5 US-$[U[5(a][U5R	5n[U5n[U5R	5nU"S	Xd4-5 US52-[U5-U-$[U[5(a][U5R	5n[U5n[U5R	5nU"SXd4-5 US53-[U5-U-$[U[5(aZUn[U5n[U5R	5nU"S5 U"U5 U"S
5 U"U5 US54-[U5-U-$[U[5(aiUR	S5n[U5n[U5R	5nU"S5 U"U5 U"S
5 U"U5 US55-[U5-U-$[U[[45(ahU"S5 US-=pq[U5Hn[XU5nM [X-565R	5nU"S
5 U"U5 US-[U5-$[U[5(a{U"S5 US-=pqUR5Hup�[XU575n[XU	5nM [X-585R	5nU"S
5 U"U5 US-[U5-$[SUS[!U5S35e)a�59Dump value as a tnetstring, to a deque instance, last chunks first.60 61This function generates the tnetstring representation of the given value,62pushing chunks of the output onto the given deque instance.  It pushes63the last chunk first, then recursively generates more chunks.64 65When passed in the current size of the string in the queue, it will return66the new size of the string in the queue.67 68Operating last-chunk-first makes it easy to calculate the size written69for recursive structures without having to build their representation as70a string.  This is measurably faster than generating the intermediate71strings, especially on deeply nested structures.72s0:~�Ts4:true!�Fs5:false!�s%s:%s#�s%s:%s^�,�:�utf8�;�]��}zunserializable object: z (�))�73appendleft�74isinstance�int�str�encode�len�float�repr�bytes�list�tuple�reversedr�dict�items�75ValueError�type)r
rrr�data�ldata�span�	init_size�item�k�vs           rrrFs��� 
�L�L�E��}�
�f�
��a�x��	�$��
�j���a�x��	�%��
�k���a�x��	�E�3�	�	��5�z� � �"���D�	���5�z� � �"��
�i�4�,�&�'��a�x�#�d�)�#�e�+�+�	�E�5�	!�	!�76�E�{�!�!�#���D�	���5�z� � �"��
�i�4�,�&�'��a�x�#�d�)�#�e�+�+�	�E�5�	!�	!����D�	���5�z� � �"��
�d��
�d��
�d��
�d���a�x�#�d�)�#�e�+�+�	�E�3�	�	��|�|�F�#���D�	���5�z� � �"��
�d��
�d��
�d��
�d���a�x�#�d�)�#�e�+�+�	�E�D�%�=�	)�	)�
�d���!�8�#�	��U�O�D��1�D�)�D�$��4�#�$�+�+�-��
�d��
�d���a�x�#�d�)�#�#�	�E�4�	 �	 �
�d���!�8�#�	��K�K�M�D�A��1�A�&�D��1�A�&�D�"��4�#�$�+�+�-��
�d��
�d���a�x�#�d�)�#�#��2�5�'��D��K�=��J�K�Kr�stringc�0�[[U55S$)z977This function parses a tnetstring into a python object.78r)�pop�79memoryview)r9s r�loadsr=�s���z�&�!�"�1�%�%rc��URS5nUS:Xa[S5eSnUR5(aFX!-
n[U5S:�a[S5eURS5nUR5(aMFUS:wa[S5e[	UR[U555nURS5Sn[
XC5$)	z�load(file) -> object80 81This function reads a tnetstring from a file and parses it into a82python object.  The file must support the read() method, and this83function promises not to read more data than necessary.84rrznot a tnetstring: empty file�z.not a tnetstring: absurdly large length prefixrz2not a tnetstring: missing or invalid length prefixr)�readr0�isdigitr'r<r$�parse)r�c�data_lengthr2�	data_types     r�loadrF�s���	�����A��C�x��7�8�8��K�85�)�)�+�+�����{��b� ��M�N�N����Q���	�)�)�+�+�86	�D�y��M�N�N��k�&�&�s�;�'7�8�9�D�� � ��#�A�&�I���!�!rrEr2c��U[S5:XaUR5$U[S5:Xa[US5$U[S5:Xa[U5$U[S5:Xa[U5$U[S5:XaUS	:Xag87US:Xag[	S
U<35eU[S5:XaU(a[	SU<35egU[S5:Xa2/nU(a'[
U5up1URU5 U(aM'U$U[S5:Xa20nU(a'[
U5upQ[
U5upaXdU'U(aM'U$[	SU35e![a [	SU<35ef=f![a [	SU<35ef=f)Nrrr�#z+not a tnetstring: invalid integer literal: �^z)not a tnetstring: invalid float literal: �!strueTsfalseFz+not a tnetstring: invalid boolean literal: �~z(not a tnetstring: invalid null literal: rr zunknown type tag: )�ord�tobytesr%r$r0r(r;�append)rEr2�lstr6�d�key�vals       rrBrB�s����C��I���|�|�~���C��I���4�� � ��C��I��	U��t�9���C��I��	S���;���C��I���7�?��
�X�
���J�4�(�S�T�T��C��I����G��x�P�Q�Q���C��I������T��J�D��J�J�t���d��88��C��I������D�	�I�C��D�	�I�C��c�F��d���89�)�)��5�906�6��?�	U��J�4�(�S�T�T�	U��91�	S��H���Q�R�R�	S�s�92E�&93E0�E-�0F94�sepc���Sn[U5nXU:waUS-
nXU:waM[USU5XS-S4$![[4a [SUR	5<35ef=f)Nrrz4not a tnetstring: missing or invalid length prefix: )rLr$�95IndexErrorr0rM)r2rS�i�ord_seps    r�splitrX�s���	�A�	96��c�(���g�� �
��F�A��g�� ��4���8�}�d�q�5�7�m�+�+���97�#�98��B�4�<�<�>�BT�U�99�	100�101�s
� ;�;�.A)c��[US5upUSUXXS-Sp2n[X 5U4$![a [SU35ef=f)z�102This function parses a tnetstring into a python object.103It returns a tuple giving the parsed object and a string104containing any unparsed data from the end of the string.105rNrz)not a tnetstring: invalid length prefix: )rXrUr0rB)r2�lengthrE�remains    rr;r;�sn����t�$�L�F�O�"&�w��-���t�Q�J�L�?Q�����!�6�)�)���O��D�V�H�M�N�N�O�s	�,�A)rrrFr=r;)�__doc__r	�typingrrr%�boolr$r(r*r+r,r.�
TSerializablerrr106rr=rFr<rBrXr;�__all__�rr�<module>rbs��(�T����d�C��s�E�5�$��t�K�L�
�	��	�5�	�$�
�$�H�$��$�PL�{� � �PL��PL�M�PL�c�PL�f&�%�&�M�&�"�h�"�=�"�6'7�S�'7�107�'7�}�'7�T108�109�110��111�5��j��+A�112�*�j�*�U�=�*�#<�=�*�$4�r
codekingpro/portable-devtools · Team Ai