
    ej&                     h   U d Z ddlZddlZddl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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 G d de          Zd ZdS )z!Dynamic class-creation for Motor.    N)AnyCallableDict_class_cachesync_methodc                      t          j                   fd            }|                     ||          }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                    /fd|D             }fd|                                 D             }n*d |D             }d |                                 D             }|                                 } j        || j        g|R i |S )Nc                 d    g | ],}|j         j                            d f          r|j        n|-S MotorClientSession	__class____name__endswithdelegate).0objunwrap_classs     Y/var/www/app.qaans.com/backend/venv/lib/python3.11/site-packages/motor/metaprogramming.py
<listcomp>z0asynchronize.<locals>.method.<locals>.<listcomp>.   sR         =)22LBV3WXX      c                 l    i | ]0\  }}||j         j                            d f          r|j        n|1S r   r   )r   keyr   r   s      r   
<dictcomp>z0asynchronize.<locals>.method.<locals>.<dictcomp>4   sY           C }-66FZ7[\\CLL	     r   c                 ^    g | ]*}|j         j                            d           r|j        n|+S r   r   r   r   s     r   r   z0asynchronize.<locals>.method.<locals>.<listcomp>>   sH        !$ 6 ? ?@T U U^[^  r   c                 f    i | ].\  }}||j         j                            d           r|j        n|/S r   r   r   r   r   s      r   r   z0asynchronize.<locals>.method.<locals>.<dictcomp>B   sQ           C $'M$:$C$CDX$Y$YbCLL_b     r   )itemsget_io_looprun_on_executorr   )	selfargskwargsunwrapped_argsunwrapped_kwargsloop	frameworkr   r   s	         r   methodzasynchronize.<locals>.method*   s    #     	  N        !'        N    !'	      !!(y(+t}
/=
 
 
AQ
 
 	
r   NT)	functoolswrapspymongo_class_wrapperis_wrap_methodis_async_methodr   pymongo_method_name__doc__)r(   r   doc
wrap_classr   r)   names   ``  `  r   asynchronizer4      s    $ _[!!!
 !
 !
 !
 !
 !
 "!!
F 00DD $ "FD!%F
Mr   c                     d | D             S )Nc              3   f   K   | ],}|j         j                            d           r|j        n|V  -dS )r   Nr   r   s     r   	<genexpr>z&unwrap_args_session.<locals>.<genexpr>_   sV         .778LMMVSV     r    )r#   s    r   unwrap_args_sessionr9   ^   s#        r   c                 >    d |                                  D             S )Nc                 f    i | ].\  }}||j         j                            d           r|j        n|/S r   r   r   s      r   r   z)unwrap_kwargs_session.<locals>.<dictcomp>f   sN       C 	cm4==>RSS\cllY\  r   )r   )r$   s    r   unwrap_kwargs_sessionr<   e   s+        r   c                     d| _         | S )zlIn docs, annotate a function that returns a Future with 'coroutine'.

    This doesn't affect behavior.
    T)coroutine_annotation)fs    r   r>   r>   o   s     "AHr   c                        e Zd ZdZddZd ZdS )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                     || _         d S N)r1   r"   r1   s     r   __init__zMotorAttributeFactory.__init__   s    r   c                     t           rC   )NotImplementedError)r"   cls	attr_names      r   create_attributez&MotorAttributeFactory.create_attribute   s    !!r   rC   )r   
__module____qualname__r0   rE   rJ   r8   r   r   rA   rA   |   sA         
   " " " " "r   rA   c                   2     e Zd Zd fd	Zd Zd Zd Z xZS )AsyncNc                 t    t                                          |           || _        d| _        d| _        dS )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)superrE   rI   r2   r   )r"   rI   r1   r   s      r   rE   zAsync.__init__   s9     	" r   c                     | j         p|}t          |j        |          }t          |j        || j        | j        | j                  S )N)r(   r   r1   r2   r   )rI   getattr__delegate_class__r4   
_frameworkr1   r2   r   )r"   rH   rI   r3   r)   s        r   rJ   zAsync.create_attribute   sO    ~*/66n*
 
 
 	
r   c                     || _         | S rC   r2   r"   original_classs     r   wrapz
Async.wrap       (r   c                     || _         | S rC   )r   )r"   
class_names     r   unwrapzAsync.unwrap   s    &r   rC   )r   rK   rL   rE   rJ   rY   r]   __classcell__)r   s   @r   rN   rN      sj        ! ! ! ! ! !	
 	
 	
        r   rN   c                       e Zd ZddZdS )	AsyncReadNc                 @    t                               | ||           dS )zeA descriptor that wraps a PyMongo read method like find_one() that
        returns a Future.
        rI   r1   NrN   rE   r"   rI   r1   s      r   rE   zAsyncRead.__init__   "     	tyc:::::r   NNr   rK   rL   rE   r8   r   r   r`   r`      (        ; ; ; ; ; ;r   r`   c                       e Zd ZddZdS )
