
    df&                     N   U d Z ddlZddlZddlmZmZmZmZ i Zeeef   e	d<   d defdZ
d Zd Z e       Zd	 Z G d
 d      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z ed      ZdedededefdZy)!z!Dynamic class-creation for Motor.    N)AnyCallableDictTypeVar_class_cachesync_methodc                      t        j                         fd       }| j                  ||      }d|_        d|_        j
                  }||_        |||_        |S )a6  Decorate `sync_method` so it returns a Future.

    The method runs on a thread and resolves the Future when it completes.

    :Parameters:
     - `motor_class`:       Motor class being created, e.g. MotorClient.
     - `framework`:         An asynchronous framework
     - `sync_method`:       Unbound method of pymongo Collection, Database,
                            MongoClient, etc.
     - `doc`:               Optionally override sync_method's docstring
     - `wrap_class`:        Optional PyMongo class, wrap a returned object of
                            this PyMongo class in the equivalent Motor class
     - `unwrap_class`       Optional Motor class name, unwrap an argument with
                            this Motor class name and pass the wrapped PyMongo
                            object instead
    c           	         
|D cg c]7  }|j                   j                  j                  
df      r|j                  n|9 }}|j	                         D ci c];  \  }}||j                   j                  j                  
df      r|j                  n|= }}}n|D cg c]5  }|j                   j                  j                  d      r|j                  n|7 }}|j	                         D ci c]9  \  }}||j                   j                  j                  d      r|j                  n|; }}}| j                         } j                  |	| j                  g|i |S c c}w c c}}w c c}w c c}}w NMotorClientSession)	__class____name__endswithdelegateitemsget_io_looprun_on_executor)selfargskwargsobjunwrapped_argskeyunwrapped_kwargsloop	frameworkr   unwrap_classs           N/home/api-vastappli/venv/lib/python3.12/site-packages/motor/metaprogramming.pymethodzasynchronize.<locals>.method+   s   #  	  ==))22LBV3WX N  !'  C }}--66FZ7[\ LL      !$ 6 6 ? ?@T U[^^N  !'	  C $'MM$:$:$C$CDX$YCLL_bc    !(y((+t}}
/=
AQ
 	
9  s   <E#A E(!:E.0>E3T)	functoolswrapspymongo_class_wrapperis_wrap_methodis_async_methodr   pymongo_method_name__doc__)r   r   doc
wrap_classr   r   names   ``  `  r   asynchronizer*      sq    $ __[!!
 "!
F 00D $ "FD!%F
M    c                     d | D        S )Nc              3      K   | ]7  }|j                   j                  j                  d       r|j                  n| 9 yw)r   N)r   r   r   r   ).0r   s     r   	<genexpr>z&unwrap_args_session.<locals>.<genexpr>`   s:       ..778LMSVVs   =? )r   s    r   unwrap_args_sessionr1   _   s     r+   c                     | j                         D ci c]9  \  }}||j                  j                  j                  d      r|j                  n|; c}}S c c}}w r   )r   r   r   r   r   )r   r   r   s      r   unwrap_kwargs_sessionr3   f   sR     C 	cmm44==>RScllY\\  s   >Ac                     d| _         | S )zlIn docs, annotate a function that returns a Future with 'coroutine'.

    This doesn't affect behavior.
    T)coroutine_annotation)fs    r   r5   r5   p   s     "AHr+   c                       e Zd ZdZddZd Zy)MotorAttributeFactoryzUsed by Motor classes to mark attributes that delegate in some way to
    PyMongo. At module import time, create_class_with_framework calls
    create_attribute() for each attr to create the final class attribute.
    Nc                     || _         y N)r'   r   r'   s     r   __init__zMotorAttributeFactory.__init__   s	    r+   c                     t         r:   )NotImplementedError)r   cls	attr_names      r   create_attributez&MotorAttributeFactory.create_attribute   s    !!r+   r:   )r   
__module____qualname__r&   r<   rA   r0   r+   r   r8   r8   }   s    
"r+   r8   c                   2     e Zd Zd fd	Zd Zd Zd Z xZS )Asyncc                 N    t         |   |       || _        d| _        d| _        y)a/  A descriptor that wraps a PyMongo method, such as insert_one,
        and returns an asynchronous version of the method that returns a Future.

        :Parameters:
         - `attr_name`: The name of the attribute on the PyMongo class, if
           different from attribute on the Motor class
        N)superr<   r@   r(   r   )r   r@   r'   r   s      r   r<   zAsync.__init__   s(     	" r+   c                     | j                   xs |}t        |j                  |      }t        |j                  || j
                  | j                  | j                        S )N)r   r   r'   r(   r   )r@   getattr__delegate_class__r*   
_frameworkr'   r(   r   )r   r?   r@   r)   r   s        r   rA   zAsync.create_attribute   sP    ~~*//6nn**
 	
