3
`^%                 @   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mZ ddl	m
Z
 ddlmZ ddlmZmZ ddlmZ eje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d ZdS )zBase option parser setup    )absolute_importN)	strtobool)string_types)UNKNOWN_ERROR)ConfigurationConfigurationError)get_terminal_sizec               @   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   max_help_position   indent_incrementr      width)r   optparseIndentedHelpFormatter__init__)selfargskwargs r   L/var/www/locly/locly/lib/python3.6/site-packages/pip/_internal/cli/parser.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    )
_short_optsappend
_long_optsleninserttakes_valuemetavardestlowerjoin)r   r   ZmvarfmtZoptsepoptsr$   r   r   r   r   $   s    z*PrettyHelpFormatter._format_option_stringsc             C   s   |dkrdS |d S )NOptionsr   z:
r   )r   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   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   descriptionlabelr   r   r   format_descriptionH   s    
z&PrettyHelpFormatter.format_descriptionc             C   s   |r|S dS d S )Nr   r   )r   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>r3   )splitr'   )r   textr?   Z	new_linesr   )r?   r   r,   a   s    z PrettyHelpFormatter.indent_linesN)r   r   )__name__
__module____qualname____doc__r   r   r   r+   r1   r:   r<   r,   r   r   r   r   r	      s   
r	   c               @   s   e Zd ZdZdd ZdS )UpdatingDefaultsHelpFormatterzCustom 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)r5   _update_defaultsdefaultsr   r   expand_default)r   r   r   r   r   rJ   m   s    
z,UpdatingDefaultsHelpFormatter.expand_defaultN)rC   rD   rE   rF   rJ   r   r   r   r   rG   f   s   rG   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.)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)option_listrM   extend)r   resir   r   r   option_list_all~   s    z"CustomOptionParser.option_list_allN)rC   rD   rE   rQ   propertyrV   r   r   r   r   rK   s   s   	rK   c               @   s@   e Zd Z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 variablesc             O   sD   |j d| _|j dd}t|| _| js,ttjj| f|| d S )NnameisolatedF)rN   rY   r   configAssertionErrorr   OptionParserr   )r   r   r   rZ   r   r   r   r      s
    

zConfigOptionParser.__init__c             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   OptionValueErrorprintsysexit)r   r   keyvalexcr   r   r   check_default   s
    z ConfigOptionParser.check_defaultc             c   s   d| j dg}dd |D }xR| jj D ]D\}}|s@tjd| q&|jdd\}}||kr&|| j||f q&W x,|D ]$}x|| D ]\}}||fV  qW qtW d S )Nglobalz:env:c             S   s   i | ]
}g |qS r   r   )r=   rY   r   r   r   
<dictcomp>   s    zGConfigOptionParser._get_ordered_configuration_items.<locals>.<dictcomp>z7Ignoring configuration key '%s' as it's value is empty..r   )rY   r[   itemsloggerdebugrA   r   )r   Zoverride_ordersection_itemsZsection_keyre   sectionrd   r   r   r    _get_ordered_configuration_items   s    
z3ConfigOptionParser._get_ordered_configuration_itemsc                sR  t jj_t }xj D ]\ }jd  dkrBq jd
kryt|}W n, t	k
r   t
j |}j| Y nX njdkr|j } fdd|D }nhjd	kr|jj j }j||}jpf }jpi }j||f|| nj |}||j< q W x|D ] tj | < q.W d_|S )zUpdates the given defaults with values from the config files and
        the environ. Does a little special handling for certain types of
        options (lists).z--N
store_truestore_falsecountr   c                s   g | ]}j  |qS r   )rg   )r=   v)rd   r   r   r   r   r@      s    z7ConfigOptionParser._update_defaults.<locals>.<listcomp>callback)rq   rr   rs   )r   ValuesrI   valuessetrp   
get_optionactionr   
ValueErrorinvalid_config_error_messageerrorrA   addr%   get_opt_stringconvert_valuecallback_argscallback_kwargsru   rg   getattr)r   rI   Z	late_evalre   	error_msgopt_strr   r   r   )rd   r   r   r   rH      s:    




z#ConfigOptionParser._update_defaultsc             C   s   | j stj| jS y| jj  W n2 tk
rR } z| jtt	| W Y dd}~X nX | j
| jj }x@| j D ]4}|j|j}t|trn|j }|j||||j< qnW tj|S )zOverriding to make updating the defaults after instantiation of
        the option parser possible, _update_defaults() does the dirty work.N)process_default_valuesr   rv   rI   r[   loadr   rc   r   strrH   copy_get_all_optionsgetr%   
isinstancer   r   r_   )r   errrI   r   defaultr   r   r   r   get_default_values   s    "
z%ConfigOptionParser.get_default_valuesc             C   s    | j tj | jtd|  d S )Nz%s
)print_usagerb   stderrrc   r   )r   r0   r   r   r   r}      s    zConfigOptionParser.errorN)
rC   rD   rE   rF   r   rg   rp   rH   r   r}   r   r   r   r   rX      s   	1rX   c             C   s    | dkrdj ||S dj ||S )zQReturns a better error message when invalid configuration option
    is provided.rq   rr   zo{0} is not a valid value for {1} option, please specify a boolean value like yes/no, true/false or 1/0 instead.z[{0} is not a valid value for {1} option, please specify a numerical value like 1/0 instead.)rq   rr   )format)rz   rd   re   r   r   r   r|      s
    r|   )rF   
__future__r   loggingr   rb   r-   distutils.utilr   pip._vendor.sixr   Zpip._internal.cli.status_codesr   Zpip._internal.configurationr   r   pip._internal.utils.compatr   	getLoggerrC   rl   r   r	   rG   r]   rK   rX   r|   r   r   r   r   <module>   s    
Ow