a [dgY+@sdZddlZddlZddlZddlZddlZddlmZddlm Z m Z m Z m Z m Z ddlmZddlmZmZddlmZmZeeZGdd d ejZGd d d eZGd d d ejZGdddeZdS)zBase option parser setupN)suppress)AnyDictIteratorListTuple) UNKNOWN_ERROR) ConfigurationConfigurationError)redact_auth_from_url strtoboolcsZeZdZdZfddZddZddd Zd d Zd d ZddZ ddZ ddZ Z S)PrettyHelpFormatterz4A prettier/less verbose help formatter for optparse.cs:d|d<d|d<tdd|d<tj|i|dS)Nmax_help_positionindent_incrementrwidth)shutilget_terminal_sizesuper__init__)selfargskwargs __class__B/usr/local/lib/python3.9/site-packages/pip/_internal/cli/parser.pyrszPrettyHelpFormatter.__init__cCs ||SN)_format_option_strings)roptionrrrformat_option_stringssz)PrettyHelpFormatter.format_option_strings <{}>, cCs~g}|jr||jd|jr0||jdt|dkrH|d||rt|jp^|j}|| |d |S)z 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 :param optsep: separator rr) Z _short_optsappendZ _long_optsleninsertZ takes_valuemetavardestlowerformatjoin)rr!ZmvarfmtZoptsepZoptsr)rrrr !s   z*PrettyHelpFormatter._format_option_stringscCs|dkr dS|dS)NZOptionsr%: r)rheadingrrrformat_heading:sz"PrettyHelpFormatter.format_headingcCsd|t|d}|S)zz Ensure there is only one newline between usage and the first heading if there is no description. z Usage: {}  )r, indent_linestextwrapdedent)rusagemsgrrr format_usage@sz PrettyHelpFormatter.format_usagecCsZ|rRt|jdrd}nd}|d}|}|t|d}|d|d}|SdSdS)NmainZCommandsZ Description r1r.r%)hasattrparserlstriprstripr2r3r4)r descriptionZlabelrrrformat_descriptionIs  z&PrettyHelpFormatter.format_descriptioncCs|r|SdSdS)Nr%r)repilogrrr format_epilog\sz!PrettyHelpFormatter.format_epilogcs"fdd|dD}d|S)Ncsg|] }|qSrr).0lineindentrr fz4PrettyHelpFormatter.indent_lines..r9)splitr-)rtextrEZ new_linesrrDrr2dsz PrettyHelpFormatter.indent_lines)r#r$) __name__ __module__ __qualname____doc__rr"r r0r7r?rAr2 __classcell__rrrrr s   r cs eZdZdZfddZZS)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. Also redact auth from url type options csd}|jdur.|j|jj|jj|j}t|}|r|jdkrt|t rX|g}t|t sfg}|D]}| |t |}qj|S)NZURL) r;_update_defaultsdefaultsgetr*rexpand_defaultr) isinstancestrlistreplacer )rr!Zdefault_values help_textvalrrrrSss    z,UpdatingDefaultsHelpFormatter.expand_default)rJrKrLrMrSrNrrrrrOjsrOc@s eZdZddZeddZdS)CustomOptionParsercOs,|j|i|}|j|j|||S)z*Insert an OptionGroup at a given position.)Zadd_option_group option_groupspopr()ridxrrgrouprrrinsert_option_groups z&CustomOptionParser.insert_option_groupcCs*|jdd}|jD]}||jq|S)ztd|q$|dd\}}||vr$||||fq$|D] }||D]\}}||fVqzqndS)Nglobalz:env:cSsi|] }|gqSrr)rBrgrrr szGConfigOptionParser._get_ordered_configuration_items..z7Ignoring configuration key '%s' as it's value is empty..r)rgrhitemsloggerdebugrHr&)rZoverride_orderZ section_itemsZ section_keyrYsectionrorrr _get_ordered_configuration_itemss" z3ConfigOptionParser._get_ordered_configuration_itemsc stj_t}D]\}ddur>qjdvr~z t|}Wn$t yx d |Yn0n2jdkrt t t|}Wdn1s0Yt t t |}Wdn1s0Yt|t r|dkr d |njdkr>|}fd d |D}nrjd kr|j}||}jptd }jpi}j||g|Ri|n|}||j<q|D]tj|<qd_|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_falsezm{} is not a valid value for {} option, please specify a boolean value like yes/no, true/false or 1/0 instead.countrz{} is not a valid value for {} option, please instead specify either a non-negative integer or a boolean value like yes/no or false/true which is equivalent to 1/0.r&csg|]}|qSr)rq)rBvror!rrrrFrGz7ConfigOptionParser._update_defaults..callbackr)rkValuesrQvaluessetryZ get_optionactionr ValueErrorerrorr,rintrTrHaddr*get_opt_stringZ convert_valueZ callback_argsZcallback_kwargsrrqgetattr)rrQZ late_evalrYopt_strrrrr~rrPsT     & &        z#ConfigOptionParser._update_defaultsc Cs|jst|jSz|jWn4tyT}z|tt |WYd}~n d}~00| |j }| D]4}| |j}t|t rn|}|||||j<qnt|S)zOverriding to make updating the defaults after instantiation of the option parser possible, _update_defaults() does the dirty work.N)Zprocess_default_valuesrkrrQrhloadr rnrrUrPcopyZ_get_all_optionsrRr*rTrrj)rerrrQr!defaultrrrrget_default_valuess &   z%ConfigOptionParser.get_default_valuescCs"|tj|t|ddS)Nr9) print_usagermstderrrnr)rr6rrrr.s zConfigOptionParser.error) rJrKrLrMrrqryrPrrrNrrrrresAre)rMloggingrkrrmr3 contextlibrtypingrrrrrZpip._internal.cli.status_codesrZpip._internal.configurationr r Zpip._internal.utils.miscr r getLoggerrJrvZIndentedHelpFormatterr rOZ OptionParserrZrerrrrs   X!