Team Ai
Datasetpublic

codekingpro/portable-devtools

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

2��j�3��X�SrSSKrSSKrSSKJr SSKJr SSKJr SSKJ	r	 SSK3Jr SSKJ
r
 SS	KJr SS4KJr SSKJr SSKJr SS
KJr SSKJr SSKJr SSKJr SSKJr \"S5r\\\
\4rSr"SS\5r"SS5r\r "SS\5r!\	"SS\55r"g)z!5Base class for protocol layers.6�N)�abstractmethod)�Callable)�	Generator)�	dataclass)�DEBUG)�Any)�ClassVar)�7NamedTuple)�TypeVar)�8Connection)�commands)�events)�Command)�	StartHook)�Context�Tic�B�\rSrSr%Sr\R\S'\\S'Sr	g)�Paused�#zK9State of a layer that's paused because it is waiting for a command reply.10�command�	generator�N)11�__name__�12__module__�__qualname__�__firstlineno__�__doc__r
r�__annotations__�CommandGenerator�__static_attributes__r��[D:\code\apps\devtools\python\user_packages\Python313\site-packages\mitmproxy/proxy/layer.pyrr#s����
�
���r!rc�f�\rSrSr%SrSr\\\S'\	\S'\13S-\S'\R\
R\S'Sr\S-\S	'S\	S14S4SjrSrS
r\S15\4Sj5r\S\
RS16\S4Sj5rS\
RS17\S4SjrSS\4SjjrS\
R44SjrSrg)�Layer�,a�18The base class for all protocol layers.19 20Layers interface with their child layer(s) by calling .handle_event(event),21which returns a list (more precisely: a generator) of commands.22Most layers do not implement .directly, but instead implement ._handle_event, which23is called by the default implementation of .handle_event.24The default implementation of .handle_event allows layers to emulate blocking code:25When ._handle_event yields a command that has its blocking attribute set to True, .handle_event pauses26the execution of ._handle_event and waits until it is called with the corresponding CommandCompleted event.27All events encountered in the meantime are buffered and replayed after execution is resumed.28 29The result is code that looks like blocking code, but is not blocking:30 31    def _handle_event(self, event):32        err = yield OpenConnection(server)  # execution continues here after a connection has been established.33 34Technically this is very similar to how coroutines are implemented.35��_Layer__last_debug_message�contextN�_paused�_paused_event_queue�debug�returnc��XlURRRU5 SUl[R36"5Ul[URSS5nU(aS[UR5-Ul37gg)N�proxy_debugFz  )r(�layers�appendr)�collections�dequer*�getattr�options�lenr+)�selfr(�show_debug_outputs   r"�__init__�Layer.__init__Ssg���������"�"�4�(����#.�#4�#4�#6�� �#�G�O�O�]�E�J�����G�N�N� 3�3�D�J�r!c���[USUR5n[USS5nURSS5nUS:XaSnOSU3n[U5RSUS3$)	N�staterr&�state_�
_handle_eventzstate: �(�))r3r=�replace�typer)r6�statefunr;s   r"�__repr__�Layer.__repr__]sk���4��$�*<�*<�=����*�b�1���
�
�h��+���O�#��E��e�W�%�E��t�*�%�%�&�a��w�a�0�0r!c��[U5[:�aUS[S-n[RU:Xa;UR	SS5SR5n[U5S:�aUSSS-nOU[lURce[R"[R"XR5[5$)zJyield a Log command indicating what message is passing through this layer.Nu…�38�r�)r5�MAX_LOG_STATEMENT_SIZEr$r'�split�stripr+r
�Log�textwrap�indentr)r6�messages  r"�__debug�
Layer.__debuggs����w�<�0�0��5�5�6��>�G��%�%��0��m�m�D�!�,�Q�/�5�5�7�G��7�|�c�!�!�$�3�-�%�/���)0�E�&��z�z�%�%�%��|�|�H�O�O�G�Z�Z�@�%�H�Hr!c���URRRU5nSRSURRSUS-55$![a [U5s$f=f)zKrepr() for this layer and all its parent layers, only useful for debugging.z >> c3�8# �UHn[U5v� M g7f�N)�repr)�.0�xs  r"�	<genexpr>�"Layer.stack_pos.<locals>.<genexpr>|s���O�0N�1�t�A�w�w�0N�s�NrG)r(r/�index�join�39ValueErrorrU)r6�idxs  r"�	stack_pos�Layer.stack_postsi��	P��,�,�%�%�+�+�D�1�C��;�;�O����0C�0C�I�c�A�g�0N�O�O�O���	���:��	�s�%A�A1�0A1�eventc#�$# �SShv�N gN7f)zHandle a proxy server eventrNr�r6r`s  r"r=�Layer._handle_event~s����
�
�s���c#�# �UR(a�[U[R5=(a" URURRLnUR40b!UR
U(aSOSSU35v� U(a;[U[R5(deURU5Shv�N gURRU5 gUR41bUR
SU35v� URU5nSnURU5nUR42b5[U[R5(dUR
SU35v� URSLaXl[!UU5UlUv� gUv� [#U5nMN�![a gf=f![a gf=f7f)Nz>>z>!� z>> T�<< )r)�43isinstancer�CommandCompletedrr+�
_Layer__debug�_Layer__continuer*r0r=�send�
StopIterationr
rL�blockingr�next)r6r`�pause_finished�command_generatorrkrs      r"�handle_event�Layer.handle_event�s�����<�<��5�&�"9�"9�:�:��M�M�T�\�\�%9�%9�9�
��z�z�%��l�l�n�d�$�%G�q���#P�Q�Q��!�%��)@�)@�A�A�A�A��?�?�5�1�1�1��(�(�/�/��6��z�z�%��l�l�S���=�1�1� $� 2� 2�5� 9���D�
�,�0�0��6����:�:�)�%�g�x�|�|�<�<�"�l�l�S��	�?�;�;��#�#�t�+�(,�$�#)��)�$�D�L�"�M��!�M��"&�'8�"9��)�'2�� !�
��
��0)����s\�B?G
�F+�AG
�F-�+A2G
�F=�)G
�-44F:�7G
�9F:�:G
�=45G46�G
�	G47�48G
rpc#�n# �URU5nURb5[U[R495(dUR
SU35v� URSLaXl[UU5Ul	Uv� gUv� [U5nM![a gf=f![a gf=f7f)z�50Yield commands from a generator.51If a command is blocking, execution is paused and this function returns without52processing any further commands.53NTrf)rkrlr+rgr
rLrirmrr)rn)r6rprkrs    r"�	__process�Layer.__process�s����	�(�,�,�T�2�G���z�z�%�!�'�8�<�<�8�8��,�,��W�I��7�7����4�'�$(� �%��%� ����
���
��"�#4�5�G�)���	��	��0%����sL�B5�B�A2B5�B%�B5�54B"�B5�!B"�"B5�%55B2�/B5�1B2�2B5c#�# �URceURRnSUlURX!R5Shv�N UR(d�UR(a�URR5nURbURSU35v� URU5nURU5Shv�N UR(dUR(aM�ggggN�N.7f)z�56Continue processing events after being paused.57The tricky part here is that events in the event queue may trigger commands which again pause the execution,58so we may not be able to process the entire queue.59Nz!> )	r)r�_Layer__process�replyr*�popleftr+rir=)r6r`rp�evs    r"�60__continue�Layer.__continue�s�����|�|�'�'�'� �L�L�2�2������>�>�"3�[�[�A�A�A��,�,�4�#;�#;��)�)�1�1�3�B��z�z�%��l�l�S���:�.�.� $� 2� 2�2� 6���~�~�&7�8�8�8��,�,�4�#;�#;�#;�,�#;�,�	B�
9�s+�AD�
D�BD�D�&D�?D�D)r)r*r(r+rT)rrrrrr'r	�strrrrr1r2r�Eventr+r8rCri�propertyr^rrr=rqrwrhrjr rr!r"r$r$,s���(+-��(�3�-�,�
��
�d�]���%�*�*�6�<�<�8�8���E�3��:���614��4�D�4�1�I��P�3�P��P���6�<�<��4D�T�4J����4�&�,�,�4�3C�D�3I�4�n$�+;�$�L9�� 7� 7�9r!r$c��^�\rSrSr%\S-\S'\\R\S'\	\S'SS\62S\	SS4U4S	jjjrS63rS\R4U4Sjjr
S\R4S
jrSrSrSrS\4SjrSrU=r$)�	NextLayer��N�layerr�
_ask_on_startr(�ask_on_startr,c�>�[TU]U5 URRR	U5 SUl/UlX lSUlgrT)	�superr8r(r/�remover�rr��_handle)r6r(r��	__class__s   �r"r8�NextLayer.__init__sC���
����!������"�"�4�(���64����)��QU��r!c�"�SUR<3$)Nz65NextLayer:)r��r6s r"rC�NextLayer.__repr__	s���D�J�J�>�*�*r!r`c#�># �URbURU5Shv�N g[TU]	U5Shv�N gNN7frT)r�r�rq)r6r`r�s  �r"rq�NextLayer.handle_events=�����<�<�#��|�|�E�*�*�*��w�+�E�2�2�2�
+�2�s�"A�A�A�A�A�Ac#�,# �URRU5 UR(a8[U[R5(aUR5Shv�N g[U[R5(aQURURR:Xa-[R"URR5v� g[U[R5(aUR5Shv�N ggN�N7frT)rr0r�rg�Start�_ask�mevents�ConnectionClosed�66connectionr(�clientr
�CloseConnection�DataReceivedrbs  r"r=�NextLayer._handle_events���������5�!����*�U�F�L�L�"A�"A��y�y�{�"�"��u�g�6�6�7�7�� � �D�L�L�$7�$7�7��*�*�4�<�<�+>�+>�?�?�
��w�3�3�
4�
4��y�y�{�"�"�5�
#�
#�s%�AD�!D�"B'D�	D�67D�Dc#� # �[U5v� UR(a�UR(a7[R"URSUR<3[685v� URH&nURRU5Shv�N M( URR5 URRUlURRUl	URRUl69ggNu7f)zs70Manually trigger a next_layer hook.71The only use at the moment is to make sure that the top layer is initialized.72z[nextlayer] N)�
NextLayerHookr�r+r
rLrrrq�clearr=r�)r6�es  r"r��NextLayer._ask#s����73�D�!�!��:�:��z�z��l�l�d�j�j�\��d�j�j�^�#L�e�T�T��[�[���:�:�2�2�1�5�5�5�!��K�K����!%�74�75� 7� 7�D��!%���!8�!8�D���:�:�2�2�D�L��6�s�BD�D�A6Dc�L�URURR5$rT)�_datar(r�r�s r"�data_client�NextLayer.data_client=����z�z�$�,�,�-�-�.�.r!c�L�URURR5$rT)r�r(�serverr�s r"�data_server�NextLayer.data_server@r�r!r�c�R^�U4SjUR5nSRU5$)Nc3�># �UHDn[U[R5(dM$URT:XdM6URv� MF g7frT)rgr�r�r��data)rVr�r�s  �r"rX�"NextLayer._data.<locals>.<genexpr>Ds?����76� ���!�W�1�1�2�
�78�|�|�z�7Q�
�A�F�F� �s�#A�A�Ar!)rr[)r6r�r�s ` r"r��NextLayer._dataCs&���77��[�[�78��79�x�x��~�r!)r�r�r=rrqr�)F)rrrrr$r�listr�r~�boolrr8rCrqr=r�r�r�rr�r �
__classcell__)r�s@r"r�r��s�����4�<��0�������>���V��V�t�V��V�V�+�3�'�-�-�3�#�7�=�=�#�"3�4/�/��80��r!r�c�$�\rSrSr%Sr\\S'Srg)r�iLz�81Network layers are being switched. You may change which layer will be used by setting data.layer.82 83(by default, this is done by mitmproxy.addons.NextLayer)84r�rN)rrrrrr�rr rr!r"r�r�Ls����Or!r�)#rr1rM�abcr�collections.abcrr�dataclassesr�loggingr�typingrr	r85r�mitmproxy.connectionr�mitmproxy.proxyr
r�mitmproxy.proxy.commandsrr�mitmproxy.proxy.contextrrrrIrr$r�r�r�rr!r"�<module>r�s�������$�%�!������+�$�"�,�.�+��C�L���W�c�1�_�-���86��N� �Z� �D9�D9�P��87Q��Q�h��I���r!
codekingpro/portable-devtools · Team Ai