o
    LK&hì  ã                   @   s”   d dl Z d dlZddlmZ ddlmZ d dlZd dlmZ d dlm	Z	 d dl
mZ g d¢Zdd
d„Zddd„ZG dd„ deƒZG dd„ deƒZdS )é    Né   )ÚCommand)Ú_cfg_read_utf8_with_fallback)Úlog)ÚDistutilsOptionError)Úconvert_path)Úconfig_fileÚedit_configÚoption_baseÚsetoptÚlocalc                 C   sh   | dkrdS | dkrt j t j tj¡d¡S | dkr/t jdkr!dp"d}t j td	|› d
ƒ¡S t	d| ƒ‚)zGet the filename of the distutils, local, global, or per-user config

    `kind` must be one of "local", "global", or "user"
    r   z	setup.cfgÚglobalzdistutils.cfgÚuserÚposixÚ.Ú z~/zpydistutils.cfgz7config_file() type must be 'local', 'global', or 'user')
ÚosÚpathÚjoinÚdirnameÚ	distutilsÚ__file__ÚnameÚ
expanduserr   Ú
ValueError)ÚkindÚdot© r   úL/var/www/html/venv/lib/python3.10/site-packages/setuptools/command/setopt.pyr      s   
r   Fc           	   	   C   sJ  t  d| ¡ t ¡ }dd„ |_t|| ƒ | ¡ D ]c\}}|du r-t  d|| ¡ | |¡ q| 	|¡s>t  d|| ¡ | 
|¡ | ¡ D ]8\}}|du rjt  d||| ¡ | ||¡ | |¡sit  d|| ¡ | |¡ qBt  d	|||| ¡ | |||¡ qBqt  d
| ¡ |s£t| ddd}| |¡ W d  ƒ dS 1 sœw   Y  dS dS )aY  Edit a configuration file to include `settings`

    `settings` is a dictionary of dictionaries or ``None`` values, keyed by
    command/section name.  A ``None`` value means to delete the entire section,
    while a dictionary lists settings to be changed or deleted in that section.
    A setting of ``None`` means to delete that setting.
    zReading configuration from %sc                 S   s   | S ©Nr   )Ú	optionstrr   r   r   Ú<lambda>(   s    zedit_config.<locals>.<lambda>NzDeleting section [%s] from %szAdding new section [%s] to %szDeleting %s.%s from %sz#Deleting empty [%s] section from %szSetting %s.%s to %r in %sz
Writing %sÚwzutf-8)Úencoding)r   ÚdebugÚconfigparserÚRawConfigParserÚoptionxformr   ÚitemsÚinfoÚremove_sectionÚhas_sectionÚadd_sectionÚremove_optionÚoptionsÚsetÚopenÚwrite)	ÚfilenameÚsettingsÚdry_runÚoptsÚsectionr.   ÚoptionÚvalueÚfr   r   r   r	      s@   




ÿ
€
ÿó"ÿÿr	   c                   @   s0   e Zd ZdZg d¢ZddgZdd„ Zdd„ Zd	S )
r
   z<Abstract base class for commands that mess with config files))úglobal-configÚgz0save options to the site-wide distutils.cfg file)úuser-configÚuz7save options to the current user's pydistutils.cfg file)z	filename=r9   z-configuration file to use (default=setup.cfg)r:   r<   c                 C   s   d | _ d | _d | _d S r   )Úglobal_configÚuser_configr2   ©Úselfr   r   r   Úinitialize_optionsV   s   
zoption_base.initialize_optionsc                 C   sv   g }| j r| tdƒ¡ | jr| tdƒ¡ | jd ur!| | j¡ |s*| tdƒ¡ t|ƒdkr5td|ƒ‚|\| _d S )Nr   r   r   é   z/Must specify only one configuration file option)r>   Úappendr   r?   r2   Úlenr   )rA   Ú	filenamesr   r   r   Úfinalize_options[   s   
ÿzoption_base.finalize_optionsN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úuser_optionsÚboolean_optionsrB   rG   r   r   r   r   r
   H   s    þr
   c                   @   sJ   e Zd ZdZdZg d¢ej Zejdg Zdd„ Zdd	d
„Z	ddd„Z
dS )r   z#Save command-line options to a filez1set an option in setup.cfg or another config file))zcommand=Úczcommand to set an option for)zoption=Úozoption to set)z
set-value=Úszvalue of the option)ÚremoveÚrzremove (unset) the valuerQ   c                 C   s&   t  | ¡ d | _d | _d | _d | _d S r   )r
   rB   Úcommandr7   Ú	set_valuerQ   r@   r   r   r   rB   z   s
   

zsetopt.initialize_optionsÚreturnNc                 C   sF   t  | ¡ | jd u s| jd u rtdƒ‚| jd u r| js!tdƒ‚d S d S )Nz%Must specify --command *and* --optionz$Must specify --set-value or --remove)r
   rG   rS   r7   r   rT   rQ   r@   r   r   r   rG      s   
ÿzsetopt.finalize_optionsc                 C   s*   t | j| j| j dd¡| jii| jƒ d S )Nú-Ú_)r	   r2   rS   r7   ÚreplacerT   r4   r@   r   r   r   Úrunˆ   s
   ýz
setopt.run)rU   N)rH   rI   rJ   rK   Údescriptionr
   rL   rM   rB   rG   rY   r   r   r   r   r   l   s    û
r   )r   )F)r%   r   r   r   Úunicode_utilsr   r   r   Údistutils.errorsr   Údistutils.utilr   Ú__all__r   r	   r
   r   r   r   r   r   Ú<module>   s    

*$