r+   c                     || _         | S r:   r(   r   original_classs     r   wrapz
Async.wrap       (r+   c                     || _         | S r:   )r   )r   
class_names     r   unwrapzAsync.unwrap   s    &r+   r:   )r   rB   rC   r<   rA   rP   rT   __classcell__)r   s   @r   rE   rE      s    !	
r+   rE   c                       e Zd ZddZy)	AsyncReadNc                 4    t         j                  | ||       y)zeA descriptor that wraps a PyMongo read method like find_one() that
        returns a Future.
        r@   r'   NrE   r<   r   r@   r'   s      r   r<   zAsyncRead.__init__        	tyc:r+   NNr   rB   rC   r<   r0   r+   r   rW   rW          ;r+   rW   c                       e Zd ZddZy)
AsyncWriteNc                 4    t         j                  | ||       y)zA descriptor that wraps a PyMongo write method like update_one() that
        accepts getLastError options and returns a Future.
        rY   NrZ   r[   s      r   r<   zAsyncWrite.__init__   r\   r+   r]   r^   r0   r+   r   ra   ra      r_   r+   ra   c                       e Zd ZddZy)AsyncCommandNc                 4    t         j                  | ||       y)zA descriptor that wraps a PyMongo command like copy_database() that
        returns a Future and does not accept getLastError options.
        rY   NrZ   r[   s      r   r<   zAsyncCommand.__init__   r\   r+   r]   r^   r0   r+   r   rd   rd      r_   r+   rd   c                       e Zd ZdZd Zy)ReadOnlyPropertyz;Creates a readonly attribute on the wrapped PyMongo object.c                     fd}| j                   r| j                   }n t        |j                        j                  }|rt	        ||      S t	        |      S )Nc                 0    t        | j                        S r:   )rI   r   )r   r@   s    r   fgetz/ReadOnlyProperty.create_attribute.<locals>.fget   s    3<<33r+   )rj   r'   )rj   )r'   rI   rJ   r&   property)r   r?   r@   rj   r'   s     `  r   rA   z!ReadOnlyProperty.create_attribute   sM    	4 88((C#00)<DDC3//&&r+   N)r   rB   rC   r&   rA   r0   r+   r   rg   rg      s
    E'r+   rg   c                   $    e Zd ZdZddZd Zd Zy)DelegateMethodz[A method on the wrapped PyMongo object that does no I/O and can be called
    synchronouslyNc                 >    t         j                  | |       d | _        y r:   )rg   r<   r(   r;   s     r   r<   zDelegateMethod.__init__   s    !!$,r+   c                     || _         | S r:   rM   rN   s     r   rP   zDelegateMethod.wrap   rQ   r+   c                    | j                   t        j                  | ||      S t        |j                  |      | j                   t        j                        fd       }| j                  r| j                  |_        d|_	        |S )Nc                 t     | j                   g|i |}|j                  k(  r| j                  |      S |S r:   )r   r   rP   )self_r   r   resultr   rO   s       r   wrapperz0DelegateMethod.create_attribute.<locals>.wrapper   s?    ENN<T<V<F >1zz&))r+   T)
r(   rg   rA   rI   rJ   r    r!   r'   r&   r#   )r   r?   r@   rt   r   rO   s       @@r   rA   zDelegateMethod.create_attribute   sy    ??"#44T3	JJ//;		 	 
!	 88"hhGO!%r+   r:   )r   rB   rC   r&   r<   rP   rA   r0   r+   r   rm   rm      s    r+   rm   c                       e Zd Zd Zy)MotorCursorChainingMethodc                     t        |j                  |      t        j                        fd       }d|_        ||_        | j                  r| j                  |_        |S )Nc                 4     | j                   g|i | | S r:   )r   )r   r   r   cursor_methods      r   return_clonez@MotorCursorChainingMethod.create_attribute.<locals>.return_clone   s    $--9$9&9Kr+   T)rI   rJ   r    r!   is_motorcursor_chaining_methodr%   r'   r&   )r   r?   r@   rz   ry   s       @r   rA   z*MotorCursorChainingMethod.create_attribute   s[     6 6	B		'	 
(	
 7;3+4(88#'88L r+   N)r   rB   rC   rA   r0   r+   r   rv   rv      s    r+   rv   Tr?   r   module_namereturnc                    |j                   | j                  z   }| ||f}t        j                  |      }|r|S t	        t        |      | fi       }||_        ||_        t        |d      sJ t        t        j                  |             D ]T  }|j                  j                         D ]5  \  }}	t        |	t              s|	j!                  ||      }
t#        |||
       7 V |t        |<   |S )NrJ   )CLASS_PREFIX__motor_class_name__r   gettypestrrB   rK   hasattrreversedinspectgetmro__dict__r   
isinstancer8   rA   setattr)r?   r   r}   motor_class_name	cache_keycached_class	new_classbaser)   attrnew_class_attrs              r   create_class_with_frameworkr     s     --0H0HH&	2I##I.LS)*SFB7I&I$I9233 ,- 9----/ 	9JD$$ 56!%!6!6y$!G	48	99 (Lr+   )NNN)r&   r    r   typingr   r   r   r   r   __annotations__r*   r1   r3   object_coro_tokenr5   r8   rE   rW   ra   rd   rg   rm   rv   r|   r   r   r0   r+   r   <module>r      s    (   / /!d38n !
C CL h

" 
"! D; ;; ;;5 ;', '$"% "J 5 $ CLQ 3 S Q r+   