o
    f}                     @  s   d Z ddlmZ ddlZddlZddlmZ 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dlmZmZ G dd deZG dd deeZG dd deZG dd deZg dZdS )u  
A rough layout of the current storage goes as:

virtualenv-app-data
├── py - <version> <cache information about python interpreters>
│  └── *.json/lock
├── wheel <cache wheels used for seeding>
│   ├── house
│   │   └── *.whl <wheels downloaded go here>
│   └── <python major.minor> -> 3.9
│       ├── img-<version>
│       │   └── image
│       │           └── <install class> -> CopyPipInstall / SymlinkPipInstall
│       │               └── <wheel name> -> pip-20.1.1-py2.py3-none-any
│       └── embed
│           └── 3 -> json format versioning
│               └── *.json -> for every distribution contains data about newer embed versions and releases
└─── unzip <in zip app we cannot refer to some internal files, so first extract them>
     └── <virtualenv version>
         ├── py_info.py
         ├── debug.py
         └── _virtualenv.py
    )annotationsN)ABC)contextmanagersuppress)sha256)ReentrantFileLock)safe_delete)extract)__version__   )AppDataContentStorec                   @  s   e Zd ZdZdZdZd"ddZd#d	d
Zd#ddZdd Z	dd Z
edd Zedd Zedd Zdd Zdd Zdd Zedd Zdd  Zd!S )$AppDataDiskFolderz>Store the application data on the disk within a folder layout.FTreturnNonec                 C  s   t || _d S N)r   lock)selffolder r   Y/var/www/html/dev/env/lib/python3.10/site-packages/virtualenv/app_data/via_disk_folder.py__init__/   s   zAppDataDiskFolder.__init__strc                 C  s   t | j d| jj dS )N())type__name__r   pathr   r   r   r   __repr__2   s   zAppDataDiskFolder.__repr__c                 C  s   t | jjS r   )r   r   r   r   r   r   r   __str__5      zAppDataDiskFolder.__str__c                 C  s    t d| jj t| jj d S )Nzreset app data folder %s)loggingdebugr   r   r   r   r   r   r   reset8   s   zAppDataDiskFolder.resetc                 C  s   dS )zDo nothing.Nr   r   r   r   r   close<   s    zAppDataDiskFolder.closec                 c  s>    | j | }| |jV  W d    d S 1 sw   Y  d S r   r   r   )r   r   	path_lockr   r   r   locked?   s
   

"zAppDataDiskFolder.lockedc                 c  sx    |d ur
t | n| jd t }||j |j|j }| s't|| |V  W d    d S 1 s5w   Y  d S )Nunzip)r   r   r
   lock_for_keynamer   existsr	   )r   r   	to_folderrootdestr   r   r   r	   E   s    
"zAppDataDiskFolder.extractc                 C  s   | j d d S )Npy_info1)r   r   r   r   r   
py_info_atN   s   zAppDataDiskFolder.py_info_atc                 C  s   t | j|S r   )PyInfoStoreDiskr2   r   r   r   r   r   r0   R   r!   zAppDataDiskFolder.py_infoc              
   C  s   | j }|4 |j D ]%}|jdkr0||j | r!|  W d   n1 s+w   Y  qW d   dS 1 s<w   Y  dS )zclear py info..jsonN)r2   r   iterdirsuffixr*   stemr,   unlink)r   py_info_folderfilenamer   r   r   py_info_clearU   s   
"zAppDataDiskFolder.py_info_clearc                 C  s   t | jd | d d |S )Nwheelembed3) EmbedDistributionUpdateStoreDiskr   )r   distributionfor_py_versionr   r   r   embed_update_log_      z"AppDataDiskFolder.embed_update_logc                 C  s"   | j jd d }|jddd |S )Nr=   houseTparentsexist_ok)r   r   mkdirr4   r   r   r   rE   b   s   zAppDataDiskFolder.housec                 C  s   | j jd | d d | S )Nr=   imager1   r&   )r   rB   r+   r   r   r   wheel_imageh   rD   zAppDataDiskFolder.wheel_imageNr   r   )r   r   )r   
__module____qualname____doc__	transient
can_updater   r   r    r$   r%   r   r(   r	   propertyr2   r0   r<   rC   rE   rK   r   r   r   r   r   )   s*    







r   c                   @  sN   e Zd ZdddZedd Zdd Zd	d
 Zdd Ze	dd Z
dd ZdS )JSONStoreDiskr   r   c                 C  s(   || _ || _|| _g || jR | _d S r   )	in_folderkeymsgfilemsg_args)r   rT   rU   rV   rX   r   r   r   r   m   s   zJSONStoreDisk.__init__c                 C  s   | j j| j d S )Nr5   )rT   r   rU   r   r   r   r   rW   s   s   zJSONStoreDisk.filec                 C  s
   | j  S r   )rW   r,   r   r   r   r   r,   w   s   
zJSONStoreDisk.existsc                 C  s   d\}}zt | jjdd}W n ty   d}Y n ty#   Y nw td| j| j	 |S |rJt
t |   W d    d S 1 sEw   Y  d S )N)NFutf-8encodingTzgot %s from %s)jsonloadsrW   	read_text
ValueError	Exceptionr"   r#   rV   rX   r   OSErrorremove)r   data
bad_formatr   r   r   readz   s"   


zJSONStoreDisk.readc                 C  s    | j   td| j| j d S )Nzremoved %s at %s)rW   r9   r"   r#   rV   rX   r   r   r   r   rb      s   
zJSONStoreDisk.removec                 c  s<    | j | j d V  W d    d S 1 sw   Y  d S r   )rT   r*   rU   r   r   r   r   r(      s   "zJSONStoreDisk.lockedc                 C  sH   | j j}|jddd | j jtj|ddddd td| j| j	 d S )NTrF      )	sort_keysindentrY   rZ   zwrote %s at %s)
rW   parentrI   
write_textr\   dumpsr"   r#   rV   rX   )r   contentr   r   r   r   write   s   zJSONStoreDisk.writeNrL   )r   rM   rN   r   rR   rW   r,   re   rb   r   r(   rm   r   r   r   r   rS   l   s    


rS   c                         e Zd Zd fddZ  ZS )r3   r   r   c                   s.   t t|d }t ||d|f d S )NrY   zpython info of %s)r   r   encode	hexdigestsuperr   )r   rT   r   rU   	__class__r   r   r      s   zPyInfoStoreDisk.__init__rL   r   rM   rN   r   __classcell__r   r   rr   r   r3          r3   c                      rn   )r@   r   r   c                   s   t  ||d|f d S )Nzembed update of distribution %s)rq   r   )r   rT   rA   rr   r   r   r      s   z)EmbedDistributionUpdateStoreDisk.__init__rL   rt   r   r   rr   r   r@      rv   r@   )r   rS   r3   )rO   
__future__r   r\   r"   abcr   
contextlibr   r   hashlibr   virtualenv.util.lockr   virtualenv.util.pathr   virtualenv.util.zipappr	   virtualenv.versionr
   baser   r   r   rS   r3   r@   __all__r   r   r   r   <module>   s"    C.