AsyncWriteNc                 @    t                               | ||           dS )zA descriptor that wraps a PyMongo write method like update_one() that
        accepts getLastError options and returns a Future.
        rb   Nrc   rd   s      r   rE   zAsyncWrite.__init__   re   r   rf   rg   r8   r   r   rj   rj      rh   r   rj   c                       e Zd ZddZdS )AsyncCommandNc                 @    t                               | ||           dS )zA descriptor that wraps a PyMongo command like copy_database() that
        returns a Future and does not accept getLastError options.
        rb   Nrc   rd   s      r   rE   zAsyncCommand.__init__   re   r   rf   rg   r8   r   r   rm   rm      rh   r   rm   c                       e Zd ZdZd ZdS )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                 .    t          | j                  S rC   )rR   r   )r   rI   s    r   fgetz/ReadOnlyProperty.create_attribute.<locals>.fget   s    3<333r   )rs   r1   )rs   )r1   rR   rS   r0   property)r"   rH   rI   rs   r1   s     `  r   rJ   z!ReadOnlyProperty.create_attribute   ss    	4 	4 	4 	4 	4 8 	E(CC#0)<<DC 	'3////&&&&r   N)r   rK   rL   r0   rJ   r8   r   r   rp   rp      s)        EE' ' ' ' 'r   rp   c                   &    e Zd ZdZddZd Zd ZdS )DelegateMethodz[A method on the wrapped PyMongo object that does no I/O and can be called
    synchronouslyNc                 J    t                               | |           d | _        d S rC   )rp   rE   r2   rD   s     r   rE   zDelegateMethod.__init__   s#    !!$,,,r   c                     || _         | S rC   rV   rW   s     r   rY   zDelegateMethod.wrap   rZ   r   c                     | j         t                              | ||          S t          |j        |          | j         t          j                  fd            }| j        r| j        |_        d|_	        |S )Nc                 j     | j         g|R i |}|j        k    r|                     |          S |S rC   )r   r   rY   )self_r#   r$   resultr)   rX   s       r   wrapperz0DelegateMethod.create_attribute.<locals>.wrapper   sK    VEN<T<<<V<<F >11zz&)))r   T)
r2   rp   rJ   rR   rS   r*   r+   r1   r0   r-   )r"   rH   rI   r}   r)   rX   s       @@r   rJ   zDelegateMethod.create_attribute   s    ?"#44T3	JJJ/;;		 	 	 	 	 	 	 
!	 	 8 	'"hGO!%r   rC   )r   rK   rL   r0   rE   rY   rJ   r8   r   r   rv   rv      sP                  r   rv   c                       e Zd Zd ZdS )MotorCursorChainingMethodc                     t          |j        |          t          j                  fd            }d|_        ||_        | j        r| j        |_        |S )Nc                 *     | j         g|R i | | S rC   )r   )r"   r#   r$   cursor_methods      r   return_clonez@MotorCursorChainingMethod.create_attribute.<locals>.return_clone   s*    M$-9$999&999Kr   T)rR   rS   r*   r+   is_motorcursor_chaining_methodr/   r1   r0   )r"   rH   rI   r   r   s       @r   rJ   z*MotorCursorChainingMethod.create_attribute   so     6	BB		'	'	 	 	 	 
(	'	
 7;3+4(8 	,#'8L r   N)r   rK   rL   rJ   r8   r   r   r   r      s#            r   r   c                    |j         | j        z   }| ||f}t                              |          }|r|S t	          t          |          | fi           }||_        ||_        t          |d          sJ t          t          j        |                     D ]]}|j                                        D ]A\  }}	t          |	t                    r'|	                    ||          }
t#          |||
           B^|t          |<   |S )NrS   )CLASS_PREFIX__motor_class_name__r   gettypestrrK   rT   hasattrreversedinspectgetmro__dict__r   
isinstancerA   rJ   setattr)rH   r(   module_namemotor_class_name	cache_keycached_class	new_classbaser3   attrnew_class_attrs              r   create_class_with_frameworkr     s    -0HH&	2I##I..L S)**SFB77I&I$I9233333 ,,-- 9 9---// 	9 	9JD$$ 566 9!%!6!6y$!G!G	4888	9
 (Lr   )NNN)r0   r*   r   typingr   r   r   r   __annotations__r4   r9   r<   object_coro_tokenr>   rA   rN   r`   rj   rm   rp   rv   r   r   r8   r   r   <module>r      s+   ( ' '      & & & & & & & & & &!d38n ! ! !C C C C C CL     fhh
 
 

" 
" 
" 
" 
"F 
" 
" 
"    !   D; ; ; ; ; ; ; ;; ; ; ; ; ; ; ;; ; ; ; ;5 ; ; ;' ' ' ' ', ' ' '$" " " " "% " " "J     5   $    r   