
     i                     F    d Z ddlmZmZmZmZ ddlZ G d de          ZdS )z
future_mrcfile
--------------

Module which exports the :class:`FutureMrcFile` class.

Classes:
    :class:`FutureMrcFile`: An object which represents an MRC file being
        opened asynchronously.

    )absolute_importdivisionprint_functionunicode_literalsNc                   X    e Zd ZdZdi fdZd Zd Zd Zd Zd Z	dd
Z
ddZd Zd Zd	S )FutureMrcFilea%  Object representing an MRC file being opened asynchronously.

    This API deliberately mimics a :class:`~concurrent.futures.Future` object
    from the :mod:`concurrent.futures` module in Python 3.2+ (which we do
    not use directly because this code still needs to run in Python 2.7).

     c                     dg| _         || _        t          j        | j        ||          | _        | j                                         dS )a  Initialise a new :class:`FutureMrcFile` object.

        This constructor starts a new thread which will invoke the callable
        given in ``open_function`` with the given arguments.

        Args:
            open_function: The callable to use to open the MRC file. (This will
                normally be :func:`mrcfile.open`, but could also be
                :class:`~mrcfile.mrcfile.MrcFile` or any of its subclasses.)
            args: A tuple of positional arguments to use when ``open_function``
                is called. (Normally a 1-tuple containing the name of the file
                to open.)
            kwargs: A dictionary of keyword arguments to use when
                ``open_function`` is called.
        N)targetargskwargs)_result_holder_open_function	threadingThread_run_threadstart)selfopen_functionr   r   s       `/srv/www/vhosts/g4struct/public_html/venv/lib/python3.11/site-packages/mrcfile/future_mrcfile.py__init__zFutureMrcFile.__init__    sU       $f+ 'ty-1/57 7 7 	    c                 z    	  | j         |i |}|| j        d<   dS # t          $ r}|| j        d<   Y d}~dS d}~ww xY w)zjCall the open function and store the result in the holder list.

        (For internal use only.)
        r   N)r   r   	Exception)r   r   r   mrcexs        r   r   zFutureMrcFile._run7   so    
	(%$%t6v66C%(D""" 	( 	( 	(%'D"""""""	(s    
:
5:c                     dS )zReturn :data:`False`.

        (See :meth:`concurrent.futures.Future.cancel` for more details. This
        implementation does not allow jobs to be cancelled.)
        Fr	   r   s    r   cancelzFutureMrcFile.cancelB   	     ur   c                     dS )zReturn :data:`False`.

        (See :meth:`concurrent.futures.Future.cancelled` for more details.
        This implementation does not allow jobs to be cancelled.)
        Fr	   r   s    r   	cancelledzFutureMrcFile.cancelledJ   r!   r   c                 4    | j                                         S )zReturn :data:`True` if the :class:`~mrcfile.mrcfile.MrcFile` is
        currently being opened.

        (See :meth:`concurrent.futures.Future.running` for more details.)
        )r   is_aliver   s    r   runningzFutureMrcFile.runningR   s     |$$&&&r   c                 ,    |                                   S )zReturn :data:`True` if the file opening has finished.

        (See :meth:`concurrent.futures.Future.done` for more details.)
        )r&   r   s    r   donezFutureMrcFile.doneZ   s    
 <<>>!!r   Nc                 ^    |                      |          }t          |t                    r||S )a  Return the :class:`~mrcfile.mrcfile.MrcFile` that has been opened.

        (See :meth:`concurrent.futures.Future.result` for more details.)

        Args:
            timeout: Time to wait (in seconds) for the file opening to finish.
                If ``timeout`` is not specified or is :data:`None`, there is no
                limit to the wait time.

        Returns:
            An :class:`~mrcfile.mrcfile.MrcFile` object (or one of its
            subclasses).

        Raises:
            :exc:`RuntimeError`: If the operation has not finished within the
                 time limit set by ``timeout``. (Note that the type of this
                 exception will change in future if this class is replaced by
                 :class:`concurrent.futures.Future`.)
            :exc:`Exception`: Any exception raised by the
                :class:`~mrcfile.mrcfile.MrcFile` opening operation will be
                re-raised here.
        _get_result
isinstancer   r   timeoutresults      r   r/   zFutureMrcFile.resulta   s3    . !!'**fi(( 	LMr   c                 ^    |                      |          }t          |t                    r|S dS )a+  Return the exception raised by the file opening operation.

        (See :meth:`concurrent.futures.Future.exception` for more details.)

        Args:
            timeout: Time to wait (in seconds) for the operation to finish. If
                ``timeout`` is not specified or is :data:`None`, there is no
                limit to the wait time.

        Returns:
            An :exc:`Exception`, if one was raised by the file opening
            operation, or :data:`None` if no exception was raised.

        Raises:
            :exc:`RuntimeError`: If the operation has not finished within the
                time limit set by ``timeout``. (Note that the type of this
                exception will change in future if this class is replaced by
                :class:`concurrent.futures.Future`.)
        Nr*   r-   s      r   	exceptionzFutureMrcFile.exception~   s3    ( !!'**fi(( 	M4r   c                     | j                             |           | j                                         rt          d          | j        d         S )zjReturn the result or exception from the file opening operation.

        (For internal use only.)
        )r.   zTimed out waiting for resultr   )r   joinr%   RuntimeErrorr   )r   r.   s     r   r+   zFutureMrcFile._get_result   sP    
 	'***<  "" 	?=>>>"1%%r   c                     t           )znNot implemented.

        (See :meth:`concurrent.futures.Future.add_done_callback` for more details.)
        )NotImplementedError)r   fns     r   add_done_callbackzFutureMrcFile.add_done_callback   s
    
 "!r   )N)__name__
__module____qualname____doc__r   r   r    r#   r&   r(   r/   r1   r+   r8   r	   r   r   r   r      s          ,.b    .	( 	( 	(    ' ' '" " "   :   4& & &" " " " "r   r   )	r<   
__future__r   r   r   r   r   objectr   r	   r   r   <module>r?      s   
 
* * * * * * * * * * * *    P" P" P" P" P"F P" P" P" P" P"r   