a
    zn„fëm  ã                   @  sð   d Z 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	Z
ddl	mZ ddlZddlZddlZdddœdd	„Zd
dœdd„Zdd„ Zd
dddœdd„ZG dd„ dejjjƒZG dd„ dƒZG dd„ dejjjƒZG dd„ dejjjƒZdS )aŸ  
This module defines a physical layer for remote files, accessed via HTTP(S).

Defines a :doc:`uproot.source.http.HTTPResource` (stateless) and two sources:
:doc:`uproot.source.http.MultithreadedHTTPSource` and
:doc:`uproot.source.http.HTTPSource`. The multi-threaded source only requires
the server to support byte range requests (code 206), but the general source
requires the server to support multi-part byte range requests. If the server
does not support multi-part GET, :doc:`uproot.source.http.HTTPSource`
automatically falls back to :doc:`uproot.source.http.MultithreadedHTTPSource`.

Despite the name, both sources support secure HTTPS (selected by URL scheme).
é    )ÚannotationsN)Úurlparsezurllib.parse.ParseResultúfloat | None)Ú
parsed_urlÚtimeoutc                 C  sZ   ddl m}m} | jdkr,|| j| j|d�S | jdkrF|| j| j|ƒS td| j› �ƒ‚dS )a7  
    Args:
        parsed_url (``urllib.parse.ParseResult``): The URL to connect to, which
            may be HTTP or HTTPS.
        timeout (None or float): An optional timeout in seconds.

    Creates a ``http.client.HTTPConnection`` or a ``http.client.HTTPSConnection``,
    depending on the URL scheme.
    r   )ÚHTTPConnectionÚHTTPSConnectionÚhttps)r   Úhttpz2unrecognized URL scheme for HTTP MultipartSource: N)Úhttp.clientr   r   ÚschemeÚhostnameÚportÚ
ValueError)r   r   r   r   © r   úU/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/uproot/source/http.pyÚmake_connection    s    



ÿr   Ústr©Úreturnc                 C  s    | j r| jd | j  S | jS dS )z~
    Returns the ``parsed_url.path`` with ``"?"`` and the ``parsed_url.query``
    if it exists, just the path otherwise.
    ú?N)ÚqueryÚpath)r   r   r   r   Ú	full_path8   s    r   c                 C  sF   | j du s| jdu ri S ddt | j d | j  d¡¡ d¡ i}|S )z–
    Returns the headers required for basic authorization, if parsed_url contains
    a username / password pair, otherwise returns an empty dict
    NÚAuthorizationzBasic ú:úutf-8)ÚusernameÚpasswordÚbase64Ú	b64encodeÚencodeÚdecode)r   Úretr   r   r   Úbasic_auth_headersC   s    ÿþÿÿr$   Úint)Ú	file_pathr   r   c           	      C  sz  t ||ƒ}t|ƒ}|jdt|ƒ|d� | ¡ }d|j  krDdk r¼n nt| ¡  | ¡ D ]F\}}| ¡ dkrXt	|ƒ}t ||ƒ}|jdt|ƒ|d� | ¡ } q.qXt
j d|j› d| › �¡‚q.|jdkrÜ| ¡  tj | d	¡‚|jd
k�r
| ¡  t
j d|j› d| › �¡‚| ¡ D ]:\}}| ¡ dk�r| ¡ dk�r| ¡  t|ƒ  S �q| ¡  t
j dt| ¡ ƒ› d| › �¡‚dS )a  
    Args:
        file_path (str): The URL to access as a raw string.
        parsed_url (``urllib.parse.ParseResult``): The URL to access.
        timeout (None or float): An optional timeout in seconds.

    Returns the number of bytes in the file by making a HEAD request.
    ÚHEAD©Úheadersé,  é�  Úlocationú$remote server responded with status ú) (redirect) without a 'location'
for URL é”  úHTTP(S) returned 404éÈ   zHTTP response was z7, rather than 200, in attempt to get file size
in file úcontent-lengthÚ0z1response headers did not include content-length: z	
in file N)r   r$   Úrequestr   ÚgetresponseÚstatusÚcloseÚ
getheadersÚlowerr   r
   ÚclientÚHTTPExceptionÚuprootÚ_utilÚ_file_not_foundÚstripr%   Údict)	r&   r   r   Ú
