o
    .j
                     @  sb   d dl mZ d dlZd dlZd dlZd dlZd dlZd dlmZ ej	r'd dl
Z
		ddddZdS )    )annotationsN)UnsupportedOperationctxssl.SSLContextcertdatastr | byteskeydatastr | bytes | Nonepassword5typing.Callable[[], str | bytes] | str | bytes | NonereturnNonec                   s  t tds	tdt|tr|d}|dur!t|tr!|d}tjdd}tj	|d}|dur9tj	|dnd}zt
|tjtjB  |durTt
|tjtjB  d d fdd}tj|||fdd}|  d}	|dur|durtj|||fdd}	|	  | j|||d |j	dd |	dur|	j	dd  durtd  W ||fD ]}
|
durzt|
 W q ty   Y qw qzt| W dS  ty   Y dS w ||fD ]}
|
durzt|
 W q ty   Y qw qzt| W w  ty   Y w w )a  Load cert chain using named pipes (FIFOs) instead of shm (linux).

    Creates temporary FIFOs, feeds PEM data through background threads,
    and lets ssl.SSLContext.load_cert_chain read from them. Data flows
    through kernel pipe buffers without ever touching disk.

    A single FIFO would deadlock on the second open.

    The idea came from https://github.com/jawah/urllib3.future/issues/325#issuecomment-4069433443

    :raise UnsupportedOperation: If anything goes wrong in the process.
    mkfifozhUnable to provide support for in-memory client certificate: os.mkfifo is not available on this platform.asciiNurllib3_imcc_)prefixz	cert.fifozkey.fifopathstrdatabytesr   r   c              
     sj   zt | d}|| W d    W d S 1 sw   Y  W d S  ty4 } z	| W Y d }~d S d }~ww )Nwb)openwriteBaseException)r   r   fe
writer_exc V/home/thesage/.local/lib/python3.10/site-packages/urllib3_future/contrib/imcc/_fifo.py_write_fifo7   s   &z$load_cert_chain.<locals>._write_fifoT)targetargsdaemon)keyfiler
   g      ?)timeoutzPUnable to provide support for in-memory client certificate: FIFO writer failed: )r   r   r   r   r   r   )hasattrosr   
isinstancer   encodetempfilemkdtempr   joinr   statS_IRUSRS_IWUSR	threadingThreadstartload_cert_chainunlinkOSErrorrmdir)r   r   r   r
   tmpdir	cert_fifokey_fifor    cert_thread
key_threadpr   r   r   r3      s   





r3   )NN)
r   r   r   r   r   r	   r
   r   r   r   )
__future__r   r'   r-   r*   r0   typingior   TYPE_CHECKINGsslr3   r   r   r   r   <module>   s    