o
    OÊÆhC/  ã                   @  s  d dl mZ d dlZd dlZd dlZd dlmZ d dlmZ d dl	m
Z
mZmZmZmZ ddlmZmZmZmZ ddlmZmZ dd	lmZmZmZmZ ed
ƒZeeeef df Zeedf ZG dd„ deƒZ edd�G dd„ deƒƒZ!edd�G dd„ dee! ƒƒZ"dS )é    )ÚannotationsN)Ú	dataclass)Úwraps)ÚAnyÚCallableÚMappingÚTupleÚTypeVaré   )ÚBrokenResourceErrorÚEndOfStreamÚaclose_forcefullyÚget_cancelled_exc_class)ÚTypedAttributeSetÚtyped_attribute)ÚAnyByteStreamÚ
ByteStreamÚListenerÚ	TaskGroupÚT_Retval.c                   @  sž   e Zd ZU dZeƒ Zded< eƒ Zded< eƒ Zded< eƒ Z	ded	< eƒ Z
d
ed< eƒ Zded< eƒ Zded< eƒ Zded< eƒ Zded< eƒ Zded< dS )ÚTLSAttributez5Contains Transport Layer Security related attributes.ú
str | NoneÚalpn_protocolÚbytesÚchannel_binding_tls_uniqueztuple[str, str, int]Úcipherz*dict[str, str | _PCTRTTT | _PCTRTT] | NoneÚ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__r   r   Ú__annotations__r   r   r   r   r   r    r"   r#   r%   © r+   r+   ú^/var/www/html/HyperOracle/crypto_trader/venv/lib/python3.10/site-packages/anyio/streams/tls.pyr      s   
 r   F)Úeqc                   @  s    e Zd ZU dZded< ded< ded< ded	< ded
< edddddœd2dd„ƒZd3dd„Zd4dd „Zd5d"d#„Z	d6d7d(d)„Z
d8d+d,„Zd5d-d.„Zed9d0d1„ƒZdS ):Ú	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   r#   r!   Ú_ssl_objectzssl.MemoryBIOÚ	_read_bioÚ
_write_bioNT)r   ÚhostnameÚssl_contextr#   r   úbool | Noner3   r   r4   ússl.SSLContext | NoneÚreturnc                Ã  s˜   �|du r| }|s'|rt jjnt jj}t  |¡}tt dƒr'| jt j M  _t  ¡ }t  ¡ }|j	||||d�}	| |||	||d�}
|
 
|	j¡I dH  |
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/   r#   r0   r1   r2   )ÚsslÚPurposeÚCLIENT_AUTHÚSERVER_AUTHÚcreate_default_contextÚhasattrÚoptionsr8   Ú	MemoryBIOÚwrap_bioÚ_call_sslobject_methodÚdo_handshake)Úclsr/   r   r3   r4   r#   ÚpurposeÚbio_inÚbio_outr"   Úwrapperr+   r+   r,   ÚwrapF   s.   €ÿ

ÿûzTLSStream.wrapÚfuncúCallable[..., T_Retval]ÚargsÚobjectr   c                 Ç  sŒ  �	 z||Ž }W nª t jyY   z| jjr!| j | j ¡ ¡I d H  | j ¡ I d H }W n& ty8   | j	 
¡  Y n tyP } z| j	 
¡  | j 
¡  t|‚d }~ww | j	 |¡ Y nl t jyn   | j | j ¡ ¡I d H  Y nW t jy‡ } z| j	 
¡  | j 
¡  t|‚d }~w t jy² } z| j	 
¡  | j 
¡  t|t jƒs¤d|jv r­| jrªt|‚td ‚‚ d }~ww | jjrÃ| j | j ¡ ¡I d H  |S q)NTÚUNEXPECTED_EOF_WHILE_READING)r:   ÚSSLWantReadErrorr2   Úpendingr/   ÚsendÚreadÚreceiver   r1   Ú	write_eofÚOSErrorr   ÚwriteÚSSLWantWriteErrorÚSSLSyscallErrorÚSSLErrorÚ
isinstanceÚSSLEOFErrorÚstrerrorr#   )ÚselfrK   rM   ÚresultÚdataÚexcr+   r+   r,   rC   ~   sT   €

€ý€

€


ÿ
€ôÖz TLSStream._call_sslobject_methodútuple[AnyByteStream, bytes]c                 Ã  s:   �|   | jj¡I dH  | j ¡  | j ¡  | j| j ¡ fS )z„
        Does the TLS closing handshake.

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

        N)rC   r0   Úunwrapr1   rU   r2   r/   rS   ©r^   r+   r+   r,   rc   ­   s
   €