connectionÚauth_headersÚresponseÚkÚxÚredirect_urlr   r   r   Úget_num_bytesS   sP    	


ÿ
ÿÿ

ÿÿÿÿrG   c                   @  sü   e Zd ZdZdd„ Zeddœdd„ƒZedd	„ ƒZed
d„ ƒZdd„ Z	dd„ Z
ddddœdd„Zeddddœdd„ƒZeddddœdd„ƒZe dej¡Ze dej¡Zdd d!d"œd#d$„Zddd%œd&d'„Zdd dd(œd)d*„Zd+d,„ Zeddd-œd.d/„ƒZd0S )1ÚHTTPResourceal  
    Args:
        file_path (str): A URL of the file to open.
        timeout (None or float): An optional timeout in seconds.

    A :doc:`uproot.source.chunk.Resource` for HTTP(S) connections.

    For simplicity, this resource does not manage a live
    ``http.client.HTTPConnection`` or ``http.client.HTTPSConnection``, though
    in principle, it could.
    c                 C  s&   || _ || _t|ƒ| _t| jƒ| _d S ©N)Ú
_file_pathÚ_timeoutr   Ú_parsed_urlr$   Ú_auth_headers)Úselfr&   r   r   r   r   Ú__init__–   s    
zHTTPResource.__init__r   r   c                 C  s   | j S ©z1
        The timeout in seconds or None.
        ©rK   ©rN   r   r   r   r   œ   s    zHTTPResource.timeoutc                 C  s   | j S ©zN
        A ``urllib.parse.ParseResult`` version of the ``file_path``.
        ©rL   rR   r   r   r   r   £   s    zHTTPResource.parsed_urlc                 C  s   | j S )zR
        Returns a dict containing auth headers, if any for this resource
        ©rM   rR   r   r   r   rB   ª   s    zHTTPResource.auth_headersc                 C  s   | S rI   r   rR   r   r   r   Ú	__enter__±   s    zHTTPResource.__enter__c                 C  s   d S rI   r   ©rN   Zexception_typeZexception_valueÚ	tracebackr   r   r   Ú__exit__´   s    zHTTPResource.__exit__r%   Úbytes©ÚstartÚstopr   c           	      C  s4  |  ¡ }|jdkr*| ¡  tj | jd¡‚d|j  kr@dk rân nž| ¡  | ¡ D ]p\}}| ¡ dkrTt	|ƒ}t
|| jƒ}|jdt|ƒtdd|› d	|d
 › �ifi | j¤Žd� |  |||¡  S qTtj d|j› d| j› �¡‚|jdk�r| ¡  tj d|j› d| j› �¡‚z| ¡ W | ¡  S | ¡  0 dS )a%  
        Args:
            start (int): Seek position of the first byte to include.
            stop (int): Seek position of the first byte to exclude
                (one greater than the last byte to include).

        Returns a Python buffer of data between ``start`` and ``stop``.
        r/   r0   r*   r+   r,   ÚGETÚRangeúbytes=ú-é   r(   r-   r.   éÎ   z+, rather than 206 (range requests)
for URL N)r5   r6   r7   r<   r=   r>   r&   r8   r9   r   r   rK   r4   r   r@   rB   Úgetr
   r:   r;   rJ   Úread)	rN   rA   r\   r]   rC   rD   rE   rF   Úredirectr   r   r   rd   ·   sJ    	
ÿÿý
ÿÿ
ÿÿþzHTTPResource.getzuproot.source.chunk.Source)Úsourcer\   r]   c              
     sd   t | j| jƒ‰ ˆ jdt| jƒtddˆ› dˆd › �ifi | j¤Žd� ‡ ‡‡fdd„}tjj	 
