� ��^i��T�ddlZddlZddlZddlmZddlmZdZGd�d��ZdS)�N)�ProxySchemeUnsupported)�sixi@c���eZdZdZed���Z d!d�Zd�Zd�Zd�Z d"d �Z d#d �Z d$d �Z d%d�Z d%d�Z d&d�Zd�Zd�Zd'd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd(d�Zd �ZdS))� SSLTransportaL The SSLTransport wraps an existing socket and establishes an SSL connection. Contrary to Python's implementation of SSLSocket, it allows you to chain multiple TLS connections together. It's particularly useful if you need to implement TLS within TLS. The class supports most of the socket API operations. c�z�t|d��s*tjrtd���td���dS)z� Raises a ProxySchemeUnsupported if the provided ssl_context can't be used for TLS in TLS. The only requirement is that the ssl_context provides the 'wrap_bio' methods. �wrap_biozKTLS in TLS requires SSLContext.wrap_bio() which isn't supported on Python 2zXTLS in TLS requires SSLContext.wrap_bio() which isn't available on non-native SSLContextN)�hasattrr�PY2r)� ssl_contexts ��/builddir/build/BUILDROOT/alt-python311-pip-21.3.1-4.el8.x86_64/opt/alt/python311/lib/python3.11/site-packages/pip/_vendor/urllib3/util/ssltransport.py�$_validate_ssl_context_for_tls_in_tlsz1SSLTransport._validate_ssl_context_for_tls_in_tlssZ���{�J�/�/� ��w� �,�,���� -�9���� � �NTc��tj��|_tj��|_||_||_|�|j|j|���|_|�|jj ��dS)zV Create an SSLTransport around socket using the provided ssl_context. )�server_hostnameN) �ssl� MemoryBIO�incoming�outgoing�suppress_ragged_eofs�socketr�sslobj� _ssl_io_loop� do_handshake)�selfrr rrs r �__init__zSSLTransport.__init__,su�� � ���� �� ���� �$8��!��� �!�*�*� �M�4�=�/�+� � �� � ���$�+�2�3�3�3�3�3rc��|S�N��rs r � __enter__zSSLTransport.__enter__?s��� rc�.�|���dSr)�close)r�_s r �__exit__zSSLTransport.__exit__Bs�� � � � � � � � rc�4�|j���Sr)r�filenors r r&zSSLTransport.filenoE����{�!�!�#�#�#r�c�.�|�||��Sr)�_wrap_ssl_read)r�len�buffers r �readzSSLTransport.readHs���"�"�3��/�/�/rrc�V�|dkrtd���|�|��S)Nrz+non-zero flags not allowed in calls to recv)� ValueErrorr*)rr+�flagss r �recvzSSLTransport.recvKs.�� �A�:�:��J�K�K� K��"�"�3�'�'�'rc��|dkrtd���|r|�t|��}n|�d}|�||��S)Nrz0non-zero flags not allowed in calls to recv_intor()r/r+r-)rr,�nbytesr0s r � recv_intozSSLTransport.recv_intoPsQ�� �A�:�:��O�P�P� P� � �v�~���[�[�F�F� �^��F��y�y���(�(�(rc�X�|dkrtd���d}t|��5}|�d��5}t|��}||kr(|�||d���}||z }||k�(ddd��n #1swxYwYddd��dS#1swxYwYdS)Nrz.non-zero flags not allowed in calls to sendall�B)r/� memoryview�castr+�send)r�datar0�count�view� byte_view�amount�vs r �sendallzSSLTransport.sendallYs1�� �A�:�:��M�N�N� N��� �� � � ��t�y�y��~�~� ����^�^�F��&�.�.��I�I�i����/�0�0���� ���&�.�.� � � � � � � � � � � ���� � � � � � � � � � � � � � � � ���� � � � � � s4�B�>B�; B�B � B�B �B�B#�&B#c�p�|dkrtd���|�|jj|��}|S)Nrz+non-zero flags not allowed in calls to send)r/rr�write)rr:r0�responses r r9zSSLTransport.sendcs9�� �A�:�:��J�K�K� K��$�$�T�[�%6��=�=���r�rc�.�t|��hd�kstd|�d����d|v}d|vp| }|s|sJ�d|v}d} |r| dz } |r| dz } tj|| ��} |jxjdz c_|�d }|d kr t j}|d kr|std ���| S|r|rt j| | |��} n1|rt j| |��} n|sJ�t j | |��} |r| St j | |||��} || _ | S) a Python's httpclient uses makefile and buffered io when reading HTTP messages and we need to support it. This is unfortunately a copy and paste of socket.py makefile with small changes to point to the socket directly. >�brD�wz invalid mode z (only r, w, b allowed)rGrDrF��N�����rz!unbuffered streams must be binary) �setr/r�SocketIO�_io_refs�io�DEFAULT_BUFFER_SIZE�BufferedRWPair�BufferedReader�BufferedWriter� TextIOWrapper�mode) rrT� buffering�encoding�errors�newline�writing�reading�binary�rawmode�rawr,�texts r �makefilezSSLTransport.makefileis~���4�y�y�O�O�O�+�+��*����O�P�P� P���+����+�,�W����!�'�!�!�!������� � � �s�N�G� � � �s�N�G��o�d�G�,�,�� � ����!��� � ��I� �q�=�=��.�I� ��>�>�� F� �!D�E�E�E��J� � 7�w� 7��&�s�C��;�;�F�F� � 7��&�s�I�6�6�F�F��N�N�7��&�s�I�6�6�F� � ��M�����&�'�B�B���� �� rc�D�|�|jj��dSr)rr�unwraprs r razSSLTransport.unwrap�s!�� ���$�+�,�-�-�-�-�-rc�8�|j���dSr)rr"rs r r"zSSLTransport.close�s�� � �������rFc�6�|j�|��Sr)r� getpeercert)r� binary_forms r rdzSSLTransport.getpeercert�s���{�&�&�{�3�3�3rc�4�|j���Sr)r�versionrs r rgzSSLTransport.version�s���{�"�"�$�$�$rc�4�|j���Sr)r�cipherrs r rizSSLTransport.cipher�r'rc�4�|j���Sr)r�selected_alpn_protocolrs r rkz#SSLTransport.selected_alpn_protocol�s���{�1�1�3�3�3rc�4�|j���Sr)r�selected_npn_protocolrs r rmz"SSLTransport.selected_npn_protocol�s���{�0�0�2�2�2rc�4�|j���Sr)r�shared_ciphersrs r rozSSLTransport.shared_ciphers�s���{�)�)�+�+�+rc�4�|j���Sr)r� compressionrs r rqzSSLTransport.compression�s���{�&�&�(�(�(rc�:�|j�|��dSr)r� settimeout)r�values r rszSSLTransport.settimeout�s�� � ���u�%�%�%�%�%rc�4�|j���Sr)r� gettimeoutrs r rvzSSLTransport.gettimeout�s���{�%�%�'�'�'rc�8�|j���dSr)r�_decref_socketiosrs r rxzSSLTransport._decref_socketios�s�� � �%�%�'�'�'�'�'rc�� |�|jj||��S#tj$r(}|jtjkr |jrYd}~dS�d}~wwxYw�Nr)rrr-r�SSLError�errno� SSL_ERROR_EOFr)rr+r,�es r r*zSSLTransport._wrap_ssl_read�sm�� ��$�$�T�[�%5�s�F�C�C� C���|� � � ��w�#�+�+�+��0I�+��q�q�q�q�q������  ���s� #�A�A�A�Ac���d}d}|r�d} ||�}nD#tj$r2}|jtjtjfvr|�|j}Yd}~nd}~wwxYw|j���}|j�|��|�d}ne|tjkrU|j� t��}|r|j � |��n|j � ��|��|S)z>Performs an I/O loop between incoming/outgoing and the socket.TNF)rr{r|�SSL_ERROR_WANT_READ�SSL_ERROR_WANT_WRITErr-rr@r1� SSL_BLOCKSIZErrB� write_eof)r�func�args� should_loop�retr|r~�bufs r rzSSLTransport._ssl_io_loop�s��� ���� .��E� ��d�D�k�����<� � � ��7�3�#:�C�r�s��� � � � � � � � � � � � �A�A�A�A�A�A�,�,�,�,�,�,�� �R�R�R�R�R�R�R�R�R�Rr