o ?Og=@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). (? sr[s()[]{}?*+-|^$\.&~# cCs.t|tr |tSt|d}|tdS)z0 Escape special characters in a string. latin1) isinstancestr translate_special_chars_mapencode)rIr1r1r2r 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)r]rr,rStypeKeyErrorr ValueErrorr7isstring TypeErrorr rCr* _MAXCACHEnextiter StopIteration RuntimeError)rIrKpr1r1r2rG s2      rGcCs t||SN) sre_parseparse_template)rOrIr1r1r2rU:s rUcCst||}t||Srn)rorpexpand_template)rIrr r1r1r2_expand?s  rrcCs>t||}|dst|ddkr|ddS|fdd}|S)Nrr!cSs t||Srn)rorq)rr r1r1r2filterJs z_subx..filter)rUr*)rIr rsr1r1r2_subxDs   rtcCst|j|jffSrn)rGrIrK)rmr1r1r2_pickleRsruc@seZdZdddZddZdS)Scannerrc Csddlm}m}t|tr|j}||_g}t}||_ |D]$\}}| } | t ||| ddt ||ffg|| |dqt ||d|ffg}t||_dS)Nr)BRANCH SUBPATTERN) sre_constantsrwrxr]rr,lexiconroStaterK opengroupr' SubPatternparse closegroupr7r scanner) r+r{rKrwrxrmsphraseactiongidr1r1r2__init__[s   zScanner.__init__c Csg}|j}|j|j}d} |}|sn,|}||krn#|j|jdd}t|r6||_|||}|dur>|||}q|||dfS)NrTr!)r'rrendr{ lastindexcallablegroup) r+rJresultr'rrZr/jrr1r1r2scanls(z Scanner.scanNr)r4r5r6rrr1r1r1r2rvZs  rvr)rr)*__doc__enumr7ro functools_locale ImportError__all__ __version__IntFlagrglobalsupdate __members__rrrrrrrrr r r r r`r rcrrrSrhrG lru_cacherUrrrtcopyregrupicklervr1r1r1r2sRk  "