|¡S )	a  
        Args:
            source (:doc:`uproot.source.http.HTTPSource` or :doc:`uproot.source.http.MultithreadedHTTPSource`): The
                data source.
            start (int): Seek position of the first byte to include.
            stop (int): Seek position of the first byte to exclude
                (one greater than the last byte to include).

        Returns a :doc:`uproot.source.futures.ResourceFuture` that calls
        :ref:`uproot.source.http.HTTPResource.get` with ``start`` and ``stop``.
        r^   r_   r`   ra   rb   r(   c                   s   |   ˆ ˆˆ¡S rI   )rd   ©Úresource©rA   r\   r]   r   r   Útaskù   s    z!HTTPResource.future.<locals>.task©r   r   r   r4   r   r@   rB   r<   rg   ÚfuturesÚResourceFuture)rg   r\   r]   rk   r   rj   r   Úfutureå   s    $ýzHTTPResource.futurer@   úlist[int, int])rg   Úrange_headerÚrangesc                   sZ   t ˆjˆjƒ‰ ˆ jdtˆjƒtf i ˆ¤ˆj¤Žd� ‡ ‡‡‡‡‡‡fdd„‰tjj	 
ˆ¡S )uÐ  
        Args:
            source (:doc:`uproot.source.http.HTTPSource`): The data source.
            ranges (list of (int, int) 2-tuples): Intervals to fetch
                as (start, stop) pairs in a single request, if possible.
            futures (dict of (int, int) â†’ :doc:`uproot.source.futures.ResourceFuture`): Mapping
                from (start, stop) to a future that is awaiting its result.
            results (dict of (int, int) â†’ None or ``numpy.ndarray`` of ``numpy.uint8``): Mapping
                from (start, stop) to None or results.

        Returns a :doc:`uproot.source.futures.ResourceFuture` that attempts
        to perform an HTTP(S) multipart GET, filling ``results`` to satisfy
        the individual :doc:`uproot.source.chunk.Chunk`'s ``futures`` with
        its multipart response.

        If the server does not support multipart GET, that same future
        sets :ref:`uproot.source.http.HTTPSource.fallback` and retries the
        request without multipart, using a
        :doc:`uproot.source.http.MultithreadedHTTPSource` to fill the same
        ``results`` and ``futures``. Subsequent attempts would immediately
        use the :ref:`uproot.source.http.HTTPSource.fallback`.
        r^   r(   c                   s>  �z,zèˆ   ¡ }d|j  kr$dk r¶n nŽˆ  ¡  | ¡ D ]`\}}| ¡ dkr8t|ƒ}t|ˆjƒ‰ ˆ jdt	|ƒi ˆ¥ˆj
¥d� ˆ| ƒ  W W ˆ  ¡  d S q8tj d|j› dˆj› �¡‚|  ˆ|¡}|sØ|  ˆˆˆˆ¡ n|  ˆˆˆ|ˆ¡ W n6 t�y"   t ¡ }ˆ ¡ D ]}| |¡ �qY n0 W ˆ  ¡  n
ˆ  ¡  0 d S )Nr*   r+   r,   r^   r(   r-   r.   )r5   r6   r7   r8   r9   r   r   r   r4   r   rB   r
   r:   r;   r&   Úis_multipart_supportedÚhandle_no_multipartÚhandle_multipartÚ	ExceptionÚsysÚexc_infoÚvaluesZ_set_excinfo)ri   rC   rD   rE   rF   Zmultipart_supportedÚexcinforo   ©rA   rm   rq   rr   Úresultsrg   rk   r   r   rk   $  sJ    ÿþýê
ÿÿ
ÿz&HTTPResource.multifuture.<locals>.taskrl   )rg   rq   rr   rm   r|   r   r{   r   Úmultifutureþ   s    ý-zHTTPResource.multifutures-   Content-Range: bytes ([0-9]+-[0-9]+)/([0-9]+)s$   Content-Range: bytes ([0-9]+-[0-9]+)zhttp.client.HTTPResponseÚbool)rr   rC   r   c                 C  sZ   |j dkrdS | ¡ D ]>\}}| ¡ dkrt|ƒ}|D ]\}}||| kr6  dS q6qdS )z„
        Helper function for :ref:`uproot.source.http.HTTPResource.multifuture`
        to check for multipart GET support.
        rc   Fr2   TN)r6   r8   r9   r%   )rN   rr   rC   rD   rE   Úcontent_lengthr\   r]   r   r   r   rs   X  s    
