f _=@sdZddlZddlZddlZddlZz ddlZWneyFdZYn0gdZdZGdddej Z e e j ejZd0ddZd1d d Zd2d d Zd3d dZd4ddZd5ddZd6ddZd7ddZd8ddZddZd9ddZdddDZd 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):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). (? rXs()[]{}?*+-|^$\.&~# cCs.t|tr|tSt|d}|tdS)z0 Escape special characters in a string. latin1N) isinstancestr translate_special_chars_mapencode)rHr1r1r2r s   r ic Cst|tr|j}ztt|||fWSty6Yn0t|trR|rNtd|St |sdt dt ||}|t @st ttkrztttt=WntttfyYn0|tt|||f<|S)Nz5cannot process flags argument with a compiled patternz1first argument must be string or compiled pattern)r[rr,rPtypeKeyErrorr ValueErrorr7isstring TypeErrorr rCr* _MAXCACHEnextiter StopIteration RuntimeError)rHrJpr1r1r2rF!s.      rFcCs t||SN) sre_parseparse_template)rLrHr1r1r2rR;srRcCst||}t||Srl)rmrnexpand_template)rHrr r1r1r2_expand@s rpcCs>t||}|ds.t|ddkr.|ddS|fdd}|S)Nrr!cSs t||Srl)rmro)rr r1r1r2filterKsz_subx..filter)rRr*)rHr rqr1r1r2_subxEs    rrcCst|j|jffSrl)rFrHrJ)rkr1r1r2_pickleSsrsc@seZdZdddZddZdS)Scannerrc Csddlm}m}t|tr |j}||_g}t}||_ |D]H\}}| } | t ||| ddt ||ffg|| |dqsNk   #