a
    	¼3jr  ã                   @   s„   d dl Z d dlZd dlZd dlZd dlZd dlmZ e ¡ Ze ¡ Z	e ¡ Z
dd„ Zedd„ ƒZe jdd„ ƒZG d	d
„ d
ejƒZdS )é    N)Úimport_fresh_modulec                    s2   t  ¡ ‰t d¡| ƒ‰ t | ¡‡ ‡fdd„ƒ}|S )z;Decorator that ensures a function is only ever called once.Nc                      s.   ˆ ˆ ƒ W  d   ƒ S 1 s 0    Y  d S ©N© r   ©ÚcachedÚlockr   úW/www/server/python_manager/versions/3.9.10/lib/python3.9/test/test_zoneinfo/_support.pyÚinner   s    zcall_once.<locals>.inner)Ú	threadingÚLockÚ	functoolsÚ	lru_cacheÚwraps)Úfr	   r   r   r   Ú	call_once   s
    r   c                  C   s   ddl } tddgd}|| fS )u¸  Retrieve two copies of zoneinfo: pure Python and C accelerated.

    Because this function manipulates the import system in a way that might
    be fragile or do unexpected things if it is run many times, it uses a
    `call_once` decorator to ensure that this is only ever called exactly
    one time â€” in other words, when using this function you will only ever
    get one copy of each module rather than a fresh import each time.
    r   NÚzoneinfoZ	_zoneinfo)Zblocked)r   r   )Zc_moduleZ	py_moduler   r   r   Úget_modules   s    
r   c                 c   sH   t ƒ }tj d|¡}| tjd< dV  ||ur8|tjd< ntj d¡ dS )zäMake sure sys.modules["zoneinfo"] refers to `module`.

    This is necessary because `pickle` will refuse to serialize
    an type calling itself `zoneinfo.ZoneInfo` unless `zoneinfo.ZoneInfo`
    refers to the same object.
    r   N)ÚobjectÚsysÚmodulesÚgetÚpop)ÚmoduleZNOT_PRESENTZold_zoneinfor   r   r   Úset_zoneinfo_module+   s    	
r   c                       s4   e Zd Ze‡ fdd„ƒZejdefdd„ƒZ‡  Z	S )ÚZoneInfoTestBasec                    s   | j j| _tƒ  ¡  d S r   )r   ZZoneInfoÚklassÚsuperÚ
setUpClass)Úcls©Ú	__class__r   r   r   ?   s    
zZoneInfoTestBase.setUpClassTc           	      c   sÖ   dd„ }|¶ |r"|ƒ }d t jd< | jj}zN| j |¡ d V  W |rlt j d¡ | ¡ D ]\}}|t j|< qX| j |¡ n:|r¦t j d¡ | ¡ D ]\}}|t j|< q’| j |¡ 0 W d   ƒ n1 sÈ0    Y  d S )Nc                  S   s>   i } t tjƒD ]*}| dd¡d dkr(qtj |¡| |< q| S )NÚ.é   r   Útzdata)Úlistr   r   Úsplitr   )Útzdata_modulesÚmodnamer   r   r   Úpop_tzdata_modulesF   s    z;ZoneInfoTestBase.tzpath_context.<locals>.pop_tzdata_modulesr#   )r   r   r   ZTZPATHZreset_tzpathr   Úitems)	ÚselfZtzpathZblock_tzdatar   r(   r&   Zold_pathr'   r   r   r   r   Útzpath_contextD   s&    

ûzZoneInfoTestBase.tzpath_context)
Ú__name__Ú
__module__Ú__qualname__Úclassmethodr   Ú
contextlibÚcontextmanagerÚTZPATH_LOCKr+   Ú__classcell__r   r   r   r   r   >   s   r   )r0   r   r   r
   ZunittestZtest.supportr   r   ZOS_ENV_LOCKr2   ZTZPATH_TEST_LOCKr   r   r1   r   ZTestCaser   r   r   r   r   Ú<module>   s   

