VcAdZgdZddlZ ddlmZn#e$rdZYnwxYwGddeZeZgfdZ gfd Z d Z d Z d Z d Zedkr+ddlZee ejdddddgdSdS)aParser for command line options. This module helps scripts to parse the command line arguments in sys.argv. It supports the same conventions as the Unix getopt() function (including the special meanings of arguments of the form `-' and `--'). Long options similar to those supported by GNU software may be used as well via an optional third argument. This module provides two functions and an exception: getopt() -- Parse command line options gnu_getopt() -- Like getopt(), but allow option and non-option arguments to be intermixed. GetoptError -- exception (class) raised with 'opt' attribute, which is the option involved with the exception. ) GetoptErrorerrorgetopt gnu_getoptN)gettextc|SN)ss /usr/lib64/python3.11/getopt.py_r )sQhc$eZdZdZdZddZdZdS)rcZ||_||_t|||dSr )msgopt Exception__init__)selfrrs r rzGetoptError.__init__.s.4c*****rc|jSr )r)rs r __str__zGetoptError.__str__3s xrN)r)__name__ __module__ __qualname__rrrrr rr rr+sA C C++++ rrc*g}t|tdkr|g}nt|}|r|ddr|ddkr|ddkr |dd}n|ddr,t||ddd||dd\}}n+t ||ddd||dd\}}|r'|ddr |ddk||fS)a@getopt(args, options[, long_options]) -> opts, args Parses command line options and parameter list. args is the argument list to be parsed, without the leading reference to the running program. Typically, this means "sys.argv[1:]". shortopts is the string of option letters that the script wants to recognize, with options that require an argument followed by a colon (i.e., the same format that Unix getopt() uses). If specified, longopts is a list of strings with the names of the long options which should be supported. The leading '--' characters should not be included in the option name. Options which require an argument should be followed by an equal sign ('='). The return value consists of two elements: the first is a list of (option, value) pairs; the second is the list of program arguments left after the option list was stripped (this is a trailing slice of the first argument). Each option-and-value pair returned has the option as its first element, prefixed with a hyphen (e.g., '-x'), and the option argument as its second element, or an empty string if the option has no argument. The options occur in the list in the same order in which they were found, thus allowing multiple occurrences. Long and short options may be mixed. rr---N)typelist startswithdo_longs do_shorts)args shortoptslongoptsoptss r rr8s=6 D H~~b!":>> K47%%c**KtAw#~K 7d? 8D  7  d # # K!$Q XtABBxHHJD$$"4aiabbJJJD$ K47%%c**KtAw#~K :rcg}g}t|tr|g}nt|}|dr |dd}d}n$tjdrd}nd}|r|ddkr||ddz }n|ddd dkr,t||dd d||dd\}}ny|dddd kr8|dd kr,t||ddd||dd\}}n-|r||z }n'| |d|dd}|||fS) agetopt(args, options[, long_options]) -> opts, args This function works like getopt(), except that GNU style scanning mode is used by default. This means that option and non-option arguments may be intermixed. The getopt() function stops processing options as soon as a non-option argument is encountered. If the first character of the option string is `+', or if the environment variable POSIXLY_CORRECT is set, then option processing stops as soon as a non-option argument is encountered. +rNTPOSIXLY_CORRECTFrrr r) isinstancestrr"r#osenvirongetr$r%append)r&r'r(r) prog_argsall_options_firsts r rrcs DI(C  ":>>C  "abbM   ) * *" !  7d?  abb !I  72A2;$  !$Q XtABBxHHJD$$ !WRaR[C  DGsN "4aiabbJJJD$$  T!   a)))ABBx  " ?rc |d}|d|||dzd}}n#t$rd}YnwxYwt||\}}|r7|4|s tt d|z||d|dd}}n"| tt d|z||d|z|pdf||fS)N=rzoption --%s requires argumentrz%option --%s must not have an argumentrr)index ValueError long_has_argsrr r2)r)rr(r&ioptarghas_args r r$r$s) IIcNN"1"gs1Q344yV  !h//LGSQ  - Q!!$C"D"Ds"JCPPP7DHDF Q!CDDsJCPPPKKV\r*+++ :s / >>cJfd|D}|s ttdz|vrdfSdz|vrdfSt|dkr ttdz|d}|d}|r |dd }||fS) Nc>g|]}||Sr )r#).0ors r z!long_has_args..s*>>>1ALL,=,=>Q>>>rzoption --%s not recognizedFr6Trzoption --%s not a unique prefixr)rr lenendswith)rr( possibilities unique_matchr<s` r r9r9s>>>>>>>M F!899C?EEE mcz sm #Sy =AK!=>>DcJJJ #L##C((G)#CRC( L  rc|dkr|d|dd}}t||r?|dkr4|s ttd|z||d|dd}}|d}}nd}|d|z|f|dk||fS)Nrrrzoption -%s requires argumentr) short_has_argrr r2)r) optstringr'r&rr;s r r%r%s r/ )"1y}Y i ( ( B 4+%a(F&G&G#&M&)+++"&q'484 )2IFFF S3Y'((( r/ ) :rctt|D]3}|||cxkrdkrn|d|dzcS4tt d|z|)N:rzoption -%s not recognized)rangerCr#rr )rr'r:s r rHrHs 3y>> " "22 )A, 2 2 2 2# 2 2 2 2 2''QqS11 1 1 1 2 a344s:C @ @@r__main__rza:bzalpha=beta)__doc____all__r/rr ImportErrorrrrrrr$r9r%rHrsysprintargvr rr rUsaB 8 7 7 $$$$$$$     )    ')))))V,.0000d,!!!*   AAA  z;JJJ E&&!""ux&8 9 9:::::;;s