g?dZddlZddlmZmZddlZddlZgdZdZejejejejGdd Z ejZd d Zd d Zd d Zd!d Zd!dZd!dZd dZd dZd dZdZd dZdDcic]}|de|zc}ZdZeej.ddZeej.ddjdZiZ iZ!dZ"dZ#e#e"ksJdZ$ejJe"dZ&ddl'Z'dZ(e'jRee(e$GddZ*ycc}w)"aSupport for regular expressions (RE). This module provides regular expression matching operations similar to those found in Perl. It supports both 8-bit and Unicode strings; both the pattern and the strings being processed can contain null bytes and characters outside the US ASCII range. Regular expressions can contain both special and ordinary characters. Most ordinary characters, like "A", "a", or "0", are the simplest regular expressions; they simply match themselves. You can concatenate ordinary characters, so last matches the string 'last'. The special characters are: "." Matches any character except a newline. "^" Matches the start of the string. "$" Matches the end of the string or just before the newline at the end of the string. "*" Matches 0 or more (greedy) repetitions of the preceding RE. Greedy means that it will match as many repetitions as possible. "+" Matches 1 or more (greedy) repetitions of the preceding RE. "?" Matches 0 or 1 (greedy) of the preceding RE. *?,+?,?? Non-greedy versions of the previous three special characters. {m,n} Matches from m to n repetitions of the preceding RE. {m,n}? Non-greedy version of the above. "\\" Either escapes special characters or signals a special sequence. [] Indicates a set of characters. A "^" as the first character indicates a complementing set. "|" A|B, creates an RE that will match either A or B. (...) Matches the RE inside the parentheses. The contents can be retrieved or matched later in the string. (?aiLmsux) The letters set the corresponding flags defined below. (?:...) Non-grouping version of regular parentheses. (?P...) The substring matched by the group is accessible by name. (?P=name) Matches the text matched earlier by the group named name. (?#...) A comment; ignored. (?=...) Matches if ... matches next, but doesn't consume the string. (?!...) Matches if ... doesn't match next. (?<=...) Matches if preceded by ... (must be fixed length). (?rr?s r<rrs GU # - -f 55r;c8t||j|S)ztScan through string looking for a match to the pattern, returning a Match object, or None if no match was found.)r>rr?s r<rrs GU # * *6 22r;c<t||j|||S)aZReturn the string obtained by replacing the leftmost non-overlapping occurrences of the pattern in string by the replacement repl. repl can be either a string or a callable; if a string, backslash escapes in it are processed. If it is a callable, it's passed the Match object and must return a replacement string to be used.)r>r r@replrAcountrBs r<r r s  GU # ' 'fe <r rFs r<r r s  GU # ( (vu ==r;c:t||j||S)aSplit the source string by the occurrences of the pattern, returning a list containing the resulting substrings. If capturing parentheses are used in pattern, then the text of all groups in the pattern are also returned as part of the resulting list. If maxsplit is nonzero, at most maxsplit splits occur, and the remainder of the string is returned as the final element of the list.)r>r )r@rAmaxsplitrBs r<r r s GU # ) )&( ;;r;c8t||j|S)aReturn a list of all non-overlapping matches in the string. If one or more capturing groups are present in the pattern, return a list of groups; this will be a list of tuples if the pattern has more than one group. Empty matches are included in the result.)r>r r?s r<r r s GU # + +F 33r;c8t||j|S)zReturn an iterator over all non-overlapping matches in the string. For each match, the iterator returns a Match object. Empty matches are included in the result.)r>r r?s r<r r s GU # , ,V 44r;ct||S)zACompile a regular expression pattern, returning a Pattern object.)r>)r@rBs r<rrs GU ##r;c|tjtjtj y)z#Clear the regular expression cachesN)_cacheclear_cache2_compile_template cache_clearr:r;r<rrs  LLN MMO!!#r;cddl}|jdt|j5|j dtt ||t zcdddS#1swYyxYw)zBCompile a template pattern, returning a Pattern object, deprecatedrNzThe re.template() function is deprecated as it is an undocumented function without an obvious purpose. Use re.compile() instead.ignore)warningswarnDeprecationWarningcatch_warnings simplefilterr>r3)r@rBrWs r<rrsT MM.% &  "h(:;q) # " "s )AA's()[]{}?*+-|^$\.&~# \ct|tr|jtSt|d}|jtj dS)z0 Escape special characters in a string. latin1) isinstancestr translate_special_chars_mapencode)r@s r<rrsI'3  !344gx(  !34;;HEEr;ic:t|tr |j} tt |||fS#t $rYnwxYwt |||f}t j|d}|t|tr|r td|Stj|s td|tzrddl}|jdt tj"||}|t$zr|St't t(k\r9 t t+t-t =n#t.t0t f$rYnwxYw|t |<t'tt2k\r9 tt+t-t=n#t.t0t f$rYnwxYw|t|<|S)Nz5cannot process flags argument with a compiled patternz1first argument must be string or compiled patternrzoThe re.TEMPLATE/re.T flag is deprecated as it is an undocumented flag without an obvious purpose. Don't use it.)r_r$valuerRtypeKeyErrorrPpopr ValueErrorrisstring TypeErrorr3rWrXrYrr5len _MAXCACHEnextiter StopIteration RuntimeError _MAXCACHE2)r@rBkeyprWs r<r>r>sv%#  tG}gu455     ='5 )C 3Ay gw ' KMMN!!'*OP P 19  MM$'  (   gu - 5=H v;) #  4V -.!<:  F3K 7|z! T']+,|X6   GCL Hs03 ??D D76D7E88FFcVtj|tj||SN)_srerrparse_template)r@rGs r<rSrSKs" =='"8"8w"G HHr;c>t|j|jffSrx)r>r@rB)rvs r<_pickler|Ts aii) ))r;ceZdZddZdZy)Scannercddlm}m}t|tr |j }||_g}tj}||_ |D]j\}}|j} |jtj||| ddtj||ffg|j| |dltj||d|ffg}tj ||_y)Nr)BRANCH SUBPATTERNr) _constantsrrr_r$rglexiconrStaterB opengroupappend SubPatternparse closegrouprrscanner) selfrrBrrrvsphraseactiongids r<__init__zScanner.__init__]s2 eY 'KKE  MMO%NFF++-C HHW''c1avu)EFG,  LLae $ &   qFT1I#6"7 8 ((+ r;cfg}|j}|jj|j}d} |}|snk|j}||k(rnU|j|j dz d}t |r||_|||j}||||}u|||dfS)Nrr)rrrendr lastindexcallablegroup) rrAresultrrimjrs r<scanz Scanner.scanns $$V,22 AAAv\\!++a-03F aggi0!vAvabz!!r;Nr)r'r(r)rrr:r;r<r~r~\s ,""r;r~r)rr)+__doc__enumrdrr functoolsry__all__ __version__ global_enum _simple_enumIntFlagKEEPr$rrrrr r r r r rrrchrrbrrhrrrPrRrortr> lru_cacherScopyregr|pickler~)rs0r<rs"iV    4<<$))4  5   2 6 3 = ><45$$ *"1RR0Q1aA&0QRF  y  Q' ( Y  r1 % + +B /0     I1 fYI I *w* %"%"SsE