3 �Pf�(�@s�dZddlmZddlZddlZddlZddlZddlZddlm Z ddl m Z ddl m Z ddlmZmZmZmZddlmZmZejd ej�ZGd d �d ej�ZGd d �d e�ZGdd�dej�ZGdd�de�ZdS)zBase 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@sReZdZdZdd�Zdd�Zddd �Zd d �Zd d �Zdd�Z dd�Z dd�Z dS)�PrettyHelpFormatterz4A prettier/less verbose help formatter for optparse.cOs:d|d<d|d<t�dd|d<tjj|f|�|�dS)N�Zmax_help_position�Zindent_incrementr��width)r �optparse�IndentedHelpFormatter�__init__)�self�args�kwargs�r� /usr/lib/python3.6/baseparser.pyrszPrettyHelpFormatter.__init__cCs|j|dd�S)Nz <%s>z, )�_format_option_strings)r�optionrrr�format_option_strings!sz)PrettyHelpFormatter.format_option_strings� <%s>�, cCs|g}|jr|j|jd�|jr0|j|jd�t|�dkrH|jd|�|j�rr|jp^|jj�}|j||j��dj |�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 rr�) Z _short_opts�appendZ _long_opts�len�insertZ takes_value�metavar�dest�lower�join)rrZmvarfmtZoptsepZoptsr"rrrr$s  z*PrettyHelpFormatter._format_option_stringscCs|dkr dS|dS)NZOptionsrz: r)rZheadingrrr�format_heading;sz"PrettyHelpFormatter.format_headingcCsd|jtj|�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)rZusage�msgrrr� format_usage@sz PrettyHelpFormatter.format_usagecCsV|rNt|jd�rd}nd}|jd�}|j�}|jtj|�d�}d||f}|SdSdS)N�mainZCommandsZ Description� z z%s: %s r)�hasattr�parser�lstrip�rstripr'r(r))r� descriptionZlabelrrr�format_descriptionHs   z&PrettyHelpFormatter.format_descriptioncCs|r|SdSdS)Nrr)rZepilogrrr� format_epilogZsz!PrettyHelpFormatter.format_epilogcs"�fdd�|jd�D�}dj|�S)Ncsg|] }�|�qSrr)�.0�line)�indentrr� bsz4PrettyHelpFormatter.indent_lines..r-)�splitr%)r�textr7Z new_linesr)r7rr'asz PrettyHelpFormatter.indent_linesN)rr) �__name__� __module__� __qualname__�__doc__rrrr&r+r3r4r'rrrrr s r c@seZdZdZdd�ZdS)�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. cCs(|jdk r|jj|jj�tjj||�S)N)r/�_update_defaults�defaultsrr�expand_default)rrrrrrBms z,UpdatingDefaultsHelpFormatter.expand_defaultN)r;r<r=r>rBrrrrr?fsr?c@s eZdZdd�Zedd��ZdS)�CustomOptionParsercOs(|j||�}|jj�|jj||�|S)z*Insert an OptionGroup at a given position.)Zadd_option_group� option_groups�popr!)r�idxrr�grouprrr�insert_option_groupus  z&CustomOptionParser.insert_option_groupcCs.|jdd�}x|jD]}|j|j�qW|S)z.�callback)rhrirj)rO�update�normalize_keys�get_config_sectionrP�get_environ_varsr�ValuesrA�values�set�itemsZ get_option�actionrr9�addr#�get_opt_stringZ convert_valueZ callback_argsZcallback_kwargsrlrf�getattr) rrArQZsectionZ late_evalrd�opt_strrrr)rcrrrr@�s@          z#ConfigOptionParser._update_defaultscCs@i}x6|D].\}}|jdd�}|jd�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)rrtZ normalizedrcrdrrrrn�s   z!ConfigOptionParser.normalize_keyscCs|jj|�r|jj|�SgS)z Get a section of a configuration)rQZ has_sectionrt)rrOrrrros  z%ConfigOptionParser.get_config_sectionccs<x6tjj�D](\}}tj|�r tjd|�j�|fVq WdS)z@Returns a generator with all environmental vars with prefix PIP_rN)rVrWrt�_environ_prefix_re�search�subr$)rrcrdrrrrps z#ConfigOptionParser.get_environ_varscCsn|jstj|j�S|j|jj��}x@|j�D]4}|j|j�}t |t �r,|j �}|j ||�||j<q,Wtj|�S)z�Overriding to make updating the defaults after instantiation of the option parser possible, _update_defaults() does the dirty work.) Zprocess_default_valuesrrqrAr@�copyZ_get_all_optionsrXr#� isinstancerrwr`)rrAr�defaultryrrr�get_default_valuess   z%ConfigOptionParser.get_default_valuescCs |jtj�|jdd|�dS)Nrz%s )Z print_usager]�stderrrb)rr*rrr�error#s zConfigOptionParser.errorN)r;r<r=r>rPrrRrfr@rnrorpr�r�rrrrrN�s (5 rN)r>Z __future__rr]rrV�rer(Zdistutils.utilrZpip._vendor.sixrZpip._vendor.six.movesrZ pip.locationsrrrr Z pip.utilsr r �compile�Ir~rr r?rUrCrNrrrr�s     O