HEX
Server: LiteSpeed
System: Linux php-prod-1.spaceapp.ru 5.15.0-157-generic #167-Ubuntu SMP Wed Sep 17 21:35:53 UTC 2025 x86_64
User: xnsbb3110 (1041)
PHP: 8.1.33
Disabled: NONE
Upload Files
File: //usr/local/CyberCP/lib/python3.10/site-packages/anyio/streams/__pycache__/tls.cpython-310.pyc
o

�h�;�@s�UddlmZddlZddlZddlZddlZddlmZmZddl	m
Z
ddlmZddlm
Z
ddlmZmZdd	lmZmZmZmZmZdd
lmZmZddlmZmZmZmZmZm Z ej!dkrkdd
lm"Z"ndd
l#m"Z"ej!dkrddlm$Z$m%Z%nddl#m$Z$m%Z%ej!dkr�ddlm&Z&nddl#m&Z&ed�Z'e$d�Z(e)e)e*e*fdfZ+de,d<e)e+dfZ-de,d<Gdd�de�Z.e
dd�Gdd�de��Z/e
dd�Gdd�dee/��Z0Gd d!�d!e�Z1dS)"�)�annotationsN)�Callable�Mapping)�	dataclass)�wraps)�
SSLContext)�Any�TypeVar�)�BrokenResourceError�EndOfStream�aclose_forcefully�get_cancelled_exc_class�	to_thread)�TypedAttributeSet�typed_attribute)�
AnyByteStream�AnyByteStreamConnectable�
ByteStream�ByteStreamConnectable�Listener�	TaskGroup)��
)�	TypeAlias)r�)�TypeVarTuple�Unpack)r�)�override�T_Retval�PosArgsT.r�_PCTRTT�_PCTRTTTc@s�eZdZUdZe�Zded<e�Zded<e�Zded<e�Z	ded	<e�Z
d
ed<e�Zded
<e�Zded<e�Z
ded<e�Zded<e�Zded<dS)�TLSAttributez5Contains Transport Layer Security related attributes.�
str | None�
alpn_protocol�bytes�channel_binding_tls_uniqueztuple[str, str, int]�cipherz*None | dict[str, str | _PCTRTTT | _PCTRTT]�peer_certificatezbytes | None�peer_certificate_binary�bool�server_sidez!list[tuple[str, str, int]] | None�shared_ciphers�
ssl.SSLObject�
ssl_object�standard_compatible�str�tls_versionN)�__name__�
__module__�__qualname__�__doc__rr&�__annotations__r(r)r*r+r-r.r0r1r3�r9r9�D/usr/local/CyberCP/lib/python3.10/site-packages/anyio/streams/tls.pyr$3s
r$F)�eqc@s�eZdZUdZded<ded<ded<ded	<ded
<eddddd
�d2dd��Zd3dd�Zd4dd �Zd5d"d#�Z	d6d7d(d)�Z
d8d+d,�Zd5d-d.�Ze
d9d0d1��ZdS):�	TLSStreama
    A stream wrapper that encrypts all sent data and decrypts received data.

    This class has no public initializer; use :meth:`wrap` instead.
    All extra attributes from :class:`~TLSAttribute` are supported.

    :var AnyByteStream transport_stream: the wrapped stream

    r�transport_streamr,r1r/�_ssl_objectz
ssl.MemoryBIO�	_read_bio�
_write_bioNT)r-�hostname�ssl_contextr1r-�bool | NonerAr%rB�ssl.SSLContext | None�returnc�s��|dur|}|s'|rtjjntjj}t�|�}ttd�r'|jtjM_t��}t��}t	|�tj
ur@|j||||d�}	nt�
|j||||d�IdH}	||||	||d�}
|
�|	j�IdH|
S)a�
        Wrap an existing stream with Transport Layer Security.

        This performs a TLS handshake with the peer.

        :param transport_stream: a bytes-transporting stream to wrap
        :param server_side: ``True`` if this is the server side of the connection,
            ``False`` if this is the client side (if omitted, will be set to ``False``
            if ``hostname`` has been provided, ``False`` otherwise). Used only to create
            a default context when an explicit context has not been provided.
        :param hostname: host name of the peer (if host name checking is desired)
        :param ssl_context: the SSLContext object to use (if not provided, a secure
            default will be created)
        :param standard_compatible: if ``False``, skip the closing handshake when
            closing the connection, and don't raise an exception if the peer does the
            same
        :raises ~ssl.SSLError: if the TLS handshake fails

        N�OP_IGNORE_UNEXPECTED_EOF)r-�server_hostname)r=r1r>r?r@)�ssl�Purpose�CLIENT_AUTH�SERVER_AUTH�create_default_context�hasattr�optionsrF�	MemoryBIO�typer�wrap_bior�run_sync�_call_sslobject_method�do_handshake)�clsr=r-rArBr1�purpose�bio_in�bio_outr0�wrapperr9r9r:�wrapas@��

�
�	�zTLSStream.wrap�func�&Callable[[Unpack[PosArgsT]], T_Retval]�args�Unpack[PosArgsT]r c
�s��	z||�}Wn�tjyYz|jjr!|j�|j���IdH|j��IdH}Wn&ty8|j	�
�YntyP}z
|j	�
�|j�
�t|�d}~ww|j	�
|�Ynotjyn|j�|j���IdHYnZtjy�}z
|j	�
�|j�
�t|�d}~wtjy�}z"|j	�
�|j�
�t|tj�s�|jr�d|jvr�|jr�t|�td��d}~ww|jjr�|j�|j���IdH|Sq)NT�UNEXPECTED_EOF_WHILE_READING)rH�SSLWantReadErrorr@�pendingr=�send�read�receiverr?�	write_eof�OSErrorr�write�SSLWantWriteError�SSLSyscallError�SSLError�
isinstance�SSLEOFError�strerrorr1)�selfr[r]�result�data�excr9r9r:rS�sV�

���

�

�
���z TLSStream._call_sslobject_method�tuple[AnyByteStream, bytes]c�s:�|�|jj�IdH|j��|j��|j|j��fS)z�
        Does the TLS closing handshake.

        :return: a tuple of (wrapped byte stream, bytes left in the read buffer)

        N)rSr>�unwrapr?rer@r=rc�rnr9r9r:rs�s
�

zTLSStream.unwrap�Nonec�sP�|jrz	|��IdHWntyt|j�IdH�w|j��IdHdS�N)r1rs�
BaseExceptionr
r=�aclosertr9r9r:rx�s��zTLSStream.aclose��	max_bytes�intr'c�s$�|�|jj|�IdH}|st�|Srv)rSr>rcr)rnrzrpr9r9r:rd�s
�zTLSStream.receive�itemc�s�|�|jj|�IdHdSrv)rSr>rg)rnr|r9r9r:rb�s�zTLSStream.sendc�sb�|�tj�}t�d|�}|r-t|�d��t|�d�pd�}}||fdkr-td|����td��)NzTLSv(\d+)(?:\.(\d+))?�r
r)r}rz;send_eof() requires at least TLSv1.3; current session uses z7send_eof() has not yet been implemented for TLS streams)�extrar$r3�re�matchr{�group�NotImplementedError)rnr3r��major�minorr9r9r:�send_eof�s�"���zTLSStream.send_eof�Mapping[Any, Callable[[], Any]]cs�i�jj�tj�jjtj�jjtj�jjtj	�fdd�tj
�fdd�tj�fdd�tj�fdd�tj
�fdd�tj�fdd�tj�jji
�S)Nc��j�d�S)NF�r>�getpeercertr9rtr9r:�<lambda>sz,TLSStream.extra_attributes.<locals>.<lambda>cr�)NTr�r9rtr9r:r�s�cs�jjSrv)r>r-r9rtr9r:r�scs�jjr	�j��SdSrv)r>r-r.r9rtr9r:r�s�c��jSrv�r1r9rtr9r:r��cr�rv)r>r9rtr9r:r�r�)r=�extra_attributesr$r&r>�selected_alpn_protocolr(�get_channel_bindingr)r*r+r-r.r1r0r3�versionrtr9rtr:r�s�


�zTLSStream.extra_attributes)r=rr-rCrAr%rBrDr1r,rEr<)r[r\r]r^rEr )rErr�rEru)ry)rzr{rEr')r|r'rEru�rEr�)r4r5r6r7r8�classmethodrZrSrsrxrdrbr��propertyr�r9r9r9r:r<Os*

�
F
.