z#HTTPResource.is_multipart_supported)rg   rr   c                 C  sd   |  ¡  t ¡ }|j ||¡ tt|ƒƒD ]4}| ¡ }|j||j	|j
f< ||j	|j
f  | ¡ q*dS )z‹
        Helper function for :ref:`uproot.source.http.HTTPResource.multifuture`
        to handle a lack of multipart GET support.
        N)Ú_set_fallbackÚqueueÚQueueÚfallbackÚchunksÚrangeÚlenrd   Úraw_datar\   r]   Ú_run)rN   rg   rr   rm   r|   ÚnotificationsÚ_Úchunkr   r   r   rt   k  s    z HTTPResource.handle_no_multipart)rg   rC   rr   c              
   C  sÄ  t |dƒr|}nt|ƒ}t|ƒ}d}t|ƒdk�rÀ|  |¡\}	}
|d7 }|	du rd|  ||||¡ dS |	 d¡\}}t|ƒt|ƒ }}|d }|| }| |¡}t|ƒ|krØt	j
 dt|ƒ› d|› d|	 ¡ ›d	| j› �¡‚| ||fd¡}|du�r
||||f< | | ¡ q$|}||k r$|D ]\}}||k�r �qv�q|	 d
d¡}	d dd„ |D ƒ¡}t	j
 d|	›d|› d| j› �¡‚||| || | | … }| ||f¡}||||f< | | ¡ |}�qq$dS )z†
        Helper function for :ref:`uproot.source.http.HTTPResource.multifuture`
        to handle the multipart GET response.
        Úreadliner   rb   Nó   -zwrong chunk length z (expected z) for byte range z2 "
                    "in HTTP multipart
for URL r   Úsurrogateescapeú, c                 s  s$   | ]\}}|› d |d › �V  qdS )ra   rb   Nr   )Ú.0ÚaÚbr   r   r   Ú	<genexpr>º  ó    z0HTTPResource.handle_multipart.<locals>.<genexpr>z6unrecognized byte range in headers of HTTP multipart: z

    expecting: z


for URL )ÚhasattrÚ_ResponseBufferr@   r†   Únext_headerrt   Úsplitr%   re   r
   r:   r;   r"   rJ   Úpoprˆ   Újoin)rN   rg   rm   r|   rC   rr   Úresponse_bufferZoriginal_futuresZ	num_foundÚrange_stringÚsizer\   Úlastr]   ÚlengthÚdataÚfoundÚnowZfuture_startZfuture_stopZ	expectingZsubdatar   r   r   ru   €  sd    

þÿ
ý

þüÿÿ
zHTTPResource.handle_multipartc                 C  sŒ   |  ¡ }d\}}|du r„| j |¡}|durF| d¡}t| d¡ƒ}n"| j |¡}|durh| d¡}d}|  ¡ }t| ¡ ƒdkrq„q||fS )z˜
        Helper function for :ref:`uproot.source.http.HTTPResource.multifuture`
        to return the next header from the ``response_buffer``.
        )NNNrb   é   r   )rŒ   Ú_content_range_sizeÚmatchÚgroupr%   Ú_content_ranger†   r?   )rN   r›   Úlinerœ   r�   Úmr   r   r   r—   Ê  s    

zHTTPResource.next_header)r\   r]   c                   s   ‡ ‡‡fdd„}t jj |¡S )a  
        Returns a :doc:`uproot.source.futures.ResourceFuture` to simply select
        the ``(start, stop)`` item from the ``results`` dict.

        In :ref:`uproot.source.http.HTTPSource.chunks`, each chunk has a
        :ref:`uproot.source.http.HTTPResource.partfuture` that are collectively
        filled by a single :ref:`uproot.source.http.HTTPResource.multifuture`.
        c                   s   ˆ ˆˆf S rI   r   rh   ©r|   r\   r]   r   r   rk   ë  s    z%HTTPResource.partfuture.<locals>.task)r<   rg   rm   rn   )r|   r\   r]   rk   r   rª   r   Ú
