^c-ddlZddlZddlmZddlmZmZhdZdZddZ Gd d Z Gd d e Z Gd de Z Gdde Z Gdde ZdZddZdS)N)_)errorpycompat>helpversionnoninteractivec|dr[|d\}}}|dd|vr|t||dfS|dddz|vr|t||dfSn|dr||dkrv|dsa|dd|dd}}||d d}|d kr*|t|||d |d zfSd S) aCheck if the given arg is a valid unabbreviated option Returns (flag_str, has_embedded_value?, embedded_value, takes_value?) >>> def opt(arg): ... return _earlyoptarg(arg, b'R:q', [b'cwd=', b'debugger']) long form: >>> opt(b'--cwd') ('--cwd', False, '', True) >>> opt(b'--cwd=') ('--cwd', True, '', True) >>> opt(b'--cwd=foo') ('--cwd', True, 'foo', True) >>> opt(b'--debugger') ('--debugger', False, '', False) >>> opt(b'--debugger=') # invalid but parsable ('--debugger', True, '', False) short form: >>> opt(b'-R') ('-R', False, '', True) >>> opt(b'-Rfoo') ('-R', True, 'foo', True) >>> opt(b'-q') ('-q', False, '', False) >>> opt(b'-qfoo') # invalid but parsable ('-q', True, 'foo', False) unknown or invalid: >>> opt(b'--unknown') ('', False, '', False) >>> opt(b'-u') ('', False, '', False) >>> opt(b'-ufoo') ('', False, '', False) >>> opt(b'--') ('', False, '', False) >>> opt(b'-') ('', False, '', False) >>> opt(b'-:') ('', False, '', False) >>> opt(b'-:foo') ('', False, '', False) --=NFT-s-:rr:)FrF) startswith partitionboolfind)arg shortlistnamelistflageqvalis 5/usr/lib/python3/dist-packages/mercurial/fancyopts.py _earlyoptargrs!b ~~e K d++ b# 8x  b3- - 8d?h & &b3, , '   K#++cnnU6K6K+GSWc NN48 $ $ 66cC)=)=dAE)J)JJ J ! !rFcg}g}d}|t|kr||}|dkr|| z }nt|||\} } } } | s| r|dzt|krn| r| r | s|r|||dz }nIn[| | kr|| | f|dz }n%|| ||dzf|dz }|t|k|||d||fS)as Parse options like getopt, but ignores unknown options and abbreviated forms If gnu=False, this stops processing options as soon as a non/unknown-option argument is encountered. Otherwise, option and non-option arguments may be intermixed, and unknown-option arguments are taken as non-option. If keepsep=True, '--' won't be removed from the list of arguments left. This is useful for stripping early options from a full command arguments. >>> def get(args, gnu=False, keepsep=False): ... return earlygetopt(args, b'R:q', [b'cwd=', b'debugger'], ... gnu=gnu, keepsep=keepsep) default parsing rules for early options: >>> get([b'x', b'--cwd', b'foo', b'-Rbar', b'-q', b'y'], gnu=True) ([('--cwd', 'foo'), ('-R', 'bar'), ('-q', '')], ['x', 'y']) >>> get([b'x', b'--cwd=foo', b'y', b'-R', b'bar', b'--debugger'], gnu=True) ([('--cwd', 'foo'), ('-R', 'bar'), ('--debugger', '')], ['x', 'y']) >>> get([b'--unknown', b'--cwd=foo', b'--', '--debugger'], gnu=True) ([('--cwd', 'foo')], ['--unknown', '--debugger']) restricted parsing rules (early options must come first): >>> get([b'--cwd', b'foo', b'-Rbar', b'x', b'-q', b'y'], gnu=False) ([('--cwd', 'foo'), ('-R', 'bar')], ['x', '-q', 'y']) >>> get([b'--cwd=foo', b'x', b'y', b'-R', b'bar', b'--debugger'], gnu=False) ([('--cwd', 'foo')], ['x', 'y', '-R', 'bar', '--debugger']) >>> get([b'--unknown', b'--cwd=foo', b'--', '--debugger'], gnu=False) ([], ['--unknown', '--cwd=foo', '--', '--debugger']) stripping early options (without loosing '--'): >>> get([b'x', b'-Rbar', b'--', '--debugger'], gnu=True, keepsep=True)[1] ['x', '--', '--debugger'] last argument: >>> get([b'--cwd']) ([], ['--cwd']) >>> get([b'--cwd=foo']) ([('--cwd', 'foo')], []) >>> get([b'-R']) ([], ['-R']) >>> get([b'-Rbar']) ([('-R', 'bar')], []) >>> get([b'-q']) ([('-q', '')], []) >>> get([b'-q', b'--']) ([('-q', '')], []) '--' may be a value: >>> get([b'-R', b'--', b'x']) ([('-R', '--')], ['x']) >>> get([b'--cwd', b'--', b'x']) ([('--cwd', '--')], ['x']) value passed to bool options: >>> get([b'--debugger=foo', b'x']) ([], ['--debugger=foo', 'x']) >>> get([b'-qfoo', b'x']) ([], ['-qfoo', 'x']) short option isn't separated with '=': >>> get([b'-R=bar']) ([('-R', '=bar')], []) ':' may be in shortlist, but shouldn't be taken as an option letter: >>> get([b'-:', b'y']) ([], ['-:', 'y']) '-' is a valid non-option argument: >>> get([b'-', b'y']) ([], ['-', 'y']) rr rr N)lenrappendextend) argsrrgnukeepsep parsedopts parsedargsposrrhasvalrtakevals r earlygetoptr*]sXdJJ C D //3i %<< w; C %1#y(%K%K"fc7 ' cAgT&:&:  v g  !!#&&&q w     tSk * * * 1HCC   tT#']3 4 4 4 1HC/ D //2d344j!!! z !!rcReZdZdZejZdZdZdZ ej dZ dS) customoptz2Manage defaults and mutations for any type of opt.c||_dSN _defaultvalue)self defaultvalues r__init__zcustomopt.__init__s)rcdS)NFr1s r _isbooloptzcustomopt._isbooloptsurc|jS)zReturns the default value for this opt. Subclasses should override this to return a new value if the value type is mutable.r/r6s rgetdefaultvaluezcustomopt.getdefaultvalues !!rcdS)zzAdds newparam to oldstate and returns the new state. On failure, abort can be called with a string error message.Nr5r1oldstatenewparamaborts rnewstatezcustomopt.newstatesrN) __name__ __module__ __qualname____doc__abcABCMeta __metaclass__r3r7r9abstractmethodr?r5rrr,r,sr<<KM***""" HHHHHrr,ceZdZdZdZdS) _simpleoptcTt|jttdfSr.) isinstancer0rtyper6s rr7z_simpleopt._isboolopts $,tT$ZZ.@AAArc|Sr.r5r;s rr?z_simpleopt.newstatesrN)r@rArBr7r?r5rrrIrIs5BBBrrIc$eZdZfdZdZxZS) _callableoptcf||_tt|ddSr.) callablefnsuperrOr3)r1rQ __class__s rr3z_callableopt.__init__s.$ lD!!**400000rc,||Sr.)rQr;s rr?z_callableopt.newstatesx(((r)r@rArBr3r? __classcell__)rSs@rrOrOsG11111)))))))rrOceZdZdZdZdS)_listoptc |jddSr.r/r6s rr9z_listopt.getdefaultvalues!!!!$$rc0|||Sr.)r r;s rr?z_listopt.newstates!!!rN)r@rArBr9r?r5rrrWrWs2%%%rrWceZdZdZdS)_intoptct t|S#t$r|tdYdSwxYw)Ns expected int)int ValueErrorrr;s rr?z_intopt.newstatesO &x==  & & & E!O$$ % % % % % % &s "77N)r@rArBr?r5rrr[r[s#&&&&&rr[c<t|tr|St|rt|St|trt |ddSt |t durt|St|S)zzfancyopts..<s%%%qt%%%rr_r rcg|]}|dzS)r r5)rfns r zfancyopts..Ts///1a$h///rsno-)r#TFcvtjtdtj|fz)Ns"invalid value %r for option %s, %s)r InputErrorrr maybebytestr)soptrs rr>zfancyopts..abort}s>&;<<,S113:;r)rr!getreplacercr9r7 nevernegaterr functoolspartialr*r gnugetoptbgetoptbr?)r"optionsstater#early optaliasesrrargmapdefmap negationsalllongoptionshortnamerbcommentdummyonamesrlinsertparseoptsboolvalnegationobjr>rsrs @@r fancyoptsrs8 HI F FI%%W%%%G'$'$ v;;!  39 0E4'55,2 )E4' jnnT2..///||D$''#te| % %A $F519  "7++t Tl2244d d|&&(( ,  /////FF  $ $ , ,<<''(qrrUFF#aZF((!AIi777705 Iefn-OOF+++    I  $ OOF # # # !!+3777 !# tY11JD$IIS==e,,  CGc{Tl >>   I!E$KK       !,//d S%HHE$KK Kr)FF)FFN)rDrwi18nrrrrvrr*r,rIrOrWr[rcrr5rrrs   <"<"<"~o"o"o"o"dHHHHHHHH2)))))9)))y&&&&&i&&& # # #mmmmmmr