grthtrhthjhtyjytjytkergtrhtrjytjerhrfh3 Ý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)rirjrk)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_kwargsrmrgÚgetattr) rrArQZsectionZ late_evalreÚopt_strrrr)rdrrrr@Ç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)rruZ normalizedrdrerrrroüs   z!ConfigOptionParser.normalize_keyscCs|jj|ƒr|jj|ƒSgS)z Get a section of a configuration)rQZ has_sectionru)rrOrrrrps  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)rWrXruÚ_environ_prefix_reÚsearchÚsubr$)rrdrerrrrqs 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_valuesrrrrAr@ÚcopyZ_get_all_optionsrYr#Ú isinstancerrxra)rrArÚdefaultrzrrrÚget_default_valuess   z%ConfigOptionParser.get_default_valuescCs |jtjƒ|jdd|ƒdS)Nrz%s )Z print_usager^Ústderrrc)rr*rrrÚerror#s zConfigOptionParser.errorN)r;r<r=r>rPrrRrgr@rorprqr…r‡rrrrrNˆs (5 rN)r>Z __future__rr^rrWÚrer(Zdistutils.utilrZpip._vendor.sixrZpip._vendor.six.movesrZ pip.locationsrrrr Z pip.utilsr r ÚcompileÚIrrr r?rVrCrNrrrrÚs     O