partfutureà  s    zHTTPResource.partfutureN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__rO   Úpropertyr   r   rB   rV   rY   rd   Ústaticmethodro   r}   ÚreÚcompileÚIr¤   r§   rs   rt   ru   r—   r«   r   r   r   r   rH   ‰   s2   

.TÿJrH   c                   @  s4   e Zd ZdZdd„ Zddœdd„Zdd	œd
d„ZdS )r–   i   c                 C  s   d| _ || _d S )Nr”   )Úalready_readÚstream)rN   r¶   r   r   r   rO   ô  s    z_ResponseBuffer.__init__r%   )rŸ   c                 C  sr   |t | jƒk r0| jd |… }| j|d … | _|S t | jƒdkrb| j}d| _|| j |t |ƒ ¡ S | j |¡S d S )Nr   r”   )r†   rµ   r¶   re   )rN   rŸ   Úoutr   r   r   re   ø  s    z_ResponseBuffer.readrZ   r   c                 C  sj   z| j  d¡}W n( ty8   | j | j | j¡ | _ Y q 0 | j d |d … }| j |d d … | _ |S q d S )Nó   
rb   )rµ   Úindexr   r¶   re   ÚCHUNK)rN   r¹   r·   r   r   r   rŒ     s    z_ResponseBuffer.readlineN)r¬   r­   r®   rº   rO   re   rŒ   r   r   r   r   r–   ñ  s   r–   c                   @  sÞ   e Zd ZdZeZddœdd„Zdd„ Zdd	„ Zd
d„ Z	dd„ Z
ddddœdd„Zddddœdd„Zedd„ ƒZeddœdd„ƒZdd „ Zd!d"„ Zed#d$„ ƒZeddœd%d&„ƒZed'd(„ ƒZed)d*„ ƒZed+d,„ ƒZd-d.„ Zd/S )0Ú
HTTPSourceaŽ  
    Args:
        file_path (str): A URL of the file to open.
        options: Must include ``"num_fallback_workers"``, ``"use_threads"``, and ``"timeout"``.

    A :doc:`uproot.source.chunk.Source` that first attempts an HTTP(S)
    multipart GET, but if the server doesn't support it, it falls back to many
    HTTP(S) connections in threads
    (:doc:`uproot.source.http.MultithreadedHTTPSource`).

    Since the multipart GET is a single request and response, it needs only one
    thread, but it is a background thread (a single
    :doc:`uproot.source.futures.ResourceWorker` in a
    :doc:`uproot.source.futures.ResourceThreadPoolExecutor`).
    r   )r&   c                 K  sš   t tjjjfi |¤Ž}|d | _|d | _d| _d| _d| _	|d | _
|| _d | _d | _| ¡ | _| j| jd< |d | _t|ƒ| _t| jƒ| _|  ¡  d S )NZnum_fallback_workersr   r   Úuse_threadsÚnum_workersZhttp_max_header_bytes)r@   r<   ÚreadingÚopenÚdefaultsZ_num_fallback_workersrK   Ú_num_requestsÚ_num_requested_chunksÚ_num_requested_bytesÚ_use_threadsrJ   Ú
_num_bytesÚ	_fallbackÚcopyÚ_fallback_optionsÚ_http_max_header_bytesr   rL   r$   rM   Ú_open©rN   r&   Úoptionsr   r   r   rO   %  s     





zHTTPSource.__init__c                 C  sB   | j r$tjj t| j| jƒg¡| _ntjj 	t| j| jƒ¡| _d S rI   )
rÄ   r<   rg   rm   ÚResourceThreadPoolExecutorrH   rJ   rK   Ú	_executorÚResourceTrivialExecutorrR   r   r   r   rÊ   >  s    ÿÿzHTTPSource._openc                 C  s   t | jƒ}| d¡ |S ©NrÎ   ©r@   Ú__dict__r™   ©rN   Ústater   r   r   Ú__getstate__H  s    

