
Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­
<!DOCTYPE html>
<html>
3
ÝPfá(  ã               @   sÚ   d Z ddlmZ 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	 ddl
mZ ddlmZ ddlmZmZmZmZ ddlmZmZ ejd	ejƒZG d
d„ dejƒZG dd„ deƒZG dd„ dejƒZG dd„ deƒZdS )zBase option parser setupé    )Úabsolute_importN)Ú	strtobool)Ústring_types)Úconfigparser)Úlegacy_config_fileÚconfig_basenameÚrunning_under_virtualenvÚsite_config_files)ÚappdirsÚget_terminal_sizez^PIP_c               @   sR   e Zd ZdZdd„ Zdd„ Zddd	„Zd
d„ Zdd„ Zdd„ Z	dd„ Z
dd„ ZdS )ÚPrettyHelpFormatterz4A prettier/less verbose help formatter for optparse.c             O   s:   d|d< d|d< t ƒ d d |d< tjj| f|ž|Ž d S )Né   Zmax_help_positioné   Zindent_incrementr   é   Úwidth)r   ÚoptparseÚIndentedHelpFormatterÚ__init__)ÚselfÚargsÚkwargs© r   ú /usr/lib/python3.6/baseparser.pyr      s    zPrettyHelpFormatter.__init__c             C   s   | j |ddƒS )Nz <%s>z, )Ú_format_option_strings)r   Úoptionr   r   r   Úformat_option_strings!   s    z)PrettyHelpFormatter.format_option_stringsú <%s>ú, c             C   s|   g }|j r|j|j d ƒ |jr0|j|jd ƒ t|ƒdkrH|jd|ƒ |jƒ rr|jp^|jjƒ }|j||jƒ  ƒ dj	|ƒS )a  
        Return a comma-separated list of option strings and metavars.

        :param option:  tuple of (short opt, long opt), e.g: ('-f', '--format')
        :param mvarfmt: metavar format string - evaluated as mvarfmt % metavar
        :param optsep:  separator
        r   r   Ú )
Z_short_optsÚappendZ
_long_optsÚlenÚinsertZtakes_valueÚmetavarÚdestÚlowerÚjoin)r   r   ZmvarfmtZoptsepZoptsr"   r   r   r   r   $   s    z*PrettyHelpFormatter._format_option_stringsc             C   s   |dkrdS |d S )NZOptionsr   z:
r   )r   Zheadingr   r   r   Úformat_heading;   s    z"PrettyHelpFormatter.format_headingc             C   s   d| j tj|ƒdƒ }|S )zz
        Ensure there is only one newline between usage and the first heading
        if there is no description.
        z
Usage: %s
z  )Úindent_linesÚtextwrapÚdedent)r   ZusageÚmsgr   r   r   Úformat_usage@   s    z PrettyHelpFormatter.format_usagec             C   sV   |rNt | jdƒrd}nd}|jdƒ}|jƒ }| jtj|ƒdƒ}d||f }|S dS d S )NÚmainZCommandsZDescriptionÚ
z  z%s:
%s
r   )ÚhasattrÚparserÚlstripÚrstripr'   r(   r)   )r   ÚdescriptionZlabelr   r   r   Úformat_descriptionH   s    
z&PrettyHelpFormatter.format_descriptionc             C   s   |r|S dS d S )Nr   r   )r   Zepilogr   r   r   Úformat_epilogZ   s    z!PrettyHelpFormatter.format_epilogc                s"   ‡ fdd„|j dƒD ƒ}dj|ƒS )Nc                s   g | ]}ˆ | ‘qS r   r   )Ú.0Úline)Úindentr   r   ú
<listcomp>b   s    z4PrettyHelpFormatter.indent_lines.<locals>.<listcomp>r-   )Úsplitr%   )r   Útextr7   Z	new_linesr   )r7   r   r'   a   s    z PrettyHelpFormatter.indent_linesN)r   r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r&   r+   r3   r4   r'   r   r   r   r   r      s   
r   c               @   s   e Zd ZdZdd„ ZdS )ÚUpdatingDefaultsHelpFormatterz®Custom help formatter for use in ConfigOptionParser.

    This is updates the defaults before expanding them, allowing
    them to show up correctly in the help listing.
    c             C   s(   | j d k	r| j j| j jƒ tjj| |ƒS )N)r/   Ú_update_defaultsÚdefaultsr   r   Úexpand_default)r   r   r   r   r   rB   m   s    
z,UpdatingDefaultsHelpFormatter.expand_defaultN)r;   r<   r=   r>   rB   r   r   r   r   r?   f   s   r?   c               @   s    e Zd Zdd„ Zedd„ ƒZdS )ÚCustomOptionParserc             O   s(   | j ||Ž}| jjƒ  | jj||ƒ |S )z*Insert an OptionGroup at a given position.)Zadd_option_groupÚoption_groupsÚpopr!   )r   Úidxr   r   Úgroupr   r   r   Úinsert_option_groupu   s    
z&CustomOptionParser.insert_option_groupc             C   s.   | j dd… }x| jD ]}|j|j ƒ qW |S )z<Get a list of all options, including those in option groups.N)Zoption_listrD   Úextend)r   ÚresÚir   r   r   Úoption_list_all~   s    z"CustomOptionParser.option_list_allN)r;   r<   r=   rH   ÚpropertyrL   r   r   r   r   rC   s   s   	rC   c               @   s\   e Zd ZdZdZdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ ZdS )ÚConfigOptionParserzsCustom option parser which updates its defaults by checking the
    configuration files and environmental variablesFc             O   sd   t jƒ | _|jdƒ| _|jddƒ| _| jƒ | _| jrB| jj| jƒ | jsLt	‚t