zTLSStream.unwrapÚNonec                 Ã  sP   �| j rz	|  ¡ I d H  W n ty   t| jƒI d H  ‚ w | j ¡ I d H  d S ©N)r#   rc   ÚBaseExceptionr   r/   Úacloserd   r+   r+   r,   rh   ¹   s   €þzTLSStream.acloseé   Ú	max_bytesÚintr   c                 Ã  s$   �|   | jj|¡I d H }|st‚|S rf   )rC   r0   rS   r   )r^   rj   r`   r+   r+   r,   rT   Ã   s
   €zTLSStream.receiveÚitemc                 Ã  s   �|   | jj|¡I d H  d S rf   )rC   r0   rW   )r^   rl   r+   r+   r,   rR   Ê   s   €zTLSStream.sendc                 Ã  sb   �|   tj¡}t d|¡}|r-t| d¡ƒt| d¡pdƒ}}||fdk r-td|› �ƒ‚tdƒ‚)NzTLSv(\d+)(?:\.(\d+))?é   r
   r   )rm   é   z;send_eof() requires at least TLSv1.3; current session uses z7send_eof() has not yet been implemented for TLS streams)Úextrar   r%   ÚreÚmatchrk   ÚgroupÚNotImplementedError)r^   r%   rq   ÚmajorÚminorr+   r+   r,   Úsend_eofÍ   s   €"ÿÿÿzTLSStream.send_eofúMapping[Any, Callable[[], Any]]c                   sŒ   i ˆ j j¥tjˆ jjtjˆ jjtjˆ jjtj	‡ fdd„tj
‡ fdd„tj‡ fdd„tj‡ fdd„tj‡ fdd„tj‡ fdd„tjˆ jji
¥S )Nc                     ó   ˆ j  d¡S )NF©r0   Úgetpeercertr+   rd   r+   r,   Ú<lambda>ã   s    z,TLSStream.extra_attributes.<locals>.<lambda>c                     rx   )NTry   r+   rd   r+   r,   r{   ä   s    ÿc                     s   ˆ j jS rf   )r0   r   r+   rd   r+   r,   r{   ç   s    c                     s   ˆ j jr	ˆ j  ¡ S d S rf   )r0   r   r    r+   rd   r+   r,   r{   è   s   ÿc                     ó   ˆ j S rf   ©r#   r+   rd   r+   r,   r{   ë   ó    c                     r|   rf   )r0   r+   rd   r+   r,   r{   ì   r~   )r/   Úextra_attributesr   r   r0   Úselected_alpn_protocolr   Úget_channel_bindingr   r   r   r   r    r#   r"   r%   Úversionrd   r+   rd   r,   r   Ü   s   ÿ



ñzTLSStream.extra_attributes)r/   r   r   r5   r3   r   r4   r6   r#   r   r7   r.   )rK   rL   rM   rN   r7   r   )r7   rb   ©r7   re   )ri   )rj   rk   r7   r   )rl   r   r7   re   ©r7   rw   )r&   r'   r(   r)   r*   ÚclassmethodrJ   rC   rc   rh   rT   rR   rv   Úpropertyr   r+   r+   r+   r,   r.   4   s*   
 
ù
7
/



r.   c                   @  sn   e Zd ZU dZded< ded< dZded< d	Zd
ed< ed dd„ƒZ	d!d"dd„Z	d#dd„Z
ed$dd„ƒZdS )%Ú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]Úlistenerzssl.SSLContextr4   Tr   r#   é   ÚfloatÚhandshake_timeoutra   rg   Ústreamr   r7   re   c                 Ã  sH   �t |ƒI dH  t| tƒ ƒst t¡ d¡ t| tƒr!t| tƒ ƒr"‚ dS )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

        NzError during TLS handshake)r   r[   r   ÚloggingÚ	getLoggerr&   Ú	exceptionÚ	Exception)ra   rŒ   r+   r+   r,   Úhandle_handshake_error  s   €ÿz"TLSListener.handle_handshake_errorNÚhandlerúCallable[[TLSStream], Any]Ú
task_groupúTaskGroup | Nonec                 ƒ  s2   �t ˆ ƒd‡ ‡fdd„ƒ}ˆj ||¡I d H  d S )NrŒ   r   r7   re   c              
   “  s¢   �ddl m} z$|ˆjƒ� tj| ˆjˆjd�I d H }W d   ƒ n1 s%w   Y  W n tyG } zˆ || ¡I d H  W Y d }~d S d }~ww ˆ |ƒI d H  d S )Nr
   )Ú
fail_after)r4   r#   )	Ú r–   r‹   r.   rJ   r4   r#   rg   r‘   )rŒ   r–   Úwrapped_streamra   ©r’   r^   r+   r,   Úhandler_wrapper'  s    €ýÿ€ €ÿz*TLSListener.serve.<locals>.handler_wrapper)rŒ   r   r7   re   )r   rˆ   Úserve)r^   r’   r”   rš   r+   r™   r,   r›   "  s   €zTLSListener.servec                 Ã  s   �| j  ¡ I d H  d S rf   )rˆ   rh   rd   r+   r+   r,   rh   9  s   €zTLSListener.acloserw   c                   s   t j‡ fdd„iS )Nc                     r|   rf   r}   r+   rd   r+   r,   r{   ?  r~   z.TLSListener.extra_attributes.<locals>.<lambda>)r   r#   rd   r+   rd   r,   r   <  s   ÿzTLSListener.extra_attributes)ra   rg   rŒ   r   r7   re   rf   )r’   r“   r”   r•   r7   re   rƒ   r„   )r&   r'   r(   r)   r*   r#   r‹   Ústaticmethodr‘   r›   rh   r†   r   r+   r+   r+   r,   r‡   ñ   s   
 ý
r‡   )#Ú
__future__r   r�   rp   r:   Údataclassesr   Ú	functoolsr   Útypingr   r   r   r   r	   r—   r   r   r   r   Ú_core._typedattrr   r   Úabcr   r   r   r   r   r$   Ú_PCTRTTÚ_PCTRTTTr   r.   r‡   r+   r+   r+   r,   Ú<module>   s&     =