zHTTPSource.__getstate__c                 C  s   || _ |  ¡  d S rI   ©rÒ   rÊ   rÓ   r   r   r   Ú__setstate__M  s    zHTTPSource.__setstate__c                 C  sn   t | jƒ}t| jƒdkr.t d| jdd …  ƒ}d}t| dd ƒd urFd}dt| ƒj› d|› |› d	t| ƒd
›d�S )Né
   z...iöÿÿÿÚ rÆ   z with fallbackú<ú z at 0xZ012xú>)ÚreprrJ   r†   ÚgetattrÚtyper¬   Úid)rN   r   rƒ   r   r   r   Ú__repr__Q  s    
zHTTPSource.__repr__r%   zuproot.source.chunk.Chunkr[   c                 C  sb   |  j d7  _ |  jd7  _|  j|| 7  _| j | ||¡}tjj | |||¡}| j	 
|¡ |S )Nrb   )rÁ   rÂ   rÃ   ÚResourceClassro   r<   rg   r‹   ÚChunkrÎ   Úsubmit)rN   r\   r]   ro   r‹   r   r   r   r‹   Z  s    zHTTPSource.chunkrp   zqueue.Queuezlist[uproot.source.chunk.Chunk])rr   r‰   r   c              
     sÆ  ˆj d u �r´ˆ jd7  _ˆ jt|ƒ7  _ˆ jtdd„ |D ƒƒ7  _g ‰ ‡ ‡‡fdd„}d\}}dd|d	 d	 › d
