o Ƌ|c=@sdZddlZddlZddlZddlZzddlZWn ey#dZYnwgdZdZGdddej Z e e j ejZd0ddZd0d d Zd0d d Zd1d dZd1ddZd1ddZd0ddZd0ddZd0ddZddZd0ddZdddDZd d!Zeed"dZeed"dd"ZiZd#Z d$d%Z!e"e d&d'Z#d(d)Z$d*d+Z%ddl&Z&d,d-Z'e&(ee'e!Gd.d/d/Z)dS)2aSupport 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). (?rcCr8)ztScan through string looking for a match to the pattern, returning a Match object, or None if no match was found.)r9rr:r-r-r.rr>rcCt|||||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.)r9rr;replr<countr=r-r-r.rsrcCr?)aReturn a 2-tuple containing (new_string, number). new_string is the string obtained by replacing the leftmost non-overlapping occurrences of the pattern in the source string by the replacement repl. number is the number of substitutions that were made. 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.)r9rr@r-r-r.rs rcCst||||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.)r9r)r;r<Zmaxsplitr=r-r-r.rsrcCr8)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.)r9rr:r-r-r.rsrcCr8)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.)r9r r:r-r-r.r sr cCs t||S)zACompile a regular expression pattern, returning a Pattern object.)r9r;r=r-r-r.r s r cCsttdS)z#Clear the regular expression cachesN)_cacheclear _compile_replZ cache_clearr-r-r-r.r s r cCst||tBS)z6Compile a template pattern, returning a Pattern object)r9r4rCr-r-r.r sr cCsi|] }|dt|qS)\)chr).0ir-r-r. srKs()[]{}?*+-|^$\.&~# cCs.t|tr |tSt|d}|tdS)z0 Escape special characters in a string. latin1) isinstancestr translate_special_chars_mapencode)r;r-r-r.r s   r ic Cst|tr|j}z tt|||fWStyYnwt|tr)|r'td|St |s2t dt ||}|t @sat ttkrXz tttt=Wn tttfyWYnw|tt|||f<|S)Nz5cannot process flags argument with a compiled patternz1first argument must be string or compiled pattern)rMrr*rDtypeKeyErrorr ValueErrorr3Zisstring TypeErrorr r5r( _MAXCACHEnextiter StopIteration RuntimeError)r;r=pr-r-r.r9 s2      r9cCs t||SN) sre_parseparse_template)rAr;r-r-r.rF:s rFcCst||}t||Sr])r^r_expand_template)r;rr r-r-r._expand?s  racCs>t||}|dst|ddkr|ddS|fdd}|S)Nrr!cSs t||Sr])r^r`)rr r-r-r.filterJs z_subx..filter)rFr()r;r rbr-r-r._subxDs   rccCst|j|jffSr])r9r;r=)r\r-r-r._pickleRsrdc@seZdZdddZddZdS)Scannerrc Csddlm}m}t|tr|j}||_g}t}||_ |D]$\}}| } | t ||| ddt ||ffg|| |dqt ||d|ffg}t||_dS)Nr)BRANCH SUBPATTERN)Z sre_constantsrfrgrMrr*lexiconr^ZStater=Z opengroupr%Z SubPatternZparseZ closegroupr3r scanner) r)rir=rfrgr\sZphraseactionZgidr-r-r.__init__[s   zScanner.__init__c Csg}|j}|j|j}d} |}|sn,|}||krn#|j|jdd}t|r6||_|||}|dur>|||}q|||dfS)NrTr!)r%rjrendriZ lastindexcallablegroup) r)r<resultr%rrJr+jrlr-r-r.scanls(z Scanner.scanNr)r0r1r2rmrsr-r-r-r.reZs  rert)rr)*__doc__Zenumr3r^Z functoolsZ_locale ImportError__all__ __version__ZIntFlagrglobalsupdateZ __members__rrrrrrrrr r r r rPr rSrrrDrWr9Z lru_cacherFrarcZcopyregrdZpicklerer-r-r-r.sRk  "