r<c@sneZdZUdZded<ded<dZded<d	Zd
ed<ed dd��Z	d!d"dd�Z	d#dd�Z
ed$dd��ZdS)%�TLSListenera�
    A convenience listener that wraps another listener and auto-negotiates a TLS session
    on every accepted connection.

    If the TLS handshake times out or raises an exception,
    :meth:`handle_handshake_error` is called to do whatever post-mortem processing is
    deemed necessary.

    Supports only the :attr:`~TLSAttribute.standard_compatible` extra attribute.

    :param Listener listener: the listener to wrap
    :param ssl_context: the SSL context object
    :param standard_compatible: a flag passed through to :meth:`TLSStream.wrap`
    :param handshake_timeout: time limit for the TLS handshake
        (passed to :func:`~anyio.fail_after`)
    z
Listener[Any]�listenerzssl.SSLContextrBTr,r1��float�handshake_timeoutrqrw�streamrrEruc�sL�t|�IdHt|t��st�t�jd|d�t|t�r#t|t��r$�dS)a�
        Handle an exception raised during the TLS handshake.

        This method does 3 things:

        #. Forcefully closes the original stream
        #. Logs the exception (unless it was a cancellation exception) using the
           ``anyio.streams.tls`` logger
        #. Reraises the exception if it was a base exception or a cancellation exception

        :param exc: the exception
        :param stream: the original stream

        NzError during TLS handshake)�exc_info)r
rkr�logging�	getLoggerr4�	exception�	Exception)rqr�r9r9r:�handle_handshake_error4s�
��z"TLSListener.handle_handshake_errorN�handler�Callable[[TLSStream], Any]�
task_group�TaskGroup | Nonec�s2�t��d��fdd��}�j�||�IdHdS)Nr�rrEruc
�s��ddlm}z$|�j��tj|�j�jd�IdH}Wd�n1s%wYWntyG}z��||�IdHWYd}~dSd}~ww�|�IdHdS)Nr
)�
fail_after)rBr1)	�r�r�r<rZrBr1rwr�)r�r��wrapped_streamrq�r�rnr9r:�handler_wrapperYs ���� ��z*TLSListener.serve.<locals>.handler_wrapper)r�rrEru)rr��serve)rnr�r�r�r9r�r:r�Ts�zTLSListener.servec�s�|j��IdHdSrv)r�rxrtr9r9r:rxks�zTLSListener.acloser�cstj�fdd�iS)Ncr�rvr�r9rtr9r:r�qr�z.TLSListener.extra_attributes.<locals>.<lambda>)r$r1rtr9rtr:r�ns�zTLSListener.extra_attributes)rqrwr�rrErurv)r�r�r�r�rErur�r�)
r4r5r6r7r8r1r��staticmethodr�r�rxr�r�r9r9r9r:r�s
"�
r�c@s2eZdZdZdddd�ddd�Zeddd��ZdS)�TLSConnectablea�
    Wraps another connectable and does TLS negotiation after a successful connection.

    :param connectable: the connectable to wrap
    :param hostname: host name of the server (if host name checking is desired)
    :param ssl_context: the SSLContext object to use (if not provided, a secure default
        will be created)
    :param standard_compatible: if ``False``, skip the closing handshake when closing
        the connection, and don't raise an exception if the server does the same
    NT�rArBr1�connectablerrAr%rBrDr1r,rErucCsN||_|pt�tjj�|_t|jtj�stdt	|j�j
����||_||_dS)Nz7ssl_context must be an instance of ssl.SSLContext, not )
r�rHrLrIrKrBrkr�	TypeErrorrPr4rAr1)rnr�rArBr1r9r9r:�__init__�s�
��
zTLSConnectable.__init__r<c�sR�|j��IdH}ztj||j|j|jd�IdHWSty(t|�IdH�w)Nr�)	r��connectr<rZrArBr1rwr
)rnr�r9r9r:r��s���zTLSConnectable.connect)
r�rrAr%rBrDr1r,rEru)rEr<)r4r5r6r7r�rr�r9r9r9r:r�us�r�)2�
__future__rr�rrH�sys�collections.abcrr�dataclassesr�	functoolsrr�typingrr	r�rrr
rr�_core._typedattrrr�abcrrrrrr�version_infor�typing_extensionsrrrr r!�tupler2r"r8r#r$r<r�r�r9r9r9r:�<module>sB 
	

MX