
    hi'                        d dl Z d dlZd dlZd dlZd dlmZ d dlmZ d dlZej	        
                    ej	                            e          d          Zd Zedk    rh eej                  dk    rTej        d         d	k    rCej        d
         dk    Z ej        eez  d           d Z ee            ej                     d dlZd dlZd dlmZ d dlmc mZ d dlZd dl m!a!m"Z"m#Z# d dl$m%Z& da'da(g da)d Z*d Z+ G d d          a,tY          tR          d          tN                    a- G d dtB                    a.t]                      a/ea0 G d d          Z1d Z2 e j3        e2e           d Z4d Z5d Z6d Z7d  Z8d! Z9edk    rB e5d"#            e5d$#            e6              e7              e8              e9             dS dS )%    N)suppress)BytesIOzsession-refimported-%s.pklc                     dd l }|                                                                d                             ddt	          |          z   dz             }d|d|                                S )Nr   z[obj][]z while testing (with refimported=z):  )	traceback
format_exc
splitlinesreplacereprlstrip)errorobjrefimportedr	   lines        o/var/www/development/aibuddy-work/election-extract/venv/lib/python3.11/site-packages/dill/tests/test_session.py_error_liner      sk    !!,,..r2::7CS		MRUDUVVDD9DdkkmmmTT    __main__      --child   Truemodulec                    	 dD ])}t                      |         j        t          j        v sJ *dt          j        v rdt          j        v sJ dd l}dd l}dD ]5}t                      |         t          j        d         j        |         u sJ 6t          j        j	        dk    sJ | rt          j        |j        u sJ t          j
        |j        u sJ d S # t          $ r}t          |||           f|_         d }~ww xY w)Njsonurl	local_modsaxdomcalendarcmathr   )Calendarisleap)globals__name__sysmodulesr%   r&   __dict__r   day_name
__module__complex_loglogAssertionErrorr   args)r   r   r%   r&   r   s        r   test_modulesr4   !   s4   	A > >yy~.#+=====,,CK1G1G1G1G""""""""- O Oyy~Z)@)I#)NNNNNN$/:==== >(H,====='59444444 	 	 	%eS+>>@EJ	s   CC 
C8C33C8)r#   )r'   r(   r.   )r1      )AliceBobCarolc                     | dz  S )Nr    xs    r   squaredr=   R   s
    q!tr   c                     | dz  S )Nr   r:   r;   s    r   <lambda>r?   S   s
    !Q$ r   c                       e Zd Zd ZdS )Personc                 "    || _         || _        d S N)nameage)selfrD   rE   s      r   __init__zPerson.__init__U   s    	r   N)r*   r/   __qualname__rG   r:   r   r   rA   rA   T   s#            r   rA   c                       e Zd Zd ZdS )CalendarSubclassc                 >    d |                                  D             S )Nc                 (    g | ]}t           |         S r:   )r.   ).0is     r   
<listcomp>z-CalendarSubclass.weekdays.<locals>.<listcomp>[   s    999999r   )iterweekdaysrF   s    r   weekdayszCalendarSubclass.weekdaysZ   s"    99T%6%6%8%89999r   N)r*   r/   rH   rR   r:   r   r   rJ   rJ   Y   s#        : : : : :r   rJ   c                   X    e Zd Z e                                            Zd Zd Zd ZdS )TestNamespacec                     || _         d S rC   )extra)rF   rV   s     r   rG   zTestNamespace.__init__b   s    


