Edit File: baseparser.cpython-36.pyc
3 )�]b�(������������������@���s����d�Z�ddlmZ�ddlZddlZddlZddlZddlZddlm Z �ddl mZ�ddlm Z �ddlmZmZmZmZ�ddlmZmZ�ejd ej�ZG�d d��dej�ZG�dd ��d e�ZG�dd��dej�ZG�dd��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���������������@���sR���e�Zd�ZdZdd��Zdd��Zddd �Zd d��Zdd ��Zdd��Z dd��Z dd��ZdS�)�PrettyHelpFormatterz4A prettier/less verbose help formatter for optparse.c�������������O���s:���d|d<�d|d<�t���d�d�|d<�tjj|�f|�|��d�S�)N����Zmax_help_position����Zindent_incrementr��������width)r����optparse�IndentedHelpFormatter�__init__)�self�args�kwargs��r���� /usr/lib/python3.6/baseparser.pyr������s����zPrettyHelpFormatter.__init__c�������������C���s���|�j�|dd�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���|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 r���r�����) Z_short_opts�appendZ _long_opts�len�insertZtakes_value�metavar�dest�lower�join)r���r���ZmvarfmtZoptsepZoptsr"���r���r���r���r���$���s����z*PrettyHelpFormatter._format_option_stringsc�������������C���s���|dkrdS�|d�S�)NZOptionsr���z: r���)r���Zheadingr���r���r����format_heading;���s����z"PrettyHelpFormatter.format_headingc�������������C���s���d|�j�tj|�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���Zusage�msgr���r���r����format_usage@���s����z PrettyHelpFormatter.format_usagec�������������C���sV���|rNt�|�jd�rd}nd}|jd�}|j��}|�jtj|�d�}d||f�}|S�dS�d�S�)N�mainZCommandsZDescription� z z%s: %s r���)�hasattr�parser�lstrip�rstripr'���r(���r)���)r����descriptionZlabelr���r���r����format_descriptionH���s���� z&PrettyHelpFormatter.format_descriptionc�������������C���s���|r|S�dS�d�S�)Nr���r���)r���Zepilogr���r���r���� format_epilogZ���s����z!PrettyHelpFormatter.format_epilogc����������������s"�����fdd�|j�d�D��}dj|�S�)Nc����������������s���g�|�]}��|��qS�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�Zd�ZdZdd��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. c�������������C���s(���|�j�d�k r|�j�j|�j�j��tjj|�|�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�Zd�Zdd��Zedd���ZdS�)�CustomOptionParserc�������������O���s(���|�j�||�}|�jj���|�jj||��|S�)z*Insert an OptionGroup at a given position.)Zadd_option_group� option_groups�popr!���)r����idxr���r����groupr���r���r����insert_option_groupu���s���� z&CustomOptionParser.insert_option_groupc�������������C���s.���|�j�dd��}x|�jD�]}|j|j���qW�|S�)z<Get a list of all options, including those in option groups.N)Zoption_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�Zd�ZdZdZdd��Zdd��Zdd��Zd d ��Zdd��Z d d��Z dd��Zdd��Zdd��Z dS�)�ConfigOptionParserzsCustom option parser which updates its defaults by checking the configuration files and environmental variablesFc�������������O���sd���t�j��|�_|jd�|�_|jdd�|�_|�j��|�_|�jrB|�jj|�j��|�jsLt �t jj|�f|�|��d�S�)N�name�isolatedF) r���ZRawConfigParser�configrE���rO���rP����get_config_files�files�read�AssertionErrorr����OptionParserr���)r���r���r���r���r���r���r�������s���� zConfigOptionParser.__init__c�������������C���s����t�jjdd�}|t�jkrg�S�tt�}|�jsj|rFt�jj|�rF|j |��n$|j t ��|j t�jjtj d�t���t��r�t�jjtjt�}t�jj|�r�|j |��|S�)NZPIP_CONFIG_FILEFZpip)�os�environ�get�devnull�listr ���rP����path�existsr���r���r%���r ���Zuser_config_dirr���r����sys�prefix)r���Zconfig_filerS���Zvenv_config_filer���r���r���rR�������s&���� z#ConfigOptionParser.get_config_filesc�������������C���sL���y|j�||�S��tjk rF�}�ztd|���tjd��W�Y�d�d�}~X�nX�d�S�)Nz*An error occurred during configuration: %s����)�check_valuer���ZOptionValueError�printr^����exit)r���r����key�val�excr���r���r���� check_default����s ����z ConfigOptionParser.check_defaultc������� ���������sj��i�}x(d�j�fD�]}|j�j�j|����qW��jsH|j�j�j�����tj�j��_ t ��}x�|j��D�]�\��}|stqf�j�����dkr�qf�j d kr�t|�}n��j dkr�|j��}����fdd�|D��}nl�j d k�r$|j�j���j��}�j||�}�j��p�f�}�j�pi�}�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����|��qS�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_argsZcallback_kwargsrm���rg����getattr) r���rA���rQ���ZsectionZ late_evalre����opt_strr���r���r���)rd���r���r���r���r@�������s@���� z#ConfigOptionParser._update_defaultsc�������������C���s@���i�}x6|D�].\}}|j�dd�}|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)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���Zhas_sectionru���)r���rO���r���r���r���rp�����s����z%ConfigOptionParser.get_config_sectionc�������������c���s<���x6t�jj��D�](\}}tj|�rtjd|�j��|fV��qW�dS�)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�stj|�j�S�|�j|�jj���}x@|�j��D�]4}|j|j�}t |t �r,|j��}|j||�||j<�q,W�tj|�S�)z�Overriding to make updating the defaults after instantiation of the option parser possible, _update_defaults() does the dirty work.) Zprocess_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�tj��|�jdd|���d�S�)Nr���z%s )Zprint_usager^����stderrrc���)r���r*���r���r���r����error#��s����zConfigOptionParser.errorN)r;���r<���r=���r>���rP���r���rR���rg���r@���ro���rp���rq���r����r����r���r���r���r���rN�������s��� (5rN���)r>���Z __future__r���r^���r���rW����rer(���Zdistutils.utilr���Zpip._vendor.sixr���Zpip._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