a
    zn„fá  ã                   @  sX   d Z ddlmZ ddlZddlZddl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 file-like objects.

Defines a :doc:`uproot.source.object.ObjectResource` (wrapped Python file-like
object) and one source :doc:`uproot.source.object.ObjectSource` which always
has exactly one worker (we can't assume that the object is thread-safe).
é    )ÚannotationsNc                   @  sl   e Zd ZdZdd„ Zedd„ ƒZeddœdd	„ƒZd
d„ Zdd„ Z	dddœdd„Z
eddddœdd„ƒZdS )ÚObjectResourcea(  
    Args:
        obj: The file-like object to use.

    A :doc:`uproot.source.chunk.Resource` for a file-like object.

    This object must have the following methods:

    - ``read(num_bytes)`` where ``num_bytes`` is an integer number of bytes to
      read.
    - ``seek(position)`` where ``position`` is an integer position to seek to.

    Both of these methods change the internal state of the object, its current
    seek position (because ``read`` moves that position forward ``num_bytes``).
    Hence, it is in principle not thread-safe.
    c                 C  s
   || _ d S ©N©Ú_obj)ÚselfÚobj© r	   úW/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/uproot/source/object.pyÚ__init__$   s    zObjectResource.__init__c                 C  s   | j S r   r   ©r   r	   r	   r
   r   '   s    zObjectResource.objÚbool)Úreturnc                 C  s   t | jddƒS )NÚclosedF)Úgetattrr   r   r	   r	   r
   r   +   s    zObjectResource.closedc                 C  s   t | jdƒr| j ¡  | S )NÚ	__enter__)Úhasattrr   r   r   r	   r	   r
   r   /   s    
zObjectResource.__enter__c                 C  s    t | jdƒr| j |||¡ d S )NÚ__exit__)r   r   r   )r   Zexception_typeZexception_valueÚ	tracebackr	   r	   r
   r   4   s    zObjectResource.__exit__Úint©ÚstartÚstopc                 C  s   | j  |¡ | j  || ¡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   ÚseekÚread)r   r   r   r	   r	   r
   Úget8   s    	zObjectResource.getzuproot.source.chunk.Source)Úsourcer   r   c                   s   ‡ ‡fdd„}t jj |¡S )aÒ  
        Args:
            source (:doc:`uproot.source.object.ObjectSource`): 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.object.ObjectResource.get` with ``start`` and
        ``stop``.
        c                   s   |   ˆ ˆ¡S r   )r   )Úresourcer   r	   r
   ÚtaskR   s    z#ObjectResource.future.<locals>.task)Úuprootr   ÚfuturesZResourceFuture)r   r   r   r   r	   r   r
   ÚfutureD   s    zObjectResource.futureN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Úpropertyr   r   r   r   r   Ústaticmethodr!   r	   r	   r	   r
   r      s   
r   c                   @  s   e Zd ZdZeZdd„ ZdS )ÚObjectSourceaž  
    Args:
        obj: The file-like object to use.

    A :doc:`uproot.source.chunk.Source` for a file-like object. (Although this
    is a :doc:`uproot.source.chunk.MultithreadedSource`, it never has more or
    less than one thread.)

    This object must have the following methods:

    - ``read(num_bytes)`` where ``num_bytes`` is an integer number of bytes to
      read.
    - ``seek(position)`` where ``position`` is an integer position to seek to.

    Both of these methods change the internal state of the object, its current
    seek position (because ``read`` moves that position forward ``num_bytes``).
    Hence, it is in principle not thread-safe.
    c                 K  sZ   d| _ d| _d| _t|ƒ| _|d r<tjj t	|ƒg¡| _
ntjj t	|ƒ¡| _
d | _d S )Nr   Zuse_threads)Z_num_requestsZ_num_requested_chunksZ_num_requested_bytesÚreprZ
_file_pathr   r   r    ZResourceThreadPoolExecutorr   Z	_executorZResourceTrivialExecutorZ
_num_bytes)r   r   Úoptionsr	   r	   r
   r   n   s    
ÿÿzObjectSource.__init__N)r"   r#   r$   r%   r   ZResourceClassr   r	   r	   r	   r
   r(   X   s   r(   )r%   Ú
__future__r   r   Zuproot.source.chunkZuproot.source.futuresr   ÚchunkÚResourcer   ZMultithreadedSourcer(   r	   r	   r	   r
   Ú<module>   s   F