r   c                 (   t                                                      | _        t                                                       t                                          | j                   t                                          | j                   | S rC   )r)   copybackupclearupdatetest_globalsrV   rQ   s    r   	__enter__zTestNamespace.__enter__d   se    iinn&&				*+++		$$$r   c                     t                                                       t                                          | j                   d S rC   )r)   rZ   r[   rY   )rF   exc_infos     r   __exit__zTestNamespace.__exit__j   s6    				%%%%%r   N)	r*   r/   rH   r)   rX   r\   rG   r]   r`   r:   r   r   rT   rT   `   sV        799>>##L    & & & & &r   rT   c                    | j                             dd          d         dz   }t          | d          r| j        n|}t          j                            t          j                            | j                   d          }t          j        |ft          j	        |ffD ]<\  }}t          t                    5   ||           d d d            n# 1 swxY w Y   =d S )N.r   r   z.pyc
__cached____pycache__)__file__splithasattrrc   ospathjoindirnameremove
removedirsr   OSError)r   cachedpycacherl   files        r   _clean_up_cacherr   n   s   _""3**1-6F")&,"?"?KVVFgll27??6?;;]KKG)V,r}g.FG  g 	 	F4LLL	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 s   5CC	C	c                 $   	 t           j        }dD ],}t                      |         j        ||         j        k    sJ -dD ]}||         ||         k    sJ dD ]9}||         j        |u sJ  ||         d           ||         d          k    sJ :t
          j        t           j        k    sJ t          t          t
                    sJ t          j	        |d         j	        k    sJ t          t          t                    sJ t          t          t                    sJ t                                          |d                                         k    sJ t          t           u sJ d S # t           $ r}t#          |||          f|_         d }~ww xY w)Nr   )r<   emptynames)r=   cubedr   personcal)r   r-   r)   r*   __globals__rA   r/   
isinstancerw   rE   
issubclassrJ   r'   rx   rR   selfrefr2   r   r3   )mainglobals_copyr   	main_dictr   r   s         r   _test_objectsr   x   s   %	 > 	I 	IC99S>*l3.?.HHHHHH* 	7 	7CS>\#%666666' 	= 	=CS>-::::!9S>!$$(9S(9!(<(<<<<<< H$55555&&)))))z\(377777*H55555#/00000||~~e!4!=!=!?!?????(""""""   !%k::<
s   E$E( (
F2F

Fc           	      T   i }| rddl m} ||d<   t          di |5 }	 t          j        t
          | z  |            ddlm}m}m	} |
                    |t          dt          |           g|          }|rt          j        |           t          t                    5  t!          j        t
          | z             ddd           n# 1 swxY w Y   nM# t          t                    5  t!          j        t
          | z             ddd           w # 1 swxY w Y   w xY wt%                      }t          j        ||            |                    d           t          j        |d	
            |j        d         t,          |j        |            ddd           dS # 1 swxY w Y   dS )zNtest dump/load_module() for __main__, both in this process and in a subprocessr   )flagsr   r   )pythonshellspr   )r   Nr   r   r   r:   )r+   r   rT   dilldump_modulesession_filedill.tests.__main__r   r   r   callre   strexitr   rn   rh   rl   r   seekload_modulerY   r   )	r   extra_objectsr   nsr   r   r   r   session_buffers	            r   test_session_mainr      s   M '!&g		'	'	'	' E2	6\K7[QQQQ==========GGVXy#k:J:JKSXGYYE%chuooo'"" 6 6	,45556 6 6 6 6 6 6 6 6 6 6 6 6 6 6'"" 6 6	,45556 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 ![AAAAA
;;;;"	/"8RYDDD!E E E E E E E E E E E E E E E E E Esr   FA+C	FC:FC
	
FC
	FD'D	DDDDDA4FF!$F!c                     ddl t          j        t                     _        d j                                        D             } t                      }t          j	        |           | D ]
}j        |= |
                    d           t          j        |           t          fd| D                       sJ j        u sJ dS )z8test dump/load_module() for a module other than __main__r   Nc                 <    g | ]}|                     d           |S )__)