|d	 d d › � i}d}|t|ƒk �r`d|| d	 › d
|| d d › � }t|d ƒˆjt|ƒ k rö|d  |7  < d}n`||||| … ƒ\}	}
ˆj ˆj	 
ˆ||||| … |	|
¡¡ ||7 }dd|dd …  i}d}|d7 }q’|t|ƒk�r°|�s°|||d … ƒ\}	}
ˆj ˆj	 
ˆ||||| … |	|
¡¡ ˆ S ˆj  |ˆ¡S d S )Nrb   c                 s  s   | ]\}}|| V  qd S rI   r   )r�   r\   r]   r   r   r   r“   l  r”   z$HTTPSource.chunks.<locals>.<genexpr>c                   sz   i }i }| D ]d\}}ˆj  |||¡}||||f< d |||f< tjj ˆ|||¡}| tjj |ˆ¡¡ ˆ  |¡ q||fS rI   )	râ   r«   r<   rg   r‹   rã   Z_set_notifyZnotifierÚappend)rr   rm   r|   r\   r]   r«   r‹   ©r„   r‰   rN   r   r   Úset_futures_and_resultso  s    ÿz2HTTPSource.chunks.<locals>.set_futures_and_results)rb   r   r_   r`   r   ra   Fr�   T)rÆ   rÁ   rÂ   r†   rÃ   ÚsumrÉ   rÎ   rä   râ   r}   r„   )rN   rr   r‰   rç   ÚiÚjrq   Zlast_batch_appendedZnew_range_to_appendrm   r|   r   ræ   r   r„   d  sF    *&ÿÿÿ
ÿÿzHTTPSource.chunksc                 C  s   | j S )zŠ
        The :doc:`uproot.source.futures.ResourceThreadPoolExecutor` that
        manages this source's single background thread.
        )rÎ   rR   r   r   r   Úexecutor£  s    zHTTPSource.executorr~   r   c                 C  s   | j jS rI   )rÎ   ÚclosedrR   r   r   r   rì   «  s    zHTTPSource.closedc                 C  s   | S rI   r   rR   r   r   r   rV   ¯  s    zHTTPSource.__enter__c                 C  s(   | j  ¡  | jd ur$| j |||¡ d S rI   )rÎ   ÚshutdownrÆ   rY   rW   r   r   r   rY   ²  s    

zHTTPSource.__exit__c                 C  s   | j S rP   rQ   rR   r   r   r   r   ·  s    zHTTPSource.timeoutc                 C  s$   | j d u rt| j| j| jƒ| _ | j S rI   ©rÅ   rG   rJ   r   rK   rR   r   r   r   Ú	num_bytes¾  s
    
ÿzHTTPSource.num_bytesc                 C  s   | j S rS   rT   rR   r   r   r   r   Æ  s    zHTTPSource.parsed_urlc                 C  s   | j S ©z6
        Dict containing auth headers, if any
        rU   rR   r   r   r   rB   Í  s    zHTTPSource.auth_headersc                 C  s   | j S )zû
        If None, the source has not encountered an unsuccessful multipart GET
        and no fallback is needed yet.

        Otherwise, this is a :doc:`uproot.source.http.MultithreadedHTTPSource`
        to which all requests are forwarded.
        )rÆ   rR   r   r   r   rƒ   Ô  s    	zHTTPSource.fallbackc                 C  s   t | jfi | j¤Ž| _d S rI   )ÚMultithreadedHTTPSourcerJ   rÈ   rÆ   rR   r   r   r   r€   ß  s
    ÿÿzHTTPSource._set_fallbackN)r¬   r­   r®   r¯   rH   râ   rO   rÊ   rÕ   r×   rá   r‹   r„   r°   rë   rì   rV   rY   r   rï   r   rB   rƒ   r€   r   r   r   r   r»     s4   
	
?





r»   c                   @  sj   e Zd ZdZeZdd„ Zdd„ Zdd„ Zdd	„ Z	e
d
d„ ƒZe
ddœdd„ƒZe
dd„ ƒZe
dd„ ƒZdS )rñ   a  
    Args:
        file_path (str): A URL of the file to open.
        options: Must include ``"num_workers"``, ``"use_threads"``, and ``"timeout"``.

    A :doc:`uproot.source.chunk.MultithreadedSource` that manages many
    :doc:`uproot.source.http.HTTPResource` objects.
    c                 K  s^   d| _ d| _d| _|d | _|d | _|| _d | _|d | _t|ƒ| _	t
| j	ƒ| _|  ¡  d S )Nr   r¼   r½   r   )rÁ   rÂ   rÃ   rÄ   Ú_num_workersrJ   rÅ   rK   r   rL   r$   rM   rÊ   rË   r   r   r   rO   ñ  s    



z MultithreadedHTTPSource.__init__c                 C  s   t | jƒ}| d¡ |S rÐ   rÑ   rÓ   r   r   r   rÕ     s    

z$MultithreadedHTTPSource.__getstate__c                 C  s   || _ |  ¡  d S rI   rÖ   rÓ   r   r   r   r×     s    z$MultithreadedHTTPSource.__setstate__c                   sJ   ˆ j r,tjj ‡ fdd„tˆ jƒD ƒ¡ˆ _ntjj t	ˆ j
ˆ jƒ¡ˆ _d S )Nc                   s   g | ]}t ˆ jˆ jƒ‘qS r   )rH   rJ   rK   )r�   rŠ   rR   r   r   Ú
<listcomp>  s   ÿz1MultithreadedHTTPSource._open.<locals>.<listcomp>)rÄ   r<   rg   rm   rÍ   r…   rò   rÎ   rÏ   rH   rJ   rK   rR   r   rR   r   rÊ     s    
þÿÿzMultithreadedHTTPSource._openc                 C  s   | j S rP   rQ   rR   r   r   r   r     s    zMultithreadedHTTPSource.timeoutr%   r   c                 C  s$   | j d u rt| j| j| jƒ| _ | j S rI   rî   rR   r   r   r   rï     s
    
ÿz!MultithreadedHTTPSource.num_bytesc                 C  s   | j S rS   rT   rR   r   r   r   r   '  s    z"MultithreadedHTTPSource.parsed_urlc                 C  s   | j S rð   rU   rR   r   r   r   rB   .  s    z$MultithreadedHTTPSource.auth_headersN)r¬   r­   r®   r¯   rH   râ   rO   rÕ   r×   rÊ   r°   r   rï   r   rB   r   r   r   r   rñ   å  s   	

rñ   )r¯   Ú
__future__r   r   r   r
   r�   r²   rw   Úurllib.parseÚurllibr   r<   Zuproot.source.chunkZuproot.source.futuresr   r   r$   rG   rg   r‹   ÚResourcerH   r–   ZSourcer»   ZMultithreadedSourcerñ   r   r   r   r   Ú<module>   s,   6  j! T