jj| f|ž|Ž d S )NÚnameÚisolatedF)r   ZRawConfigParserÚconfigrE   rO   rP   Úget_config_filesÚfilesÚreadÚAssertionErrorr   ÚOptionParserr   )r   r   r   r   r   r   r   Ž   s    


zConfigOptionParser.__init__c             C   sš   t jjddƒ}|t jkrg S ttƒ}| jsj|rFt jj|ƒrF|j	|ƒ n$|j	t
ƒ |j	t jjtjdƒtƒƒ tƒ r–t jjtjtƒ}t jj|ƒr–|j	|ƒ |S )NZPIP_CONFIG_FILEFZpip)ÚosÚenvironÚgetÚdevnullÚlistr	   rP   ÚpathÚexistsr   r   r%   r
   Zuser_config_dirr   r   ÚsysÚprefix)r   Zconfig_filerS   Zvenv_config_filer   r   r   rR   ˜   s&    


z#ConfigOptionParser.get_config_filesc             C   sL   y|j ||ƒS  tjk
rF } ztd| ƒ tjdƒ W Y d d }~X nX d S )Nz*An error occurred during configuration: %sé   )Úcheck_valuer   ZOptionValueErrorÚprintr^   Úexit)r   r   ÚkeyÚvalÚexcr   r   r   Úcheck_defaultÀ   s
    z ConfigOptionParser.check_defaultc       	         sj  i }x(dˆj fD ]}|jˆjˆj|ƒƒƒ qW ˆjsH|jˆjˆjƒ ƒƒ tjˆjƒˆ_	t
ƒ }xâ|jƒ D ]Ö\‰ }|stqfˆjˆ ƒ‰ˆdkrˆqfˆjd
krœt|ƒ}n–ˆjdkrÆ|jƒ }‡ ‡‡fdd„|D ƒ}nlˆjd	k�r$|jˆjƒ ˆjƒ }ˆj||ƒ}ˆj� püf }ˆj�pi }ˆjˆ||ˆf|ž|Ž nˆjˆˆ |ƒ}||ˆj< qfW x|D ]‰ tˆj	ˆ ƒ|ˆ < �qFW dˆ_	|S )z¢Updates the given defaults with values from the config files and
        the environ. Does a little special handling for certain types of
        options (lists).ÚglobalNÚ
store_trueÚstore_falseÚcountr   c                s   g | ]}ˆj ˆˆ |ƒ‘qS r   )rg   )r5   Úv)rd   r   r   r   r   r8   é   s    z7ConfigOptionParser._update_defaults.<locals>.<listcomp>Úcallback)ri   rj   rk   )rO   ÚupdateÚnormalize_keysÚget_config_sectionrP   Úget_environ_varsr   ÚValuesrA   ÚvaluesÚsetÚitemsZ
get_optionÚactionr   r9   Úaddr#   Úget_opt_stringZconvert_valueZcallback_argsZcallback_kwargsrm   rg   Úgetattr)	r   rA   rQ   ZsectionZ	late_evalre   Úopt_strr   r   r   )rd   r   r   r   r@   Ç   s@    




z#ConfigOptionParser._update_defaultsc             C   s@   i }x6|D ].\}}|j ddƒ}|jdƒs0d| }|||< q
W |S )z™Return a config dictionary with normalized keys regardless of
        whether the keys were specified in environment variables or in config
        filesÚ_ú-z--z--%s)ÚreplaceÚ
startswith)r   ru   Z
normalizedrd   re   r   r   r   ro   ü   s    
z!ConfigOptionParser.normalize_keysc             C   s   | j j|ƒr| j j|ƒS g S )z Get a section of a configuration)rQ   Zhas_sectionru   )r   rO   r   r   r   rp     s    z%ConfigOptionParser.get_config_sectionc             c   s<   x6t jjƒ D ](\}}tj|ƒrtjd|ƒjƒ |fV  qW dS )z@Returns a generator with all environmental vars with prefix PIP_r   N)rW   rX   ru   Ú_environ_prefix_reÚsearchÚsubr$   )r   rd   re   r   r   r   rq     s    
z#ConfigOptionParser.get_environ_varsc             C   sn   | j stj| jƒS | j| jjƒ ƒ}x@| jƒ D ]4}|j|jƒ}t	|t
ƒr,|jƒ }|j||ƒ||j< q,W tj|ƒS )z‹Overriding to make updating the defaults after instantiation of
        the option parser possible, _update_defaults() does the dirty work.)Zprocess_default_valuesr   rr   rA   r@   ÚcopyZ_get_all_optionsrY   r#   Ú
isinstancer   rx   ra   )r   rA   r   Údefaultrz   r   r   r   Úget_default_values  s    
z%ConfigOptionParser.get_default_valuesc             C   s    | j tjƒ | jdd| ƒ d S )Nr   z%s
)Zprint_usager^   Ústderrrc   )r   r*   r   r   r   Úerror#  s    zConfigOptionParser.errorN)r;   r<   r=   r>   rP   r   rR   rg   r@   ro   rp   rq   r…   r‡   r   r   r   r   rN   ˆ   s   
(5rN   )r>   Z
__future__r   r^   r   rW   Úrer(   Zdistutils.utilr   Zpip._vendor.sixr   Zpip._vendor.six.movesr   Zpip.locationsr   r   r   r	   Z	pip.utilsr
   r   ÚcompileÚIr   r   r   r?   rV   rC   rN   r   r   r   r   Ú<module>   s    O