
    -it                         d dl mZmZ d dlmZ d dlmZ d dlmZ d dl	m
Z
 d dlmZ ded<   eed	<    G d
 de          Z G d dee          ZdS )    )FunctionType
MethodType)RLockwraps)Database)th_safe_gen)cdb_environmentthreadsmode	rlock_objc                   *    e Zd Zed             Zd ZdS )	SuperLockc                 <     t                      fd            }|S )Nc                  j    | d         }|j         5   | i |}|cd d d            S # 1 swxY w Y   d S )Nr   )
super_lock)argskwargsdbresfs       e/var/www/html/speakWrite/venv/lib/python3.11/site-packages/codernitydb3/database_super_thread_safe.py_innerz!SuperLock.wrapper.<locals>._inner"   s    aB  a(((                  s   
(,,r   )r   r   s   ` r   wrapperzSuperLock.wrapper    s3    	q	 	 	 	 
	     c                    i }|D ]q}t          |          D ]_}t          ||d           }t          |t                    r7|                    d          s"|dv rBt
                              |          ||<   `r|                                D ]N\  }}	t          |	t                    r/|                    d          st
                              |	          }	|	||<   Ot                      |d<   t                              | |||          S )N_)flushflush_indexesr   )dirgetattr
isinstancer   
startswithr   r   itemsr   r   type__new__)
cls	classnamebasesattrnew_attrbaseb_attra	attr_name
attr_values
             r   r&   zSuperLock.__new__/   s*    	@ 	@Dd)) @ @D&$//a,, @V5F5Fs5K5K @!;;; ,5+<+<Q+?+?(@ &*ZZ\\ 	- 	-!Iz*&( ( ;090D0DS0I0I;&..z::
",HY!&||CE8<<<r   N)__name__
__module____qualname__staticmethodr   r&    r   r   r   r      s<          \= = = = =r   r   c                   J     e Zd ZdZeZd Z fdZ fdZ fdZ	 fdZ
 xZS )SuperThreadSafeDatabasea  
    Thread safe version that always allows single thread to use db.
    It adds the same lock for all methods, so only one operation can be
    performed in given time. Completely different implementation
    than ThreadSafe version (without super word)
    c                     | j         |         }dD ]j}t          ||          }t          ||dz   d           r d S t          j        |||| j                  }t          |||           t          ||dz   |           kd S )N)allget_many_orig)indexes_namesr!   r	   r   r   setattr)selfnameindcmm_fixeds         r   __patch_index_gensz*SuperThreadSafeDatabase.__patch_index_gensM   s     &$ 	) 	)AQAsAK.. !)!T1doFFGCG$$$CWa((((	) 	)r   c                      t          t          |           j        |i |}| j                                        D ]\  }}|                     |           |S N)superr7   openr<   r$   *_SuperThreadSafeDatabase__patch_index_gensr>   r   r   r   r?   r   	__class__s         r   rH   zSuperThreadSafeDatabase.openW   sc    7e+T227HHH)//11 	* 	*GD!##D))))
r   c                      t          t          |           j        |i |}| j                                        D ]\  }}|                     |           |c S d S rF   )rG   r7   creater<   r$   rI   rJ   s         r   rM   zSuperThreadSafeDatabase.create]   sn    9e+T2294J6JJ)//11 	 	GD!##D)))JJJ	 	r   c                 r     t          t          |           j        |i |}|                     |           |S rF   )rG   r7   	add_indexrI   r>   r   r   r   rK   s       r   rO   z!SuperThreadSafeDatabase.add_indexc   s>    <e+T22<dMfMM$$$
r   c                 r     t          t          |           j        |i |}|                     |           |S rF   )rG   r7   
edit_indexrI   rP   s       r   rR   z"SuperThreadSafeDatabase.edit_indexh   s>    =e+T22=tNvNN$$$
r   )r1   r2   r3   __doc__r   __metaclass__rI   rH   rM   rO   rR   __classcell__)rK   s   @r   r7   r7   C   s          M) ) )            
        r   r7   )	metaclassN)typesr   r   	threadingr   	functoolsr   codernitydb3.databaser   !codernitydb3.database_safe_sharedr	   codernitydb3.envr
   r%   r   r7   r5   r   r   <module>r]      s   & + * * * * * * *             * * * * * * 9 9 9 9 9 9 , , , , , ,# $ != != != != != != != !=H( ( ( ( (h) ( ( ( ( ( (r   