startswith)rM   r   s     r   rO   z&test_session_other.<locals>.<listcomp>   s*    VVVCPTAUAUVCVVVr   c              3   *   K   | ]}|j         v V  d S rC   )r-   )rM   r   r   s     r   	<genexpr>z%test_session_other.<locals>.<genexpr>   s*      >>#sfo%>>>>>>r   )test_classdefatexitregisterrr   r|   r-   keysr   r   r   r   r   all)dict_objectsr   r   r   s      @r   test_session_otherr      s    """"
OOV,,,FNVV6?#7#7#9#9VVVLYYN^V,,, ! !OC  ^V,,,>>>>>>>>>>>>>V######r   c                     ddl m}  d} | |          }d|_        t          j                            |          }||ur-t          d|j        |j        |j	        t          j                   t                      }t          j        ||d           |                                } | |          }t          j        t          |          |	          }|J |j        |k    sJ |j        dk    sJ |t          j                                        vsJ |                    d           t          j        t          |                    }|j        |k    sJ |j        dk    sJ |t          j                                        vsJ d S )
Nr   )
ModuleType__runtime__*   z:There are objects to save by referenece that shouldn't be:)rq   T)r   r   r   )typesr   r<   r   session_stash_modulesprint__dill_imported__dill_imported_as__dill_imported_top_levelr+   stderrr   r   getvaluer   r*   r,   valuesr   )r   modnameruntimemodr   session_dump
return_vals          r   test_runtime_moduler      s         Gj!!GGI
,
%
%g
.
.C
'J!3#93;X:	 	 	 	 YYN^GFFFF!**,,L j!!G!',"7"7HHHJw&&&&9????#+,,...... w|4455Gw&&&&9????#+,,........r   c                     dd l } dd l}dd l}dd l}|                    d          x}t
          j        d<   |j                            d          t          _
        | j        |_        |j        |_        t          j
        |_        t!                      }t          j        ||d           |                    d           t          j        |          }t
          j        d= t)          |j                  h dk    sJ d S )Nr   __test__r   )max_workersTr   >   r   executorthread_exectypingAsyncContextManagerAsyncCMcollectionsUserDictDict)r   concurrent.futuresr   r   r   r+   r,   futuresThreadPoolExecutorr   r   r   r   r   r   r   r   r   r   loadsetr   )r   
concurrentr   r   r   r   s         r   test_refimported_imported_asr      s   LLLMMM$)$4$4Z$@$@@C#+j
!&99a9HHDM#CH,CKmCOYYN^Sd;;;;
)N
#
#CJs%&& + + +      r   c                  $   t                      5  t                      } t          j        |            dxaabt                                                      }| 	                    d           t          j
        |           }|t                      usJ t                      |k    sJ |d         dk    sJ |d         t          k    sJ |d         t          usJ |d         t          k    sJ d|vsJ d|v sJ 	 d d d            d S # 1 swxY w Y   d S )Nr   r*   r   ru   r<   yrt   )rT   r   r   r   r<   r   rt   r)   rX   r   load_module_asdictru   )r   globals_state	main_varss      r   test_load_module_asdictr      su   	 $ $ ((( 	A		((A+N;;			))))yyM))))$
2222!U****!....~"""")####)#####)$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $s   C(DD	D	Fr   T):r   rh   r+   r   
contextlibr   ior   r   ri   rj   rk   re   r   r   r*   lenargvr   r   r4   r   r    urllibr!   xmlr#   xml.dom.minidomr$   minidomtest_dictviewsr"   r%   r'   r(   r.   r&   r1   r0   r<   rt   ru   r=   rv   rA   rw   rJ   rx   r|   rT   rr   r   r   r   r   r   r   r   r:   r   r   <module>r      sf    				 



              w||BGOOH557STTU U U
 zcc#(mmq00SXa[I5M5M8A;&(KD\K/
CCCC  2 LCHJJJ                     " " " " 0 / / / / / / / / / $ $ $ $ $ $ !!!           
a!		: : : : :x : : : 
& & & & & & & &    + + +  :E E E4$ $ $& /  /  /D  .$ $ $. z%(((($''''  """ r   